4 use Test::More tests => 16;
17 my ($self, $value, $attr) = @_;
18 push @trigger, [$self, $value, $attr];
27 } "it's no longer an error to have trigger on a readonly attribute";
34 } qr/Trigger must be a CODE or HASH ref on attribute \(error\)/;
37 can_ok(Class => 'attr');
39 my $object = Class->new;
40 is(@trigger, 0, "trigger not called yet");
42 is($object->attr, 10, "default value");
43 is(@trigger, 0, "trigger not called on read");
45 is($object->attr(50), 50, "setting the value");
46 is(@trigger, 1, "trigger was called on read");
47 is_deeply([splice @trigger], [[$object, 50, $object->meta->get_attribute('attr')]], "correct arguments to trigger in the accessor");
49 my $object2 = Class->new(attr => 100);
50 is(@trigger, 1, "trigger was called on new with the attribute specified");
51 is_deeply([splice @trigger], [[$object2, 100, $object2->meta->get_attribute('attr')]], "correct arguments to trigger in the constructor");
61 push @trigger, ['before', @_];
64 push @trigger, ['after', @_];
68 my ($self, $value, $attr) = @_;
70 push @trigger, ['around-before', $self, $value, $attr];
71 $code->($self, 4 * $value, $attr);
72 push @trigger, ['around-after', $self, $value, $attr];
86 my $child = Child->new;
87 is(@trigger, 0, "trigger not called on constructor with default");
89 is($child->attr, 10, "reader");
90 is(@trigger, 0, "trigger not called on reader");
92 is($child->attr(5), 20, "writer");
93 is_deeply([splice @trigger], [
94 ['before', $child, 5, Child->meta->get_attribute('attr')],
95 ['around-before', $child, 5, Child->meta->get_attribute('attr')],
96 ['around-after', $child, 5, Child->meta->get_attribute('attr')],
97 ['after', $child, 20, Child->meta->get_attribute('attr')],