From: Shawn M Moore Date: Wed, 3 Dec 2008 03:37:52 +0000 (+0000) Subject: Close over $key so we don't need to do an assignment or variable lookup in the constr... X-Git-Tag: 0.19~136^2~73 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dcbf65da69b42871e448d45e23f25ef9e91d364;p=gitmo%2FMouse.git Close over $key so we don't need to do an assignment or variable lookup in the constructor --- diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 2de3802..32baa00 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -44,9 +44,9 @@ sub _generate_processattrs { if ($attr->has_type_constraint) { push @code, "\$attr->verify_type_constraint( \$args->{\$from} );"; } - push @code, "\$instance->{\$key} = \$args->{\$from};"; + push @code, "\$instance->{'$key'} = \$args->{\$from};"; if ($attr->is_weak_ref) { - push @code, "weaken( \$instance->{\$key} ) if ref( \$instance->{\$key} );"; + push @code, "weaken( \$instance->{'$key'} ) if ref( \$instance->{'$key'} );"; } if ( $attr->has_trigger ) { push @code, "\$attr->trigger->( \$instance, \$args->{\$from}, \$attr );"; @@ -72,9 +72,9 @@ sub _generate_processattrs { if ($attr->has_type_constraint) { push @code, "\$attr->verify_type_constraint(\$value);"; } - push @code, "\$instance->{\$key} = \$value;"; + push @code, "\$instance->{'$key'} = \$value;"; if ($attr->is_weak_ref) { - push @code, "weaken( \$instance->{\$key} ) if ref( \$instance->{\$key} );"; + push @code, "weaken( \$instance->{'$key'} ) if ref( \$instance->{'$key'} );"; } } join "\n", @code; @@ -91,7 +91,6 @@ sub _generate_processattrs { { my \$attr = \$attrs[$index]; my \$from = '$from'; - my \$key = '$key'; if (defined(\$from) && exists(\$args->{\$from})) { $part1; } else {