Commit | Line | Data |
3f343f5c |
1 | use strictures 1; |
2 | use Test::More; |
3 | |
baa7d706 |
4 | use lib "t/lib"; |
5 | |
6 | { |
7 | package Baz; |
8 | use Moo; |
9 | sub beep {'beep'} |
10 | } |
11 | |
3f343f5c |
12 | { |
13 | package Robot; |
14 | |
15 | use Moo::Role; |
16 | |
17 | requires 'smash'; |
baa7d706 |
18 | $INC{"Robot.pm"} = 1; |
3f343f5c |
19 | |
20 | } |
21 | |
22 | { |
23 | package Foo; |
24 | |
25 | use Moo; |
26 | |
27 | with 'Robot'; |
28 | |
29 | sub one {1} |
30 | sub two {2} |
31 | sub smash {'smash'} |
32 | sub yum {$_[1]} |
33 | } |
34 | |
35 | { |
36 | package Bar; |
37 | |
38 | use Moo; |
39 | |
40 | has foo => ( is => 'ro', handles => [ qw(one two) ] ); |
41 | has foo2 => ( is => 'ro', handles => { un => 'one' } ); |
42 | has foo3 => ( is => 'ro', handles => 'Robot' ); |
43 | has foo4 => ( is => 'ro', handles => { |
44 | eat_curry => [ yum => 'Curry!' ], |
45 | }); |
baa7d706 |
46 | has foo5 => ( is => 'ro', handles => 'ExtRobot' ); |
3f343f5c |
47 | } |
48 | |
49 | my $bar = Bar->new( |
baa7d706 |
50 | foo => Foo->new, foo2 => Foo->new, foo3 => Foo->new, foo4 => Foo->new, |
51 | foo5 => Baz->new |
3f343f5c |
52 | ); |
53 | |
54 | is $bar->one, 1, 'handles works'; |
55 | is $bar->two, 2, 'handles works for more than one method'; |
56 | |
57 | is $bar->un, 1, 'handles works for aliasing a method'; |
58 | |
59 | is $bar->smash, 'smash', 'handles works for a role'; |
60 | |
baa7d706 |
61 | is $bar->beep, 'beep', 'handles loads roles'; |
62 | |
3f343f5c |
63 | is $bar->eat_curry, 'Curry!', 'handles works for currying'; |
64 | |
65 | done_testing; |