Commit | Line | Data |
be9f5a89 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | |
7 | { |
8 | |
9 | package Foo; |
10 | use Moose; |
11 | |
12 | our @TriggerArgs; |
13 | |
14 | has hash => ( |
15 | traits => ['Hash'], |
16 | is => 'rw', |
17 | isa => 'HashRef', |
18 | handles => { |
19 | delete_key => 'delete', |
20 | set_key => 'set', |
21 | }, |
22 | clearer => 'clear_key', |
23 | trigger => sub { @TriggerArgs = @_ }, |
24 | ); |
25 | } |
26 | |
27 | my $foo = Foo->new; |
28 | |
29 | { |
30 | $foo->hash( { x => 1, y => 2 } ); |
31 | |
32 | is_deeply( |
33 | \@Foo::TriggerArgs, |
34 | [ $foo, { x => 1, y => 2 } ], |
35 | 'trigger was called for normal writer' |
36 | ); |
37 | |
38 | $foo->set_key( z => 5 ); |
39 | |
40 | is_deeply( |
41 | \@Foo::TriggerArgs, |
42 | [ $foo, { x => 1, y => 2, z => 5 }, { x => 1, y => 2 } ], |
43 | 'trigger was called on set' |
44 | ); |
45 | |
46 | $foo->delete_key('y'); |
47 | |
48 | is_deeply( |
49 | \@Foo::TriggerArgs, |
50 | [ $foo, { x => 1, z => 5 }, { x => 1, y => 2, z => 5 } ], |
51 | 'trigger was called on delete' |
52 | ); |
53 | } |
54 | |
55 | done_testing; |