summaryrefslogtreecommitdiff
path: root/t/native_traits/array_trigger.t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /t/native_traits/array_trigger.t
downloadMoose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz
Diffstat (limited to 't/native_traits/array_trigger.t')
-rw-r--r--t/native_traits/array_trigger.t53
1 files changed, 53 insertions, 0 deletions
diff --git a/t/native_traits/array_trigger.t b/t/native_traits/array_trigger.t
new file mode 100644
index 0000000..419c303
--- /dev/null
+++ b/t/native_traits/array_trigger.t
@@ -0,0 +1,53 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+{
+ package Foo;
+ use Moose;
+
+ our @TriggerArgs;
+
+ has array => (
+ traits => ['Array'],
+ is => 'rw',
+ isa => 'ArrayRef',
+ handles => {
+ push_array => 'push',
+ set_array => 'set',
+ },
+ clearer => 'clear_array',
+ trigger => sub { @TriggerArgs = @_ },
+ );
+}
+
+my $foo = Foo->new;
+
+{
+ $foo->array( [ 1, 2, 3 ] );
+
+ is_deeply(
+ \@Foo::TriggerArgs,
+ [ $foo, [ 1, 2, 3 ] ],
+ 'trigger was called for normal writer'
+ );
+
+ $foo->push_array(5);
+
+ is_deeply(
+ \@Foo::TriggerArgs,
+ [ $foo, [ 1, 2, 3, 5 ], [ 1, 2, 3 ] ],
+ 'trigger was called on push'
+ );
+
+ $foo->set_array( 1, 42 );
+
+ is_deeply(
+ \@Foo::TriggerArgs,
+ [ $foo, [ 1, 42, 3, 5 ], [ 1, 2, 3, 5 ] ],
+ 'trigger was called on set'
+ );
+}
+
+done_testing;