support weak_ref
[gitmo/Moo.git] / t / accessor-handles.t
CommitLineData
3f343f5c 1use strictures 1;
2use 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
39my $bar = Bar->new(
40 foo => Foo->new, foo2 => Foo->new, foo3 => Foo->new, foo4 => Foo->new
41);
42
43is $bar->one, 1, 'handles works';
44is $bar->two, 2, 'handles works for more than one method';
45
46is $bar->un, 1, 'handles works for aliasing a method';
47
48is $bar->smash, 'smash', 'handles works for a role';
49
50is $bar->eat_curry, 'Curry!', 'handles works for currying';
51
52done_testing;