6 use Test::More tests => 15;
12 A fair amount of these tests will likely be irrelevant
13 once we have more fine grained control over the class
14 building process. A lot of the edge cases tested here
15 are actually related to class construction order and
16 not any real functionality.
19 Role which requires a method implemented
20 in another role as an override (it does
21 not remove the requirement)
26 package Role::RequireFoo;
33 package Role::ProvideFoo;
39 with 'Role::RequireFoo';
40 } '... the required "foo" method will not exist yet (but we will live)';
42 override 'foo' => sub { 'Role::ProvideFoo::foo' };
46 [ Role::ProvideFoo->meta->get_required_method_list ],
48 '... foo method is still required for Role::ProvideFoo');
52 Role which requires a method implemented
53 in the consuming class as an override.
54 It will fail since method modifiers are
55 second class citizens.
60 package Class::ProvideFoo::Base;
63 sub foo { 'Class::ProvideFoo::Base::foo' }
65 package Class::ProvideFoo::Override1;
68 extends 'Class::ProvideFoo::Base';
71 with 'Role::RequireFoo';
72 } '... the required "foo" method will be found in the superclass';
74 override 'foo' => sub { 'Class::ProvideFoo::foo' };
76 package Class::ProvideFoo::Override2;
79 extends 'Class::ProvideFoo::Base';
81 override 'foo' => sub { 'Class::ProvideFoo::foo' };
84 with 'Role::RequireFoo';
85 } '... the required "foo" method exists, although it is overriden locally';
91 Now same thing, but with a before
97 package Class::ProvideFoo::Before1;
100 extends 'Class::ProvideFoo::Base';
103 with 'Role::RequireFoo';
104 } '... the required "foo" method will be found in the superclass';
106 before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
108 package Class::ProvideFoo::Before2;
111 extends 'Class::ProvideFoo::Base';
113 before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
116 with 'Role::RequireFoo';
117 } '... the required "foo" method exists, although it is a before modifier locally';
119 package Class::ProvideFoo::Before3;
122 extends 'Class::ProvideFoo::Base';
124 sub foo { 'Class::ProvideFoo::foo' }
125 before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
128 with 'Role::RequireFoo';
129 } '... the required "foo" method exists locally, and it is modified locally';
131 package Class::ProvideFoo::Before4;
134 extends 'Class::ProvideFoo::Base';
136 sub foo { 'Class::ProvideFoo::foo' }
137 before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
139 ::isa_ok(__PACKAGE__->meta->get_method('foo'), 'Class::MOP::Method::Wrapped');
140 ::is(__PACKAGE__->meta->get_method('foo')->get_original_method->package_name, __PACKAGE__,
141 '... but the original method is from our package');
144 with 'Role::RequireFoo';
145 } '... the required "foo" method exists in the symbol table (and we will live)';
151 Now same thing, but with a method from an attribute
158 package Class::ProvideFoo::Attr1;
161 extends 'Class::ProvideFoo::Base';
164 with 'Role::RequireFoo';
165 } '... the required "foo" method will be found in the superclass (but then overriden)';
167 has 'foo' => (is => 'ro');
169 package Class::ProvideFoo::Attr2;
172 extends 'Class::ProvideFoo::Base';
174 has 'foo' => (is => 'ro');
177 with 'Role::RequireFoo';
178 } '... the required "foo" method exists, and is an accessor';
182 # a method required in a role, but then
183 # implemented in the superclass (as an
184 # attribute accessor too)
187 package Foo::Class::Base;
206 default => sub { (shift)->bar + 1 }
210 package Foo::Class::Child;
212 extends 'Foo::Class::Base';
216 } '... our role combined successfully';
219 # a method required in a role and implemented in a superclass, with a method
220 # modifier in the subclass. this should live, but dies in 0.26 -- hdp,
224 package Bar::Class::Base;
235 package Bar::Class::Child;
237 extends 'Bar::Class::Base';
238 after bar => sub { "o noes" };
239 # technically we could run lives_ok here, too, but putting it into a
240 # grandchild class makes it more obvious why this matters.
243 package Bar::Class::Grandchild;
245 extends 'Bar::Class::Child';
248 } 'required method exists in superclass as non-modifier, so we live';
252 package Bar2::Class::Base;
263 package Bar2::Class::Child;
265 extends 'Bar2::Class::Base';
266 override bar => sub { "o noes" };
267 # technically we could run lives_ok here, too, but putting it into a
268 # grandchild class makes it more obvious why this matters.
271 package Bar2::Class::Grandchild;
273 extends 'Bar2::Class::Child';
276 } 'required method exists in superclass as non-modifier, so we live';