add another test to confirm that the coercion is run on the resulting arrayref, as...
[gitmo/Moose.git] / t / 070_native_traits / 012_array_trigger.t
CommitLineData
ccd17aa9 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6
7{
8 package Foo;
9 use Moose;
10
11 our @TriggerArgs;
12
13 has array => (
14 traits => ['Array'],
15 is => 'rw',
16 isa => 'ArrayRef',
17 handles => {
18 push_array => 'push',
19 set_array => 'set',
20 },
21 clearer => 'clear_array',
22 trigger => sub { @TriggerArgs = @_ },
23 );
24}
25
26my $foo = Foo->new;
27
28{
29 $foo->array( [ 1, 2, 3 ] );
30
31 is_deeply(
32 \@Foo::TriggerArgs,
33 [ $foo, [ 1, 2, 3 ] ],
34 'trigger was called for normal writer'
35 );
36
37 $foo->push_array(5);
38
39 is_deeply(
40 \@Foo::TriggerArgs,
41 [ $foo, [ 1, 2, 3, 5 ], [ 1, 2, 3 ] ],
42 'trigger was called on push'
43 );
44
45 $foo->set_array( 1, 42 );
46
47 is_deeply(
48 \@Foo::TriggerArgs,
49 [ $foo, [ 1, 42, 3, 5 ], [ 1, 2, 3, 5 ] ],
50 'trigger was called on set'
51 );
52}
53
54done_testing;