From: Graham Knop Date: Wed, 17 Apr 2013 11:16:15 +0000 (-0400) Subject: avoid using separate variable for value in modifier when possible X-Git-Tag: v1.002000~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a2711acc6bc0e71f3fdc08174c1185bec0b54bec;p=gitmo%2FMoo.git avoid using separate variable for value in modifier when possible --- diff --git a/Changes b/Changes index 493cc83..a2f8e03 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - avoid localising @_ when not required for Sub::Quote - successfully inflate a metaclass for attributeless classes (RT#86415) - fix false default values used with non-lazy accessors - stop built values that fail isa checks still getting stored in the object diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 02443df..9bb8d51 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -302,22 +302,27 @@ sub _generate_set { $self->_generate_simple_set('$_[0]', $name, $spec, '$_[1]'); } else { my ($coerce, $trigger, $isa_check) = @{$spec}{qw(coerce trigger isa)}; - my $simple = $self->_generate_simple_set('$self', $name, $spec, '$value'); - my $code = "do { my (\$self, \$value) = \@_;\n"; + my $value_store = '$_[0]'; + my $code; if ($coerce) { - $code .= - " \$value = " - .$self->_generate_coerce($name, '$value', $coerce).";\n"; + $value_store = '$value'; + $code = "do { my (\$self, \$value) = \@_;\n" + ." \$value = " + .$self->_generate_coerce($name, $value_store, $coerce).";\n"; + } + else { + $code = "do { my \$self = shift;\n"; } if ($isa_check) { $code .= - " ".$self->_generate_isa_check($name, '$value', $isa_check).";\n"; + " ".$self->_generate_isa_check($name, $value_store, $isa_check).";\n"; } + my $simple = $self->_generate_simple_set('$self', $name, $spec, $value_store); if ($trigger) { - my $fire = $self->_generate_trigger($name, '$self', '$value', $trigger); + my $fire = $self->_generate_trigger($name, '$self', $value_store, $trigger); $code .= " ".$simple.";\n ".$fire.";\n" - ." \$value;\n"; + ." $value_store;\n"; } else { $code .= " ".$simple.";\n"; }