aee5958ba2004e2b9fee59c20e0238fac18c8a84
[gitmo/Role-Tiny.git] / t / accessor-handles.t
1 use strictures 1;
2 use Test::More;
3
4 {
5   package Robot;
6
7   use Moo::Role;
8
9   requires 'smash';
10
11 }
12
13 {
14   package Foo;
15
16   use Moo;
17
18   with 'Robot';
19
20   sub one {1}
21   sub two {2}
22   sub smash {'smash'}
23   sub yum {$_[1]}
24 }
25
26 {
27   package Bar;
28
29   use Moo;
30
31   has foo => ( is => 'ro', handles => [ qw(one two) ] );
32   has foo2 => ( is => 'ro', handles => { un => 'one' } );
33   has foo3 => ( is => 'ro', handles => 'Robot' );
34   has foo4 => ( is => 'ro', handles => {
35      eat_curry => [ yum => 'Curry!' ],
36   });
37 }
38
39 my $bar = Bar->new(
40   foo => Foo->new, foo2 => Foo->new, foo3 => Foo->new, foo4 => Foo->new
41 );
42
43 is $bar->one, 1, 'handles works';
44 is $bar->two, 2, 'handles works for more than one method';
45
46 is $bar->un, 1, 'handles works for aliasing a method';
47
48 is $bar->smash, 'smash', 'handles works for a role';
49
50 is $bar->eat_curry, 'Curry!', 'handles works for currying';
51
52 done_testing;