1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
use strict;
use warnings;
use Test::More;
{
package ModifierRole;
use Role::Tiny;
sub method { 0 }
around method => sub {
my $orig = shift;
my $self = shift;
$self->$orig(@_) + 1;
};
}
{
package Role1;
use Role::Tiny;
with 'ModifierRole';
}
{
package Role2;
use Role::Tiny;
with 'ModifierRole';
}
{
package ComposingClass1;
use Role::Tiny::With;
with qw(Role1 Role2);
}
is +ComposingClass1->method, 1, 'recomposed modifier called once';
{
package ComposingClass2;
use Role::Tiny::With;
with 'Role1';
with 'Role2';
}
is +ComposingClass2->method, 1, 'recomposed modifier called once (separately composed)';
{
package DoubleRole;
use Role::Tiny;
with qw(Role1 Role2);
}
{
package ComposingClass3;
use Role::Tiny::With;
with 'DoubleRole';
}
is +ComposingClass3->method, 1, 'recomposed modifier called once (via composing role)';
{
package DoubleRoleSeparate;
use Role::Tiny;
with 'Role1';
with 'Role2';
}
{
package ComposingClass4;
use Role::Tiny::With;
with qw(DoubleRoleSeparate);
}
is +ComposingClass4->method, 1, 'recomposed modifier called once (via separately composing role)';
done_testing;
|