6 use Test::More tests => 32;
15 Check for repeated inheritance causing
16 a method conflict (which is not really
25 sub foo { 'Role::Base::foo' }
27 package Role::Derived1;
32 package Role::Derived2;
37 package My::Test::Class1;
41 with 'Role::Derived1', 'Role::Derived2';
42 } '... roles composed okay (no conflicts)';
45 ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected');
46 ok(Role::Derived1->meta->has_method('foo'), '... have the method foo as expected');
47 ok(Role::Derived2->meta->has_method('foo'), '... have the method foo as expected');
48 ok(My::Test::Class1->meta->has_method('foo'), '... have the method foo as expected');
50 is(My::Test::Class1->foo, 'Role::Base::foo', '... got the right value from method');
54 Check for repeated inheritance causing
55 a method conflict with method modifiers
56 (which is not really a conflict)
64 override 'foo' => sub { super() . ' -> Role::Base::foo' };
66 package Role::Derived3;
71 package Role::Derived4;
76 package My::Test::Class2::Base;
79 sub foo { 'My::Test::Class2::Base' }
81 package My::Test::Class2;
84 extends 'My::Test::Class2::Base';
87 with 'Role::Derived3', 'Role::Derived4';
88 } '... roles composed okay (no conflicts)';
91 ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
92 ok(Role::Derived3->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
93 ok(Role::Derived4->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
94 ok(My::Test::Class2->meta->has_method('foo'), '... have the method foo as expected');
96 local $TODO = 'Not a Mouse::Meta::Method::Overriden';
97 isa_ok(My::Test::Class2->meta->get_method('foo'), 'Mouse::Meta::Method::Overridden');
99 ok(My::Test::Class2::Base->meta->has_method('foo'), '... have the method foo as expected');
101 local $TODO = 'Not a Class::MOP::Method';
102 isa_ok(My::Test::Class2::Base->meta->get_method('foo'), 'Class::MOP::Method');
104 is(My::Test::Class2::Base->foo, 'My::Test::Class2::Base', '... got the right value from method');
105 is(My::Test::Class2->foo, 'My::Test::Class2::Base -> Role::Base::foo', '... got the right value from method');
109 Check for repeated inheritance of the
110 same code. There are no conflicts with
111 before/around/after method modifiers.
113 This tests around, but should work the
114 same for before/afters as well
122 around 'foo' => sub { 'Role::Base::foo(' . (shift)->() . ')' };
124 package Role::Derived5;
129 package Role::Derived6;
134 package My::Test::Class3::Base;
137 sub foo { 'My::Test::Class3::Base' }
139 package My::Test::Class3;
142 extends 'My::Test::Class3::Base';
145 with 'Role::Derived5', 'Role::Derived6';
146 } '... roles composed okay (no conflicts)';
149 ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
150 ok(Role::Derived5->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
151 ok(Role::Derived6->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
152 ok(My::Test::Class3->meta->has_method('foo'), '... have the method foo as expected');
154 local $TODO = 'Not a Class::MOP::Method::Wrapped';
155 isa_ok(My::Test::Class3->meta->get_method('foo'), 'Class::MOP::Method::Wrapped');
157 ok(My::Test::Class3::Base->meta->has_method('foo'), '... have the method foo as expected');
159 local $TODO = 'Not a Class::MOP::Method';
160 isa_ok(My::Test::Class3::Base->meta->get_method('foo'), 'Class::MOP::Method');
162 is(My::Test::Class3::Base->foo, 'My::Test::Class3::Base', '... got the right value from method');
163 is(My::Test::Class3->foo, 'Role::Base::foo(My::Test::Class3::Base)', '... got the right value from method');
167 Check for repeated inheritance causing
168 a attr conflict (which is not really
177 has 'foo' => (is => 'ro', default => 'Role::Base::foo');
179 package Role::Derived7;
184 package Role::Derived8;
189 package My::Test::Class4;
193 with 'Role::Derived7', 'Role::Derived8';
194 } '... roles composed okay (no conflicts)';
197 ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected');
198 ok(Role::Derived7->meta->has_attribute('foo'), '... have the attribute foo as expected');
199 ok(Role::Derived8->meta->has_attribute('foo'), '... have the attribute foo as expected');
200 ok(My::Test::Class4->meta->has_attribute('foo'), '... have the attribute foo as expected');
202 is(My::Test::Class4->new->foo, 'Role::Base::foo', '... got the right value from method');