Commit | Line | Data |
a6ff1f9e |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 7; |
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 | |
38 | my $obj = Bar->new; |
39 | isa_ok($obj, 'Bar'); |
40 | |
41 | my $foo = Foo->new; |
42 | |
43 | ok(!$obj->can( 'talk' ), "... the role is not composed yet"); |
44 | |
45 | dies_ok { |
46 | $foo->dog($obj) |
47 | } '... and setting the accessor fails (not a Dog yet)'; |
48 | |
49 | Dog->meta->apply($obj); |
50 | |
51 | ok($obj->can('talk'), "... the role is now composed at the object level"); |
52 | |
53 | is($obj->talk, 'woof', '... got the right return value for the newly composed method'); |
54 | |
55 | lives_ok { |
56 | $foo->dog($obj) |
57 | } '... and setting the accessor is okay'; |
58 | |