diff options
Diffstat (limited to 't/native_traits/hash_trigger.t')
-rw-r--r-- | t/native_traits/hash_trigger.t | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/t/native_traits/hash_trigger.t b/t/native_traits/hash_trigger.t new file mode 100644 index 0000000..1618f3c --- /dev/null +++ b/t/native_traits/hash_trigger.t @@ -0,0 +1,54 @@ +use strict; +use warnings; + +use Test::More; + +{ + + package Foo; + use Moose; + + our @TriggerArgs; + + has hash => ( + traits => ['Hash'], + is => 'rw', + isa => 'HashRef', + handles => { + delete_key => 'delete', + set_key => 'set', + }, + clearer => 'clear_key', + trigger => sub { @TriggerArgs = @_ }, + ); +} + +my $foo = Foo->new; + +{ + $foo->hash( { x => 1, y => 2 } ); + + is_deeply( + \@Foo::TriggerArgs, + [ $foo, { x => 1, y => 2 } ], + 'trigger was called for normal writer' + ); + + $foo->set_key( z => 5 ); + + is_deeply( + \@Foo::TriggerArgs, + [ $foo, { x => 1, y => 2, z => 5 }, { x => 1, y => 2 } ], + 'trigger was called on set' + ); + + $foo->delete_key('y'); + + is_deeply( + \@Foo::TriggerArgs, + [ $foo, { x => 1, z => 5 }, { x => 1, y => 2, z => 5 } ], + 'trigger was called on delete' + ); +} + +done_testing; |