6 use Test::More tests => 24;
11 use_ok('Moose::Role');
16 The idea and examples for this feature are taken
17 from the Fortress spec.
19 http://research.sun.com/projects/plrg/fortress0903.pdf
21 trait OrganicMolecule extends Molecule
22 excludes { InorganicMolecule }
24 trait InorganicMolecule extends Molecule end
32 package Molecule::Organic;
36 excludes 'Molecule::Inorganic';
38 package Molecule::Inorganic;
44 ok(Molecule::Organic->meta->excludes_role('Molecule::Inorganic'), '... Molecule::Organic exludes Molecule::Inorganic');
46 [ Molecule::Organic->meta->get_excluded_roles_list() ],
47 [ 'Molecule::Inorganic' ],
48 '... Molecule::Organic exludes Molecule::Inorganic');
52 Check some basic conflicts when combining
53 the roles into the same class
62 with 'Molecule::Organic';
63 } '... adding the role (w/ excluded roles) okay';
69 with 'Molecule::Organic', 'Molecule::Inorganic';
70 } qr/Conflict detected: .+ excludes role \'Molecule::Inorganic\'/,
71 '... adding the role w/ excluded role conflict dies okay';
77 with 'Molecule::Organic';
78 } '... adding the role (w/ excluded roles) okay';
81 with 'Molecule::Inorganic';
82 } qr/Conflict detected: My::Test3 excludes role 'Molecule::Inorganic'/,
83 '... adding the role w/ excluded role conflict dies okay';
86 ok(My::Test1->does('Molecule::Organic'), '... My::Test1 does Molecule::Organic');
87 ok(My::Test1->does('Molecule'), '... My::Test1 does Molecule');
88 ok(My::Test1->meta->excludes_role('Molecule::Inorganic'), '... My::Test1 excludes Molecule::Organic');
90 ok(!My::Test2->does('Molecule::Organic'), '... ! My::Test2 does Molecule::Organic');
91 ok(!My::Test2->does('Molecule::Inorganic'), '... ! My::Test2 does Molecule::Inorganic');
93 ok(My::Test3->does('Molecule::Organic'), '... My::Test3 does Molecule::Organic');
94 ok(My::Test3->does('Molecule'), '... My::Test1 does Molecule');
95 ok(My::Test3->meta->excludes_role('Molecule::Inorganic'), '... My::Test3 excludes Molecule::Organic');
96 ok(!My::Test3->does('Molecule::Inorganic'), '... ! My::Test3 does Molecule::Inorganic');
100 Check some basic conflicts when combining
101 the roles into the a superclass
109 with 'Molecule::Organic';
117 with 'Molecule::Inorganic';
118 } qr/Conflict detected: My::Test4 excludes role \'Molecule::Inorganic\'/,
119 '... cannot add exculded role into class which extends Methane';
122 ok(Methane->does('Molecule::Organic'), '... Methane does Molecule::Organic');
123 ok(My::Test4->isa('Methane'), '... My::Test4 isa Methane');
124 ok(My::Test4->does('Molecule::Organic'), '... My::Test4 does Molecule::Organic');
125 ok(My::Test4->meta->does_role('Molecule::Organic'), '... My::Test4 meat does_role Molecule::Organic');
126 ok(My::Test4->meta->excludes_role('Molecule::Inorganic'), '... My::Test4 meta excludes Molecule::Organic');
127 ok(!My::Test4->does('Molecule::Inorganic'), '... My::Test4 does Molecule::Inorganic');