File: hash_trigger.t

package info (click to toggle)
libmoose-perl 2.4000-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,408 kB
  • sloc: perl: 21,275; ansic: 291; makefile: 10
file content (54 lines) | stat: -rw-r--r-- 975 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;