6 use Test::More tests => 34;
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)
65 override 'foo' => sub { super() . ' -> Role::Base::foo' };
67 package Role::Derived3;
72 package Role::Derived4;
77 package My::Test::Class2::Base;
80 sub foo { 'My::Test::Class2::Base' }
82 package My::Test::Class2;
85 extends 'My::Test::Class2::Base';
88 with 'Role::Derived3', 'Role::Derived4';
89 } '... roles composed okay (no conflicts)';
92 ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
93 ok(Role::Derived3->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
94 ok(Role::Derived4->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
95 ok(My::Test::Class2->meta->has_method('foo'), '... have the method foo as expected');
96 isa_ok(My::Test::Class2->meta->get_method('foo'), 'Moose::Meta::Method::Overriden');
97 ok(My::Test::Class2::Base->meta->has_method('foo'), '... have the method foo as expected');
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 inheritence 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');
149 isa_ok(My::Test::Class3->meta->get_method('foo'), 'Class::MOP::Method::Wrapped');
150 ok(My::Test::Class3::Base->meta->has_method('foo'), '... have the method foo as expected');
151 isa_ok(My::Test::Class3::Base->meta->get_method('foo'), 'Class::MOP::Method');
153 is(My::Test::Class3::Base->foo, 'My::Test::Class3::Base', '... got the right value from method');
154 is(My::Test::Class3->foo, 'Role::Base::foo(My::Test::Class3::Base)', '... got the right value from method');
158 Check for repeated inheritence causing
159 a attr conflict (which is not really
168 has 'foo' => (is => 'ro', default => 'Role::Base::foo');
170 package Role::Derived7;
175 package Role::Derived8;
180 package My::Test::Class4;
184 with 'Role::Derived7', 'Role::Derived8';
185 } '... roles composed okay (no conflicts)';
188 ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected');
189 ok(Role::Derived7->meta->has_attribute('foo'), '... have the attribute foo as expected');
190 ok(Role::Derived8->meta->has_attribute('foo'), '... have the attribute foo as expected');
191 ok(My::Test::Class4->meta->has_attribute('foo'), '... have the attribute foo as expected');
193 is(My::Test::Class4->new->foo, 'Role::Base::foo', '... got the right value from method');