From: gfx Date: Mon, 8 Mar 2010 07:25:37 +0000 (+0900) Subject: Fix triggers X-Git-Tag: 0.50_08~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=25431bc447d70124c2734d9a69ebe70f23f5b624;p=gitmo%2FMouse.git Fix triggers --- diff --git a/lib/Mouse/Meta/Method/Accessor.pm b/lib/Mouse/Meta/Method/Accessor.pm index 474ae95..350e3e2 100755 --- a/lib/Mouse/Meta/Method/Accessor.pm +++ b/lib/Mouse/Meta/Method/Accessor.pm @@ -90,6 +90,7 @@ sub _generate_accessor_any{ $value = '$default'; } + $accessor .= "els" if $type eq 'rw' || $type eq 'wo'; $accessor .= "if(!exists $slot){\n"; if($should_coerce){ $accessor .= "$slot = \$constraint->coerce($value)"; diff --git a/t/001_mouse/016-trigger.t b/t/001_mouse/016-trigger.t index edac65e..62ebe20 100644 --- a/t/001_mouse/016-trigger.t +++ b/t/001_mouse/016-trigger.t @@ -14,8 +14,8 @@ do { is => 'rw', default => 10, trigger => sub { - my ($self, $value, $attr) = @_; - push @trigger, [$self, $value, $attr]; + my ($self, $value) = @_; + push @trigger, [$self, $value]; }, ); @@ -60,14 +60,15 @@ is(@trigger, 0, "trigger not called on read"); is($object->attr(50), 50, "setting the value"); is(@trigger, 1, "trigger was called on read"); -is_deeply([splice @trigger], [[$object, 50, undef]], "correct arguments to trigger in the accessor"); +is_deeply([splice @trigger], [[$object, 50]], "correct arguments to trigger in the accessor"); is($object->foobar, 'piyo'); -is($object->foobar('baz'), 'baz'); +lives_ok { $object->foobar('baz') } "triggers that clear the attr"; + is($object->foobar, 'piyo', "call clearer in triggers"); my $object2 = Class->new(attr => 100); is(@trigger, 1, "trigger was called on new with the attribute specified"); -is_deeply([splice @trigger], [[$object2, 100, undef]], "correct arguments to trigger in the constructor"); +is_deeply([splice @trigger], [[$object2, 100]], "correct arguments to trigger in the constructor"); done_testing; diff --git a/tool/create-moose-compatibility-tests.pl b/tool/create-moose-compatibility-tests.pl index 6289344..05f33ce 100644 --- a/tool/create-moose-compatibility-tests.pl +++ b/tool/create-moose-compatibility-tests.pl @@ -12,7 +12,6 @@ File::Path::rmtree(File::Spec->catfile('xt', 'compatibility')); # some test does not pass... currently skip it. my %SKIP_TEST = ( - '016-trigger.t' => "trigger's argument is incompatble :(", '810-isa-or.t' => "Mouse has a bug", '052-undefined-type-in-union.t' => "Mouse accepts undefined type as a member of union types",