17 my ($self, $value) = @_;
18 push @trigger, [$self, $value];
22 has foobar => ( # from Net::Google::DataAPI
27 trigger => sub{ $_[0]->update },
28 default => sub{ 'piyo' },
30 clearer => 'clear_foobar',
43 } "it's no longer an error to have trigger on a readonly attribute";
50 } qr/Trigger must be a CODE ref on attribute \(error\)/;
53 can_ok(Class => 'attr');
55 my $object = Class->new;
56 is(@trigger, 0, "trigger not called yet");
58 is($object->attr, 10, "default value");
59 is(@trigger, 0, "trigger not called on read");
61 is($object->attr(50), 50, "setting the value");
62 is(@trigger, 1, "trigger was called on read");
63 is_deeply([splice @trigger], [[$object, 50]], "correct arguments to trigger in the accessor");
65 is($object->foobar, 'piyo');
66 lives_ok { $object->foobar('baz') } "triggers that clear the attr";
68 is($object->foobar, 'piyo', "call clearer in triggers");
70 my $object2 = Class->new(attr => 100);
71 is(@trigger, 1, "trigger was called on new with the attribute specified");
72 is_deeply([splice @trigger], [[$object2, 100]], "correct arguments to trigger in the constructor");