From: Matt S Trout Date: Sat, 21 Jul 2012 14:33:29 +0000 (+0000) Subject: localize @_ when inlining quote_sub'ed isa checks (fixes lazy+isa+default) X-Git-Tag: v1.000001~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=159d9c5b735d060e33a267a00b391901b478502d;hp=9f8d2cdb30f01c298ccc06606740587a0394735e;p=gitmo%2FMoo.git localize @_ when inlining quote_sub'ed isa checks (fixes lazy+isa+default) --- diff --git a/Changes b/Changes index ec47b24..f990edc 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - localize @_ when inlining quote_sub'ed isa checks (fixes lazy+isa+default) - ensure constructor gets regenerated if forced early by metaclass inflation 1.000000 - 2012-07-18 diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 21b8924..7089056 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -332,15 +332,14 @@ sub _generate_call_code { my ($self, $name, $type, $values, $sub) = @_; if (my $quoted = quoted_from_sub($sub)) { my $code = $quoted->[1]; - my $at_ = '@_ = ('.$values.');'; if (my $captures = $quoted->[2]) { my $cap_name = qq{\$${type}_captures_for_${name}}; $self->{captures}->{$cap_name} = \$captures; Sub::Quote::inlinify( - $code, $values, Sub::Quote::capture_unroll($cap_name, $captures, 6) + $code, $values, Sub::Quote::capture_unroll($cap_name, $captures, 6), 1 ); } else { - Sub::Quote::inlinify($code, $values); + Sub::Quote::inlinify($code, $values, undef, 1); } } else { my $cap_name = qq{\$${type}_for_${name}}; diff --git a/t/accessor-isa.t b/t/accessor-isa.t index 69d66c1..2ce945a 100644 --- a/t/accessor-isa.t +++ b/t/accessor-isa.t @@ -85,23 +85,32 @@ run_for 'Bar'; run_for 'Baz'; +my $lt3; + { package LazyFoo; + use Sub::Quote; use Moo; has less_than_three => ( is => 'lazy', - isa => sub { die "$_[0] is not less than three" unless $_[0] < 3 } + isa => quote_sub(q{ die "$_[0] is not less than three" unless $_[0] < 3 }) ); - sub _build_less_than_three { 4 } + sub _build_less_than_three { $lt3 } } +$lt3 = 4; + like( exception { LazyFoo->new->less_than_three }, qr/isa check for "less_than_three" failed: 4 is not less than three/, "exception thrown on bad builder return value (LazyFoo)" ); +$lt3 = 2; + +is(LazyFoo->new->less_than_three, 2, 'Correct builder value returned ok'); + done_testing;