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
|
#!/usr/bin/perl
use v5.18;
use warnings;
use Test2::V0;
use Object::Pad 0.800;
my @BUILD;
my @ADJUST;
role ARole {
BUILD { push @BUILD, "ARole" }
ADJUST { push @ADJUST, "ARole" }
}
class AClass {
apply ARole;
BUILD { push @BUILD, "AClass" }
ADJUST { push @ADJUST, "AClass" }
}
{
undef @BUILD;
undef @ADJUST;
AClass->new;
is( \@BUILD, [qw( ARole AClass )],
'Roles are built before their implementing classes' );
is( \@ADJUST, [qw( ARole AClass )],
'Roles are adjusted before their implementing classes' );
}
class BClass {
inherit AClass;
apply ARole;
BUILD { push @BUILD, "BClass" }
}
{
undef @BUILD;
BClass->new;
is( \@BUILD, [qw( ARole AClass BClass )],
'Roles are built once only even if implemented multiple times' );
}
# RT154494
{
use Object::Pad ':experimental(composed_adjust)';
role RT154494Role { }
pass( 'Managed to compile a role under :experimental(composed_adjust)' );
}
done_testing;
|