Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/doc/perl-Moose/t/native_traits/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-Moose/t/native_traits/array_trigger.t
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;

Hry