Commit | Line | Data |
---|---|---|
a6ff1f9e | 1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
a28e50e4 | 6 | use Test::More; |
a6ff1f9e | 7 | use Test::Exception; |
8 | use Scalar::Util 'blessed'; | |
9 | ||
7ff56534 | 10 | |
a6ff1f9e | 11 | { |
12 | package Dog; | |
13 | use Moose::Role; | |
14 | ||
15 | sub talk { 'woof' } | |
16 | ||
17 | package Foo; | |
18 | use Moose; | |
19 | ||
20 | has 'dog' => ( | |
21 | is => 'rw', | |
22 | does => 'Dog', | |
23 | ); | |
24 | ||
25 | no Moose; | |
26 | ||
27 | package Bar; | |
28 | ||
29 | sub new { | |
30 | return bless {}, shift; | |
31 | } | |
32 | } | |
33 | ||
238b424d | 34 | my $bar = Bar->new; |
d03bd989 | 35 | isa_ok($bar, 'Bar'); |
a6ff1f9e | 36 | |
37 | my $foo = Foo->new; | |
d03bd989 | 38 | isa_ok($foo, 'Foo'); |
a6ff1f9e | 39 | |
238b424d | 40 | ok(!$bar->can( 'talk' ), "... the role is not composed yet"); |
a6ff1f9e | 41 | |
42 | dies_ok { | |
238b424d | 43 | $foo->dog($bar) |
a6ff1f9e | 44 | } '... and setting the accessor fails (not a Dog yet)'; |
45 | ||
238b424d | 46 | Dog->meta->apply($bar); |
a6ff1f9e | 47 | |
238b424d | 48 | ok($bar->can('talk'), "... the role is now composed at the object level"); |
a6ff1f9e | 49 | |
238b424d | 50 | is($bar->talk, 'woof', '... got the right return value for the newly composed method'); |
a6ff1f9e | 51 | |
52 | lives_ok { | |
238b424d | 53 | $foo->dog($bar) |
a6ff1f9e | 54 | } '... and setting the accessor is okay'; |
55 | ||
a28e50e4 | 56 | done_testing; |