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