Commit | Line | Data |
db1ab48d |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
b10dde3a |
7 | use Test::Fatal; |
db1ab48d |
8 | |
db1ab48d |
9 | =pod |
10 | |
11 | Mutually recursive roles. |
12 | |
13 | =cut |
14 | |
15 | { |
16 | package Role::Foo; |
db1ab48d |
17 | use Moose::Role; |
18 | |
19 | requires 'foo'; |
d03bd989 |
20 | |
db1ab48d |
21 | sub bar { 'Role::Foo::bar' } |
d03bd989 |
22 | |
db1ab48d |
23 | package Role::Bar; |
db1ab48d |
24 | use Moose::Role; |
d03bd989 |
25 | |
db1ab48d |
26 | requires 'bar'; |
d03bd989 |
27 | |
28 | sub foo { 'Role::Bar::foo' } |
db1ab48d |
29 | } |
30 | |
31 | { |
32 | package My::Test1; |
db1ab48d |
33 | use Moose; |
d03bd989 |
34 | |
b10dde3a |
35 | ::is( ::exception { |
db1ab48d |
36 | with 'Role::Foo', 'Role::Bar'; |
b10dde3a |
37 | }, undef, '... our mutually recursive roles combine okay' ); |
d03bd989 |
38 | |
db1ab48d |
39 | package My::Test2; |
db1ab48d |
40 | use Moose; |
d03bd989 |
41 | |
b10dde3a |
42 | ::is( ::exception { |
db1ab48d |
43 | with 'Role::Bar', 'Role::Foo'; |
b10dde3a |
44 | }, undef, '... our mutually recursive roles combine okay (no matter what order)' ); |
db1ab48d |
45 | } |
46 | |
47 | my $test1 = My::Test1->new; |
48 | isa_ok($test1, 'My::Test1'); |
49 | |
50 | ok($test1->does('Role::Foo'), '... $test1 does Role::Foo'); |
51 | ok($test1->does('Role::Bar'), '... $test1 does Role::Bar'); |
52 | |
53 | can_ok($test1, 'foo'); |
54 | can_ok($test1, 'bar'); |
55 | |
56 | is($test1->foo, 'Role::Bar::foo', '... $test1->foo worked'); |
57 | is($test1->bar, 'Role::Foo::bar', '... $test1->bar worked'); |
58 | |
59 | my $test2 = My::Test2->new; |
60 | isa_ok($test2, 'My::Test2'); |
61 | |
62 | ok($test2->does('Role::Foo'), '... $test2 does Role::Foo'); |
63 | ok($test2->does('Role::Bar'), '... $test2 does Role::Bar'); |
64 | |
65 | can_ok($test2, 'foo'); |
66 | can_ok($test2, 'bar'); |
67 | |
68 | is($test2->foo, 'Role::Bar::foo', '... $test2->foo worked'); |
69 | is($test2->bar, 'Role::Foo::bar', '... $test2->bar worked'); |
70 | |
71 | # check some meta-stuff |
72 | |
73 | ok(Role::Foo->meta->has_method('bar'), '... it still has the bar method'); |
74 | ok(Role::Foo->meta->requires_method('foo'), '... it still has the required foo method'); |
75 | |
76 | ok(Role::Bar->meta->has_method('foo'), '... it still has the foo method'); |
77 | ok(Role::Bar->meta->requires_method('bar'), '... it still has the required bar method'); |
78 | |
79 | =pod |
80 | |
81 | Role method conflicts |
82 | |
83 | =cut |
84 | |
85 | { |
86 | package Role::Bling; |
db1ab48d |
87 | use Moose::Role; |
d03bd989 |
88 | |
db1ab48d |
89 | sub bling { 'Role::Bling::bling' } |
d03bd989 |
90 | |
db1ab48d |
91 | package Role::Bling::Bling; |
db1ab48d |
92 | use Moose::Role; |
d03bd989 |
93 | |
94 | sub bling { 'Role::Bling::Bling::bling' } |
db1ab48d |
95 | } |
96 | |
97 | { |
98 | package My::Test3; |
db1ab48d |
99 | use Moose; |
d03bd989 |
100 | |
b10dde3a |
101 | ::like( ::exception { |
db1ab48d |
102 | with 'Role::Bling', 'Role::Bling::Bling'; |
b10dde3a |
103 | }, qr/Due to a method name conflict in roles 'Role::Bling' and 'Role::Bling::Bling', the method 'bling' must be implemented or excluded by 'My::Test3'/, '... role methods conflict and method was required' ); |
d03bd989 |
104 | |
db1ab48d |
105 | package My::Test4; |
db1ab48d |
106 | use Moose; |
d03bd989 |
107 | |
b10dde3a |
108 | ::is( ::exception { |
db1ab48d |
109 | with 'Role::Bling'; |
f6bee6fe |
110 | with 'Role::Bling::Bling'; |
b10dde3a |
111 | }, undef, '... role methods didnt conflict when manually combined' ); |
d03bd989 |
112 | |
db1ab48d |
113 | package My::Test5; |
db1ab48d |
114 | use Moose; |
d03bd989 |
115 | |
b10dde3a |
116 | ::is( ::exception { |
db1ab48d |
117 | with 'Role::Bling::Bling'; |
f6bee6fe |
118 | with 'Role::Bling'; |
b10dde3a |
119 | }, undef, '... role methods didnt conflict when manually combined (in opposite order)' ); |
d03bd989 |
120 | |
db1ab48d |
121 | package My::Test6; |
db1ab48d |
122 | use Moose; |
d03bd989 |
123 | |
b10dde3a |
124 | ::is( ::exception { |
db1ab48d |
125 | with 'Role::Bling::Bling', 'Role::Bling'; |
b10dde3a |
126 | }, undef, '... role methods didnt conflict when manually resolved' ); |
d03bd989 |
127 | |
db1ab48d |
128 | sub bling { 'My::Test6::bling' } |
24817476 |
129 | |
130 | package My::Test7; |
131 | use Moose; |
132 | |
133 | ::is( ::exception { |
134 | with 'Role::Bling::Bling', { -excludes => ['bling'] }, 'Role::Bling'; |
135 | }, undef, '... role methods didnt conflict when one of the conflicting methods is excluded' ); |
136 | |
137 | package My::Test8; |
138 | use Moose; |
139 | |
140 | ::is( ::exception { |
141 | with 'Role::Bling::Bling', { -excludes => ['bling'], -alias => { bling => 'bling_bling' } }, 'Role::Bling'; |
142 | }, undef, '... role methods didnt conflict when one of the conflicting methods is excluded and aliased' ); |
db1ab48d |
143 | } |
144 | |
145 | ok(!My::Test3->meta->has_method('bling'), '... we didnt get any methods in the conflict'); |
146 | ok(My::Test4->meta->has_method('bling'), '... we did get the method when manually dealt with'); |
147 | ok(My::Test5->meta->has_method('bling'), '... we did get the method when manually dealt with'); |
148 | ok(My::Test6->meta->has_method('bling'), '... we did get the method when manually dealt with'); |
24817476 |
149 | ok(My::Test7->meta->has_method('bling'), '... we did get the method when manually dealt with'); |
150 | ok(My::Test8->meta->has_method('bling'), '... we did get the method when manually dealt with'); |
151 | ok(My::Test8->meta->has_method('bling_bling'), '... we did get the aliased method too'); |
db1ab48d |
152 | |
d79e62fd |
153 | ok(!My::Test3->does('Role::Bling'), '... our class does() the correct roles'); |
154 | ok(!My::Test3->does('Role::Bling::Bling'), '... our class does() the correct roles'); |
155 | ok(My::Test4->does('Role::Bling'), '... our class does() the correct roles'); |
156 | ok(My::Test4->does('Role::Bling::Bling'), '... our class does() the correct roles'); |
157 | ok(My::Test5->does('Role::Bling'), '... our class does() the correct roles'); |
158 | ok(My::Test5->does('Role::Bling::Bling'), '... our class does() the correct roles'); |
159 | ok(My::Test6->does('Role::Bling'), '... our class does() the correct roles'); |
160 | ok(My::Test6->does('Role::Bling::Bling'), '... our class does() the correct roles'); |
24817476 |
161 | ok(My::Test7->does('Role::Bling'), '... our class does() the correct roles'); |
162 | ok(My::Test7->does('Role::Bling::Bling'), '... our class does() the correct roles'); |
163 | ok(My::Test8->does('Role::Bling'), '... our class does() the correct roles'); |
164 | ok(My::Test8->does('Role::Bling::Bling'), '... our class does() the correct roles'); |
d79e62fd |
165 | |
db1ab48d |
166 | is(My::Test4->bling, 'Role::Bling::bling', '... and we got the first method that was added'); |
167 | is(My::Test5->bling, 'Role::Bling::Bling::bling', '... and we got the first method that was added'); |
168 | is(My::Test6->bling, 'My::Test6::bling', '... and we got the local method'); |
24817476 |
169 | is(My::Test7->bling, 'Role::Bling::bling', '... and we got the non-excluded method'); |
170 | is(My::Test8->bling, 'Role::Bling::bling', '... and we got the non-excluded/aliased method'); |
171 | is(My::Test8->bling_bling, 'Role::Bling::Bling::bling', '... and the aliased method comes from the correct role'); |
db1ab48d |
172 | |
173 | # check how this affects role compostion |
174 | |
175 | { |
176 | package Role::Bling::Bling::Bling; |
db1ab48d |
177 | use Moose::Role; |
d03bd989 |
178 | |
db1ab48d |
179 | with 'Role::Bling::Bling'; |
d03bd989 |
180 | |
181 | sub bling { 'Role::Bling::Bling::Bling::bling' } |
db1ab48d |
182 | } |
183 | |
184 | ok(Role::Bling::Bling->meta->has_method('bling'), '... still got the bling method in Role::Bling::Bling'); |
d79e62fd |
185 | ok(Role::Bling::Bling->meta->does_role('Role::Bling::Bling'), '... our role correctly does() the other role'); |
fb1e11d5 |
186 | ok(Role::Bling::Bling::Bling->meta->has_method('bling'), '... dont have the bling method in Role::Bling::Bling::Bling'); |
d03bd989 |
187 | is(Role::Bling::Bling::Bling->meta->get_method('bling')->(), |
d05cd563 |
188 | 'Role::Bling::Bling::Bling::bling', |
189 | '... still got the bling method in Role::Bling::Bling::Bling'); |
db1ab48d |
190 | |
fb1e11d5 |
191 | |
db1ab48d |
192 | =pod |
193 | |
194 | Role attribute conflicts |
195 | |
196 | =cut |
197 | |
198 | { |
199 | package Role::Boo; |
db1ab48d |
200 | use Moose::Role; |
d03bd989 |
201 | |
db1ab48d |
202 | has 'ghost' => (is => 'ro', default => 'Role::Boo::ghost'); |
d03bd989 |
203 | |
db1ab48d |
204 | package Role::Boo::Hoo; |
db1ab48d |
205 | use Moose::Role; |
d03bd989 |
206 | |
db1ab48d |
207 | has 'ghost' => (is => 'ro', default => 'Role::Boo::Hoo::ghost'); |
208 | } |
209 | |
210 | { |
211 | package My::Test7; |
db1ab48d |
212 | use Moose; |
d03bd989 |
213 | |
b10dde3a |
214 | ::like( ::exception { |
db1ab48d |
215 | with 'Role::Boo', 'Role::Boo::Hoo'; |
b10dde3a |
216 | }, qr/We have encountered an attribute conflict.+ghost/ ); |
db1ab48d |
217 | |
218 | package My::Test8; |
db1ab48d |
219 | use Moose; |
220 | |
b10dde3a |
221 | ::is( ::exception { |
db1ab48d |
222 | with 'Role::Boo'; |
223 | with 'Role::Boo::Hoo'; |
b10dde3a |
224 | }, undef, '... role attrs didnt conflict when manually combined' ); |
d03bd989 |
225 | |
db1ab48d |
226 | package My::Test9; |
db1ab48d |
227 | use Moose; |
228 | |
b10dde3a |
229 | ::is( ::exception { |
db1ab48d |
230 | with 'Role::Boo::Hoo'; |
231 | with 'Role::Boo'; |
b10dde3a |
232 | }, undef, '... role attrs didnt conflict when manually combined' ); |
db1ab48d |
233 | |
234 | package My::Test10; |
db1ab48d |
235 | use Moose; |
d03bd989 |
236 | |
237 | has 'ghost' => (is => 'ro', default => 'My::Test10::ghost'); |
238 | |
b10dde3a |
239 | ::like( ::exception { |
db1ab48d |
240 | with 'Role::Boo', 'Role::Boo::Hoo'; |
b10dde3a |
241 | }, qr/We have encountered an attribute conflict/, '... role attrs conflict and cannot be manually disambiguted' ); |
db1ab48d |
242 | |
243 | } |
244 | |
245 | ok(!My::Test7->meta->has_attribute('ghost'), '... we didnt get any attributes in the conflict'); |
246 | ok(My::Test8->meta->has_attribute('ghost'), '... we did get an attributes when manually composed'); |
247 | ok(My::Test9->meta->has_attribute('ghost'), '... we did get an attributes when manually composed'); |
248 | ok(My::Test10->meta->has_attribute('ghost'), '... we did still have an attribute ghost (conflict does not mess with class)'); |
249 | |
d79e62fd |
250 | ok(!My::Test7->does('Role::Boo'), '... our class does() the correct roles'); |
251 | ok(!My::Test7->does('Role::Boo::Hoo'), '... our class does() the correct roles'); |
252 | ok(My::Test8->does('Role::Boo'), '... our class does() the correct roles'); |
253 | ok(My::Test8->does('Role::Boo::Hoo'), '... our class does() the correct roles'); |
254 | ok(My::Test9->does('Role::Boo'), '... our class does() the correct roles'); |
255 | ok(My::Test9->does('Role::Boo::Hoo'), '... our class does() the correct roles'); |
256 | ok(!My::Test10->does('Role::Boo'), '... our class does() the correct roles'); |
257 | ok(!My::Test10->does('Role::Boo::Hoo'), '... our class does() the correct roles'); |
258 | |
db1ab48d |
259 | can_ok('My::Test8', 'ghost'); |
260 | can_ok('My::Test9', 'ghost'); |
261 | can_ok('My::Test10', 'ghost'); |
262 | |
263 | is(My::Test8->new->ghost, 'Role::Boo::ghost', '... got the expected default attr value'); |
264 | is(My::Test9->new->ghost, 'Role::Boo::Hoo::ghost', '... got the expected default attr value'); |
265 | is(My::Test10->new->ghost, 'My::Test10::ghost', '... got the expected default attr value'); |
266 | |
d05cd563 |
267 | =pod |
268 | |
269 | Role override method conflicts |
270 | |
271 | =cut |
272 | |
0558683c |
273 | { |
274 | package Role::Plot; |
275 | use Moose::Role; |
d03bd989 |
276 | |
0558683c |
277 | override 'twist' => sub { |
278 | super() . ' -> Role::Plot::twist'; |
279 | }; |
d03bd989 |
280 | |
0558683c |
281 | package Role::Truth; |
282 | use Moose::Role; |
d03bd989 |
283 | |
0558683c |
284 | override 'twist' => sub { |
285 | super() . ' -> Role::Truth::twist'; |
286 | }; |
287 | } |
288 | |
289 | { |
290 | package My::Test::Base; |
291 | use Moose; |
d03bd989 |
292 | |
0558683c |
293 | sub twist { 'My::Test::Base::twist' } |
d03bd989 |
294 | |
0558683c |
295 | package My::Test11; |
296 | use Moose; |
d03bd989 |
297 | |
0558683c |
298 | extends 'My::Test::Base'; |
299 | |
b10dde3a |
300 | ::is( ::exception { |
0558683c |
301 | with 'Role::Truth'; |
b10dde3a |
302 | }, undef, '... composed the role with override okay' ); |
d03bd989 |
303 | |
0558683c |
304 | package My::Test12; |
305 | use Moose; |
306 | |
307 | extends 'My::Test::Base'; |
308 | |
b10dde3a |
309 | ::is( ::exception { |
0558683c |
310 | with 'Role::Plot'; |
b10dde3a |
311 | }, undef, '... composed the role with override okay' ); |
d03bd989 |
312 | |
0558683c |
313 | package My::Test13; |
314 | use Moose; |
315 | |
b10dde3a |
316 | ::isnt( ::exception { |
d03bd989 |
317 | with 'Role::Plot'; |
b10dde3a |
318 | }, undef, '... cannot compose it because we have no superclass' ); |
d03bd989 |
319 | |
0558683c |
320 | package My::Test14; |
321 | use Moose; |
322 | |
323 | extends 'My::Test::Base'; |
324 | |
b10dde3a |
325 | ::like( ::exception { |
d03bd989 |
326 | with 'Role::Plot', 'Role::Truth'; |
b10dde3a |
327 | }, qr/Two \'override\' methods of the same name encountered/, '... cannot compose it because we have no superclass' ); |
0558683c |
328 | } |
329 | |
330 | ok(My::Test11->meta->has_method('twist'), '... the twist method has been added'); |
331 | ok(My::Test12->meta->has_method('twist'), '... the twist method has been added'); |
332 | ok(!My::Test13->meta->has_method('twist'), '... the twist method has not been added'); |
333 | ok(!My::Test14->meta->has_method('twist'), '... the twist method has not been added'); |
334 | |
335 | ok(!My::Test11->does('Role::Plot'), '... our class does() the correct roles'); |
336 | ok(My::Test11->does('Role::Truth'), '... our class does() the correct roles'); |
337 | ok(!My::Test12->does('Role::Truth'), '... our class does() the correct roles'); |
338 | ok(My::Test12->does('Role::Plot'), '... our class does() the correct roles'); |
339 | ok(!My::Test13->does('Role::Plot'), '... our class does() the correct roles'); |
340 | ok(!My::Test14->does('Role::Truth'), '... our class does() the correct roles'); |
341 | ok(!My::Test14->does('Role::Plot'), '... our class does() the correct roles'); |
342 | |
343 | is(My::Test11->twist(), 'My::Test::Base::twist -> Role::Truth::twist', '... got the right method return'); |
344 | is(My::Test12->twist(), 'My::Test::Base::twist -> Role::Plot::twist', '... got the right method return'); |
345 | ok(!My::Test13->can('twist'), '... no twist method here at all'); |
346 | is(My::Test14->twist(), 'My::Test::Base::twist', '... got the right method return (from superclass)'); |
347 | |
348 | { |
349 | package Role::Reality; |
350 | use Moose::Role; |
351 | |
b10dde3a |
352 | ::like( ::exception { |
0558683c |
353 | with 'Role::Plot'; |
b10dde3a |
354 | }, qr/A local method of the same name as been found/, '... could not compose roles here, it dies' ); |
0558683c |
355 | |
356 | sub twist { |
357 | 'Role::Reality::twist'; |
358 | } |
d03bd989 |
359 | } |
0558683c |
360 | |
361 | ok(Role::Reality->meta->has_method('twist'), '... the twist method has not been added'); |
fb1e11d5 |
362 | #ok(!Role::Reality->meta->does_role('Role::Plot'), '... our role does() the correct roles'); |
d03bd989 |
363 | is(Role::Reality->meta->get_method('twist')->(), |
364 | 'Role::Reality::twist', |
0558683c |
365 | '... the twist method returns the right value'); |
3c5fd53a |
366 | |
f0916ad8 |
367 | # Ovid's test case from rt.cpan.org #44 |
368 | { |
369 | package Role1; |
370 | use Moose::Role; |
371 | |
372 | sub foo {} |
373 | } |
374 | { |
375 | package Role2; |
376 | use Moose::Role; |
377 | |
378 | sub foo {} |
379 | } |
380 | { |
381 | package Conflicts; |
382 | use Moose; |
383 | |
b10dde3a |
384 | ::like( ::exception { |
f0916ad8 |
385 | with qw(Role1 Role2); |
b10dde3a |
386 | }, qr/Due to a method name conflict in roles 'Role1' and 'Role2', the method 'foo' must be implemented or excluded by 'Conflicts'/ ); |
f0916ad8 |
387 | } |
388 | |
a39b044e |
389 | { |
390 | package HasFooMeth; |
391 | use Moose::Role; |
392 | |
393 | requires 'bar'; |
394 | |
395 | sub foo {} |
5161b9fe |
396 | sub baz {} |
a39b044e |
397 | } |
398 | |
399 | { |
400 | package AlsoHasFooMeth; |
401 | use Moose::Role; |
402 | |
403 | with 'HasFooMeth'; |
404 | |
405 | sub foo {} |
406 | } |
407 | |
408 | { |
409 | package UsesAlso1; |
410 | use Moose; |
411 | |
412 | sub bar {} |
413 | |
414 | ::like( |
415 | ::exception{ with 'AlsoHasFooMeth' }, |
416 | qr/\QDue to a method name conflict in roles 'AlsoHasFooMeth' and 'HasFooMeth', the method 'foo' must be implemented or excluded by 'UsesAlso1'/, |
417 | 'got an exception when trying to consume a role that has a conflict' |
418 | ); |
419 | } |
420 | |
421 | { |
422 | package UsesAlso2; |
423 | use Moose; |
424 | |
425 | sub bar {} |
426 | |
427 | ::is( |
428 | ::exception{ with 'AlsoHasFooMeth', { -excludes => ['foo'] } }, |
429 | undef, |
430 | 'no exception when trying to consume a role that has a conflict if we exclude the conflicting method' |
431 | ); |
432 | } |
433 | |
434 | { |
435 | package UsesAlso3; |
436 | use Moose; |
437 | |
438 | ::like( |
439 | ::exception{ with 'AlsoHasFooMeth', |
440 | { -excludes => [ 'foo', 'bar' ] } }, |
441 | qr/\Q'AlsoHasFooMeth' requires the method 'bar' to be implemented by 'UsesAlso3'/, |
442 | 'cannot exclude a required method if it is not a conflicting method' |
443 | ); |
444 | } |
445 | |
66c51e9d |
446 | { |
447 | package UsesAlso4; |
448 | use Moose; |
449 | |
450 | sub bar {} |
451 | |
452 | ::is( |
5161b9fe |
453 | ::exception{ with 'AlsoHasFooMeth', { -alias => { baz => 'foo' } } }, |
66c51e9d |
454 | undef, |
5161b9fe |
455 | 'aliasing a method to the conflicting method suppresses the conflict error' |
66c51e9d |
456 | ); |
457 | } |
458 | |
3c5fd53a |
459 | =pod |
460 | |
461 | Role conflicts between attributes and methods |
462 | |
21716c07 |
463 | [15:23] <kolibrie> when class defines method and role defines method, class wins |
464 | [15:24] <kolibrie> when class 'has' method and role defines method, class wins |
465 | [15:24] <kolibrie> when class defines method and role 'has' method, role wins |
466 | [15:24] <kolibrie> when class 'has' method and role 'has' method, role wins |
6549b0d1 |
467 | [15:24] <kolibrie> which means when class 'has' method and two roles 'has' method, no tiebreak is detected |
21716c07 |
468 | [15:24] <perigrin> this is with role and has declaration in the exact same order in every case? |
469 | [15:25] <kolibrie> yes |
470 | [15:25] <perigrin> interesting |
471 | [15:25] <kolibrie> that's what I thought |
472 | [15:26] <kolibrie> does that sound like something I should write a test for? |
473 | [15:27] <perigrin> stevan, ping? |
474 | [15:27] <perigrin> I'm not sure what the right answer for composition is. |
475 | [15:27] <perigrin> who should win |
476 | [15:27] <perigrin> if I were to guess I'd say the class should always win. |
477 | [15:27] <kolibrie> that would be my guess, but I thought I would ask to make sure |
478 | [15:29] <stevan> kolibrie: please write a test |
479 | [15:29] <stevan> I am not exactly sure who should win either,.. but I suspect it is not working correctly right now |
480 | [15:29] <stevan> I know exactly why it is doing what it is doing though |
481 | |
482 | Now I have to decide actually what happens, and how to fix it. |
483 | - SL |
3c5fd53a |
484 | |
485 | { |
486 | package Role::Method; |
487 | use Moose::Role; |
d03bd989 |
488 | |
3c5fd53a |
489 | sub ghost { 'Role::Method::ghost' } |
490 | |
491 | package Role::Method2; |
492 | use Moose::Role; |
d03bd989 |
493 | |
3c5fd53a |
494 | sub ghost { 'Role::Method2::ghost' } |
495 | |
496 | package Role::Attribute; |
497 | use Moose::Role; |
d03bd989 |
498 | |
3c5fd53a |
499 | has 'ghost' => (is => 'ro', default => 'Role::Attribute::ghost'); |
500 | |
501 | package Role::Attribute2; |
502 | use Moose::Role; |
d03bd989 |
503 | |
3c5fd53a |
504 | has 'ghost' => (is => 'ro', default => 'Role::Attribute2::ghost'); |
505 | } |
506 | |
507 | { |
508 | package My::Test15; |
509 | use Moose; |
510 | |
53a4d826 |
511 | ::lives_ok { |
3c5fd53a |
512 | with 'Role::Method'; |
53a4d826 |
513 | } '... composed the method role into the method class'; |
3c5fd53a |
514 | |
515 | sub ghost { 'My::Test15::ghost' } |
516 | |
517 | package My::Test16; |
518 | use Moose; |
519 | |
53a4d826 |
520 | ::lives_ok { |
3c5fd53a |
521 | with 'Role::Method'; |
53a4d826 |
522 | } '... composed the method role into the attribute class'; |
3c5fd53a |
523 | |
524 | has 'ghost' => (is => 'ro', default => 'My::Test16::ghost'); |
525 | |
526 | package My::Test17; |
527 | use Moose; |
528 | |
53a4d826 |
529 | ::lives_ok { |
3c5fd53a |
530 | with 'Role::Attribute'; |
53a4d826 |
531 | } '... composed the attribute role into the method class'; |
3c5fd53a |
532 | |
533 | sub ghost { 'My::Test17::ghost' } |
534 | |
535 | package My::Test18; |
536 | use Moose; |
537 | |
53a4d826 |
538 | ::lives_ok { |
3c5fd53a |
539 | with 'Role::Attribute'; |
53a4d826 |
540 | } '... composed the attribute role into the attribute class'; |
3c5fd53a |
541 | |
542 | has 'ghost' => (is => 'ro', default => 'My::Test18::ghost'); |
543 | |
544 | package My::Test19; |
545 | use Moose; |
546 | |
53a4d826 |
547 | ::lives_ok { |
3c5fd53a |
548 | with 'Role::Method', 'Role::Method2'; |
53a4d826 |
549 | } '... composed method roles into class with method tiebreaker'; |
3c5fd53a |
550 | |
551 | sub ghost { 'My::Test19::ghost' } |
552 | |
553 | package My::Test20; |
554 | use Moose; |
555 | |
53a4d826 |
556 | ::lives_ok { |
3c5fd53a |
557 | with 'Role::Method', 'Role::Method2'; |
53a4d826 |
558 | } '... composed method roles into class with attribute tiebreaker'; |
3c5fd53a |
559 | |
560 | has 'ghost' => (is => 'ro', default => 'My::Test20::ghost'); |
561 | |
562 | package My::Test21; |
563 | use Moose; |
564 | |
53a4d826 |
565 | ::lives_ok { |
3c5fd53a |
566 | with 'Role::Attribute', 'Role::Attribute2'; |
53a4d826 |
567 | } '... composed attribute roles into class with method tiebreaker'; |
3c5fd53a |
568 | |
569 | sub ghost { 'My::Test21::ghost' } |
570 | |
571 | package My::Test22; |
572 | use Moose; |
573 | |
53a4d826 |
574 | ::lives_ok { |
3c5fd53a |
575 | with 'Role::Attribute', 'Role::Attribute2'; |
53a4d826 |
576 | } '... composed attribute roles into class with attribute tiebreaker'; |
3c5fd53a |
577 | |
578 | has 'ghost' => (is => 'ro', default => 'My::Test22::ghost'); |
579 | |
580 | package My::Test23; |
581 | use Moose; |
582 | |
53a4d826 |
583 | ::lives_ok { |
3c5fd53a |
584 | with 'Role::Method', 'Role::Attribute'; |
53a4d826 |
585 | } '... composed method and attribute role into class with method tiebreaker'; |
3c5fd53a |
586 | |
587 | sub ghost { 'My::Test23::ghost' } |
588 | |
589 | package My::Test24; |
590 | use Moose; |
591 | |
53a4d826 |
592 | ::lives_ok { |
3c5fd53a |
593 | with 'Role::Method', 'Role::Attribute'; |
53a4d826 |
594 | } '... composed method and attribute role into class with attribute tiebreaker'; |
3c5fd53a |
595 | |
596 | has 'ghost' => (is => 'ro', default => 'My::Test24::ghost'); |
597 | |
598 | package My::Test25; |
599 | use Moose; |
600 | |
53a4d826 |
601 | ::lives_ok { |
3c5fd53a |
602 | with 'Role::Attribute', 'Role::Method'; |
53a4d826 |
603 | } '... composed attribute and method role into class with method tiebreaker'; |
3c5fd53a |
604 | |
605 | sub ghost { 'My::Test25::ghost' } |
606 | |
607 | package My::Test26; |
608 | use Moose; |
609 | |
53a4d826 |
610 | ::lives_ok { |
3c5fd53a |
611 | with 'Role::Attribute', 'Role::Method'; |
53a4d826 |
612 | } '... composed attribute and method role into class with attribute tiebreaker'; |
3c5fd53a |
613 | |
614 | has 'ghost' => (is => 'ro', default => 'My::Test26::ghost'); |
615 | } |
616 | |
617 | my $test15 = My::Test15->new; |
618 | isa_ok($test15, 'My::Test15'); |
619 | is($test15->ghost, 'My::Test15::ghost', '... we access the method from the class and ignore the role method'); |
620 | |
621 | my $test16 = My::Test16->new; |
622 | isa_ok($test16, 'My::Test16'); |
623 | is($test16->ghost, 'My::Test16::ghost', '... we access the attribute from the class and ignore the role method'); |
624 | |
625 | my $test17 = My::Test17->new; |
626 | isa_ok($test17, 'My::Test17'); |
627 | is($test17->ghost, 'My::Test17::ghost', '... we access the method from the class and ignore the role attribute'); |
628 | |
629 | my $test18 = My::Test18->new; |
630 | isa_ok($test18, 'My::Test18'); |
631 | is($test18->ghost, 'My::Test18::ghost', '... we access the attribute from the class and ignore the role attribute'); |
632 | |
633 | my $test19 = My::Test19->new; |
634 | isa_ok($test19, 'My::Test19'); |
635 | is($test19->ghost, 'My::Test19::ghost', '... we access the method from the class and ignore the role methods'); |
636 | |
637 | my $test20 = My::Test20->new; |
638 | isa_ok($test20, 'My::Test20'); |
639 | is($test20->ghost, 'My::Test20::ghost', '... we access the attribute from the class and ignore the role methods'); |
640 | |
641 | my $test21 = My::Test21->new; |
642 | isa_ok($test21, 'My::Test21'); |
643 | is($test21->ghost, 'My::Test21::ghost', '... we access the method from the class and ignore the role attributes'); |
644 | |
645 | my $test22 = My::Test22->new; |
646 | isa_ok($test22, 'My::Test22'); |
647 | is($test22->ghost, 'My::Test22::ghost', '... we access the attribute from the class and ignore the role attributes'); |
648 | |
649 | my $test23 = My::Test23->new; |
650 | isa_ok($test23, 'My::Test23'); |
651 | is($test23->ghost, 'My::Test23::ghost', '... we access the method from the class and ignore the role method and attribute'); |
652 | |
653 | my $test24 = My::Test24->new; |
654 | isa_ok($test24, 'My::Test24'); |
655 | is($test24->ghost, 'My::Test24::ghost', '... we access the attribute from the class and ignore the role method and attribute'); |
656 | |
657 | my $test25 = My::Test25->new; |
658 | isa_ok($test25, 'My::Test25'); |
659 | is($test25->ghost, 'My::Test25::ghost', '... we access the method from the class and ignore the role attribute and method'); |
660 | |
661 | my $test26 = My::Test26->new; |
662 | isa_ok($test26, 'My::Test26'); |
663 | is($test26->ghost, 'My::Test26::ghost', '... we access the attribute from the class and ignore the role attribute and method'); |
664 | |
21716c07 |
665 | =cut |
a28e50e4 |
666 | |
667 | done_testing; |