Commit | Line | Data |
cdf3cae6 |
1 | use strict; |
2 | use warnings; |
3 | |
63723115 |
4 | use Test::More tests => 3; |
cdf3cae6 |
5 | |
6 | { |
7 | package Thingy; |
8 | use Moose; |
9 | |
10 | has callback => ( |
11 | traits => ['Code'], |
12 | is => 'ro', |
13 | isa => 'CodeRef', |
14 | required => 1, |
15 | handles => { 'invoke_callback' => 'execute' }, |
16 | ); |
63723115 |
17 | |
18 | has multiplier => ( |
19 | traits => ['Code'], |
20 | is => 'ro', |
21 | isa => 'CodeRef', |
22 | required => 1, |
23 | handles => { 'multiply' => 'execute' }, |
24 | ); |
cdf3cae6 |
25 | } |
26 | |
27 | my $i = 0; |
63723115 |
28 | my $thingy = Thingy->new( |
29 | callback => sub { ++$i }, |
30 | multiplier => sub { $_[0] * 2 } |
31 | ); |
cdf3cae6 |
32 | |
33 | is($i, 0); |
34 | $thingy->invoke_callback; |
35 | is($i, 1); |
63723115 |
36 | is($thingy->multiply(3), 6); |