6 use Test::More tests => 14;
11 use_ok('Moose::Role');
16 Check for repeated inheritence causing
17 a method conflict (which is not really
26 sub foo { 'Role::Base::foo' }
28 package Role::Derived1;
33 package Role::Derived2;
38 package My::Test::Class1;
42 with 'Role::Derived1', 'Role::Derived2';
43 } '... roles composed okay (no conflicts)';
46 ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected');
47 ok(Role::Derived1->meta->has_method('foo'), '... have the method foo as expected');
48 ok(Role::Derived2->meta->has_method('foo'), '... have the method foo as expected');
49 ok(My::Test::Class1->meta->has_method('foo'), '... have the method foo as expected');
51 is(My::Test::Class1->foo, 'Role::Base::foo', '... got the right value from method');
55 Check for repeated inheritence causing
56 a method conflict with method modifiers
57 (which is not really a conflict)
67 override 'foo' => sub { super() . ' -> Role::Base::foo' };
69 package Role::Derived3;
74 package Role::Derived4;
79 package My::Test::Class2::Base;
82 sub foo { 'My::Test::Class2::Base' }
84 package My::Test::Class2;
87 extends 'My::Test::Class2::Base';
90 with 'Role::Derived3', 'Role::Derived4';
91 } '... roles composed okay (no conflicts)';
94 ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
95 ok(Role::Derived3->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
96 ok(Role::Derived4->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
97 ok(My::Test::Class2->meta->has_method('foo'), '... have the method foo as expected');
98 isa_ok(My::Test::Class2->meta->get_method('foo'), 'Moose::Meta::Method::Overriden');
99 ok(My::Test::Class2::Base->meta->has_method('foo'), '... have the method foo as expected');
100 isa_ok(My::Test::Class2::Base->meta->get_method('foo'), 'Class::MOP::Method');
102 is(My::Test::Class2::Base->foo, 'My::Test::Class2::Base', '... got the right value from method');
103 is(My::Test::Class2->foo, 'My::Test::Class2::Base -> Role::Base::foo', '... got the right value from method');
109 Check for repeated inheritence 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
124 around 'foo' => sub { 'Role::Base::foo(' . (shift)->() . ')' };
126 package Role::Derived5;
131 package Role::Derived6;
136 package My::Test::Class3::Base;
139 sub foo { 'My::Test::Class3::Base' }
141 package My::Test::Class3;
144 extends 'My::Test::Class3::Base';
147 with 'Role::Derived5', 'Role::Derived6';
148 } '... roles composed okay (no conflicts)';
151 ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
152 ok(Role::Derived5->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
153 ok(Role::Derived6->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
154 ok(My::Test::Class3->meta->has_method('foo'), '... have the method foo as expected');
155 isa_ok(My::Test::Class3->meta->get_method('foo'), 'Class::MOP::Method::Wrapped');
156 ok(My::Test::Class3::Base->meta->has_method('foo'), '... have the method foo as expected');
157 isa_ok(My::Test::Class3::Base->meta->get_method('foo'), 'Class::MOP::Method');
159 is(My::Test::Class3::Base->foo, 'My::Test::Class3::Base', '... got the right value from method');
160 is(My::Test::Class3->foo, 'Role::Base::foo(My::Test::Class3::Base)', '... got the right value from method');
166 Check for repeated inheritence causing
167 a attr conflict (which is not really
176 has 'foo' => (is => 'ro', default => 'Role::Base::foo');
178 package Role::Derived7;
183 package Role::Derived8;
188 package My::Test::Class4;
192 with 'Role::Derived7', 'Role::Derived8';
193 } '... roles composed okay (no conflicts)';
196 ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected');
197 ok(Role::Derived7->meta->has_attribute('foo'), '... have the attribute foo as expected');
198 ok(Role::Derived8->meta->has_attribute('foo'), '... have the attribute foo as expected');
199 ok(My::Test::Class4->meta->has_attribute('foo'), '... have the attribute foo as expected');
201 is(My::Test::Class4->new->foo, 'Role::Base::foo', '... got the right value from method');