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');
91 isa_ok(My::Test::Class2->meta->get_method('foo'), 'Moose::Meta::Method::Overriden');
92 ok(My::Test::Class2::Base->meta->has_method('foo'), '... have the method foo as expected');
93 isa_ok(My::Test::Class2::Base->meta->get_method('foo'), 'Class::MOP::Method');
95 is(My::Test::Class2::Base->foo, 'My::Test::Class2::Base', '... got the right value from method');
96 is(My::Test::Class2->foo, 'My::Test::Class2::Base -> Role::Base::foo', '... got the right value from method');
100 Check for repeated inheritance of the
101 same code. There are no conflicts with
102 before/around/after method modifiers.
104 This tests around, but should work the
105 same for before/afters as well
113 around 'foo' => sub { 'Role::Base::foo(' . (shift)->() . ')' };
115 package Role::Derived5;
120 package Role::Derived6;
125 package My::Test::Class3::Base;
128 sub foo { 'My::Test::Class3::Base' }
130 package My::Test::Class3;
133 extends 'My::Test::Class3::Base';
136 with 'Role::Derived5', 'Role::Derived6';
137 } '... roles composed okay (no conflicts)';
140 ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
141 ok(Role::Derived5->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
142 ok(Role::Derived6->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
143 ok(My::Test::Class3->meta->has_method('foo'), '... have the method foo as expected');
144 isa_ok(My::Test::Class3->meta->get_method('foo'), 'Class::MOP::Method::Wrapped');
145 ok(My::Test::Class3::Base->meta->has_method('foo'), '... have the method foo as expected');
146 isa_ok(My::Test::Class3::Base->meta->get_method('foo'), 'Class::MOP::Method');
148 is(My::Test::Class3::Base->foo, 'My::Test::Class3::Base', '... got the right value from method');
149 is(My::Test::Class3->foo, 'Role::Base::foo(My::Test::Class3::Base)', '... got the right value from method');
153 Check for repeated inheritance causing
154 a attr conflict (which is not really
163 has 'foo' => (is => 'ro', default => 'Role::Base::foo');
165 package Role::Derived7;
170 package Role::Derived8;
175 package My::Test::Class4;
179 with 'Role::Derived7', 'Role::Derived8';
180 } '... roles composed okay (no conflicts)';
183 ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected');
184 ok(Role::Derived7->meta->has_attribute('foo'), '... have the attribute foo as expected');
185 ok(Role::Derived8->meta->has_attribute('foo'), '... have the attribute foo as expected');
186 ok(My::Test::Class4->meta->has_attribute('foo'), '... have the attribute foo as expected');
188 is(My::Test::Class4->new->foo, 'Role::Base::foo', '... got the right value from method');