1use Test::More;
2
3my ($foo, $bar, $baz, $bat) = (0) x 4;
4{
5    package Foos;
6    use Moos;
7    has foo => ( trigger => sub { $foo++ } );
8    has bar => ( trigger => sub { $bar++ } );
9    has baz => ( trigger => sub { $baz++ }, default => sub { 42 } );
10    has bat => ( trigger => 1 );
11    sub _trigger_bat { $bat = $_[2] };
12}
13
14
15my $obj = Foos->new(foo => 1);
16is $foo, 1;
17is $bar, 0;
18is $baz, 0;
19is $bat, 0;
20
21$obj->foo(2); $obj->baz($obj->baz + 1);
22is($obj->baz, 43);
23is $foo, 2;
24is $bar, 0;
25is $baz, 1;
26is $bat, 0;
27
28$obj->bat(3);
29is $bat, undef;
30$obj->bat(42);
31is $bat, 3;
32
33done_testing;
34