6 use Test::More tests => 28;
11 use_ok('Moose::Role');
16 Check for repeated inheritence causing
17 a method conflict (which is not really
28 sub foo { 'Role::Base::foo' }
30 package Role::Derived1;
37 package Role::Derived2;
44 package My::Test::Class1;
50 with 'Role::Derived1', 'Role::Derived2';
51 } '... roles composed okay (no conflicts)';
54 ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected');
55 ok(Role::Derived1->meta->has_method('foo'), '... have the method foo as expected');
56 ok(Role::Derived2->meta->has_method('foo'), '... have the method foo as expected');
57 ok(My::Test::Class1->meta->has_method('foo'), '... have the method foo as expected');
59 is(My::Test::Class1->foo, 'Role::Base::foo', '... got the right value from method');
63 Check for repeated inheritence causing
64 a method conflict with method modifiers
65 (which is not really a conflict)
75 override 'foo' => sub { super() . ' -> Role::Base::foo' };
77 package Role::Derived3;
84 package Role::Derived4;
91 package My::Test::Class2::Base;
96 sub foo { 'My::Test::Class2::Base' }
98 package My::Test::Class2;
103 extends 'My::Test::Class2::Base';
106 with 'Role::Derived3', 'Role::Derived4';
107 } '... roles composed okay (no conflicts)';
110 ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
111 ok(Role::Derived3->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
112 ok(Role::Derived4->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
113 ok(My::Test::Class2->meta->has_method('foo'), '... have the method foo as expected');
114 isa_ok(My::Test::Class2->meta->get_method('foo'), 'Moose::Meta::Method::Overriden');
115 ok(My::Test::Class2::Base->meta->has_method('foo'), '... have the method foo as expected');
116 isa_ok(My::Test::Class2::Base->meta->get_method('foo'), 'Class::MOP::Method');
118 is(My::Test::Class2::Base->foo, 'My::Test::Class2::Base', '... got the right value from method');
119 is(My::Test::Class2->foo, 'My::Test::Class2::Base -> Role::Base::foo', '... got the right value from method');
123 Check for repeated inheritence of the
124 same code. There are no conflicts with
125 before/around/after method modifiers.
127 This tests around, but should work the
128 same for before/afters as well
138 around 'foo' => sub { 'Role::Base::foo(' . (shift)->() . ')' };
140 package Role::Derived5;
147 package Role::Derived6;
154 package My::Test::Class3::Base;
159 sub foo { 'My::Test::Class3::Base' }
161 package My::Test::Class3;
166 extends 'My::Test::Class3::Base';
169 with 'Role::Derived5', 'Role::Derived6';
170 } '... roles composed okay (no conflicts)';
173 ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
174 ok(Role::Derived5->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
175 ok(Role::Derived6->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
176 ok(My::Test::Class3->meta->has_method('foo'), '... have the method foo as expected');
177 isa_ok(My::Test::Class3->meta->get_method('foo'), 'Class::MOP::Method::Wrapped');
178 ok(My::Test::Class3::Base->meta->has_method('foo'), '... have the method foo as expected');
179 isa_ok(My::Test::Class3::Base->meta->get_method('foo'), 'Class::MOP::Method');
181 is(My::Test::Class3::Base->foo, 'My::Test::Class3::Base', '... got the right value from method');
182 is(My::Test::Class3->foo, 'Role::Base::foo(My::Test::Class3::Base)', '... got the right value from method');