handles => "RoleName" should try to load the module
[gitmo/Moo.git] / t / accessor-handles.t
CommitLineData
3f343f5c 1use strictures 1;
2use Test::More;
3
baa7d706 4use 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
49my $bar = Bar->new(
baa7d706 50 foo => Foo->new, foo2 => Foo->new, foo3 => Foo->new, foo4 => Foo->new,
51 foo5 => Baz->new
3f343f5c 52);
53
54is $bar->one, 1, 'handles works';
55is $bar->two, 2, 'handles works for more than one method';
56
57is $bar->un, 1, 'handles works for aliasing a method';
58
59is $bar->smash, 'smash', 'handles works for a role';
60
baa7d706 61is $bar->beep, 'beep', 'handles loads roles';
62
3f343f5c 63is $bar->eat_curry, 'Curry!', 'handles works for currying';
64
65done_testing;