Commit | Line | Data |
67199842 |
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 | |
11 | |
12 | |
13 | { |
14 | package Dog; |
15 | use Mouse::Role; |
16 | |
17 | sub talk { 'woof' } |
18 | |
19 | package Foo; |
20 | use Mouse; |
21 | |
22 | has 'dog' => ( |
23 | is => 'rw', |
24 | does => 'Dog', |
25 | ); |
26 | |
27 | no Mouse; |
28 | |
29 | package Bar; |
30 | |
31 | sub new { |
32 | return bless {}, shift; |
33 | } |
34 | } |
35 | |
36 | my $bar = Bar->new; |
6cfa1e5e |
37 | isa_ok($bar, 'Bar'); |
67199842 |
38 | |
39 | my $foo = Foo->new; |
6cfa1e5e |
40 | isa_ok($foo, 'Foo'); |
67199842 |
41 | |
42 | ok(!$bar->can( 'talk' ), "... the role is not composed yet"); |
43 | |
44 | dies_ok { |
45 | $foo->dog($bar) |
46 | } '... and setting the accessor fails (not a Dog yet)'; |
47 | |
48 | Dog->meta->apply($bar); |
49 | |
50 | ok($bar->can('talk'), "... the role is now composed at the object level"); |
51 | |
52 | is($bar->talk, 'woof', '... got the right return value for the newly composed method'); |
53 | |
54 | lives_ok { |
55 | $foo->dog($bar) |
56 | } '... and setting the accessor is okay'; |
57 | |