6 use Test::More tests => 32;
11 Check for repeated inheritance causing
12 a method conflict (which is not really
21 sub foo { 'Role::Base::foo' }
23 package Role::Derived1;
28 package Role::Derived2;
33 package My::Test::Class1;
37 with 'Role::Derived1', 'Role::Derived2';
38 } '... roles composed okay (no conflicts)';
41 ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected');
42 ok(Role::Derived1->meta->has_method('foo'), '... have the method foo as expected');
43 ok(Role::Derived2->meta->has_method('foo'), '... have the method foo as expected');
44 ok(My::Test::Class1->meta->has_method('foo'), '... have the method foo as expected');
46 is(My::Test::Class1->foo, 'Role::Base::foo', '... got the right value from method');
50 Check for repeated inheritance causing
51 a method conflict with method modifiers
52 (which is not really a conflict)
60 override 'foo' => sub { super() . ' -> Role::Base::foo' };
62 package Role::Derived3;
67 package Role::Derived4;
72 package My::Test::Class2::Base;
75 sub foo { 'My::Test::Class2::Base' }
77 package My::Test::Class2;
80 extends 'My::Test::Class2::Base';
83 with 'Role::Derived3', 'Role::Derived4';
84 } '... roles composed okay (no conflicts)';
87 ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
88 ok(Role::Derived3->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
89 ok(Role::Derived4->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
90 ok(My::Test::Class2->meta->has_method('foo'), '... have the method foo as expected');
92 local $TODO = 'Not a Mouse::Meta::Method::Overriden';
93 isa_ok(My::Test::Class2->meta->get_method('foo'), 'Mouse::Meta::Method::Overridden');
95 ok(My::Test::Class2::Base->meta->has_method('foo'), '... have the method foo as expected');
97 local $TODO = 'Not a Class::MOP::Method';
98 isa_ok(My::Test::Class2::Base->meta->get_method('foo'), 'Class::MOP::Method');
100 is(My::Test::Class2::Base->foo, 'My::Test::Class2::Base', '... got the right value from method');
101 is(My::Test::Class2->foo, 'My::Test::Class2::Base -> Role::Base::foo', '... got the right value from method');
105 Check for repeated inheritance of the
106 same code. There are no conflicts with
107 before/around/after method modifiers.
109 This tests around, but should work the
110 same for before/afters as well
118 around 'foo' => sub { 'Role::Base::foo(' . (shift)->() . ')' };
120 package Role::Derived5;
125 package Role::Derived6;
130 package My::Test::Class3::Base;
133 sub foo { 'My::Test::Class3::Base' }
135 package My::Test::Class3;
138 extends 'My::Test::Class3::Base';
141 with 'Role::Derived5', 'Role::Derived6';
142 } '... roles composed okay (no conflicts)';
145 ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
146 ok(Role::Derived5->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
147 ok(Role::Derived6->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
148 ok(My::Test::Class3->meta->has_method('foo'), '... have the method foo as expected');
150 local $TODO = 'Not a Class::MOP::Method::Wrapped';
151 isa_ok(My::Test::Class3->meta->get_method('foo'), 'Class::MOP::Method::Wrapped');
153 ok(My::Test::Class3::Base->meta->has_method('foo'), '... have the method foo as expected');
155 local $TODO = 'Not a Class::MOP::Method';
156 isa_ok(My::Test::Class3::Base->meta->get_method('foo'), 'Class::MOP::Method');
158 is(My::Test::Class3::Base->foo, 'My::Test::Class3::Base', '... got the right value from method');
159 is(My::Test::Class3->foo, 'Role::Base::foo(My::Test::Class3::Base)', '... got the right value from method');
163 Check for repeated inheritance causing
164 a attr conflict (which is not really
173 has 'foo' => (is => 'ro', default => 'Role::Base::foo');
175 package Role::Derived7;
180 package Role::Derived8;
185 package My::Test::Class4;
189 with 'Role::Derived7', 'Role::Derived8';
190 } '... roles composed okay (no conflicts)';
193 ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected');
194 ok(Role::Derived7->meta->has_attribute('foo'), '... have the attribute foo as expected');
195 ok(Role::Derived8->meta->has_attribute('foo'), '... have the attribute foo as expected');
196 ok(My::Test::Class4->meta->has_attribute('foo'), '... have the attribute foo as expected');
198 is(My::Test::Class4->new->foo, 'Role::Base::foo', '... got the right value from method');