From: Dave Rolsky Date: Sat, 25 Sep 2010 23:23:40 +0000 (-0500) Subject: Add tests for triggers on a native Hash trait attr X-Git-Tag: 1.15~80 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=be9f5a891272973989ae73de2beb8fbce7582bce;p=gitmo%2FMoose.git Add tests for triggers on a native Hash trait attr --- diff --git a/t/070_native_traits/052_hash_trigger.t b/t/070_native_traits/052_hash_trigger.t new file mode 100644 index 0000000..26f343c --- /dev/null +++ b/t/070_native_traits/052_hash_trigger.t @@ -0,0 +1,55 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +{ + + 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;