Commit | Line | Data |
c3b35392 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 9; |
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 | |
30 | my $obj = Foo->new; |
31 | isa_ok($obj, 'Foo'); |
32 | |
33 | ok(!$obj->can( 'talk' ), "... the role is not composed yet"); |
34 | ok(!$obj->does('Dog'), '... we do not do any roles yet'); |
35 | |
36 | dies_ok { |
37 | $obj->dog($obj) |
38 | } '... and setting the accessor fails (not a Dog yet)'; |
39 | |
40 | Dog->meta->apply($obj); |
41 | |
42 | ok($obj->does('Dog'), '... we now do the Bark role'); |
43 | ok($obj->can('talk'), "... the role is now composed at the object level"); |
44 | |
45 | is($obj->talk, 'woof', '... got the right return value for the newly composed method'); |
46 | |
47 | lives_ok { |
48 | $obj->dog($obj) |
49 | } '... and setting the accessor is okay'; |
50 | |