From: Graham Knop Date: Wed, 17 Apr 2013 10:14:06 +0000 (-0400) Subject: fix accessor bugs X-Git-Tag: v1.002000~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b48dcff12471f38b3c88e357ab62899fc5fb07c;p=gitmo%2FMoo.git fix accessor bugs Fixes bugs with isa being called on every access for lazy accessors, and invalid defaults modifying the object. This required converting _generate_use_default to create an expression that could be returned rather than a statement to assign the default. The calling location was then adjusted to return that expression directly. --- diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index ad9f683..7524528 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -232,15 +232,10 @@ sub _generate_get { if ($self->is_simple_get($name, $spec)) { $simple; } else { - 'do { '.$self->_generate_use_default( + $self->_generate_use_default( '$_[0]', $name, $spec, $self->_generate_simple_has('$_[0]', $name, $spec), - ).'; ' - .($spec->{isa} - ?($self->_generate_isa_check($name, $simple, $spec->{isa}).'; ') - :'' - ) - .$simple.' }'; + ); } } @@ -270,9 +265,14 @@ sub _generate_use_default { $spec->{coerce} ) } - $self->_generate_simple_set( - $me, $name, $spec, $get_value - ).' unless '.$test; + $test." ? \n" + .$self->_generate_simple_get($me, $name, $spec)."\n:" + .($spec->{isa} + ? " do {\n my \$value = ".$get_value.";\n" + ." ".$self->_generate_isa_check($name, '$value', $spec->{isa}).";\n" + ." ".$self->_generate_simple_set($me, $name, $spec, '$value')."\n" + ." }\n" + : ' '.$self->_generate_simple_set($me, $name, $spec, $get_value)."\n"); } sub _generate_get_default {