Cache init_arg() in _generate_slot_initializer()
[gitmo/Class-MOP.git] / lib / Class / MOP / Method / Constructor.pm
index c295e42..9a1bf3f 100644 (file)
@@ -7,7 +7,7 @@ use warnings;
 use Carp         'confess';
 use Scalar::Util 'blessed', 'weaken', 'looks_like_number';
 
-our $VERSION   = '0.82_02';
+our $VERSION   = '0.89';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -136,11 +136,11 @@ sub _generate_constructor_method_inline {
     $source .= ";\n" . '}';
     warn $source if $self->options->{debug};
 
-    my $code = $self->_eval_closure(
+    my ( $code, $e ) = $self->_eval_closure(
         $close_over,
         $source
     );
-    confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@;
+    confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e" if $e;
 
     return $code;
 }
@@ -174,13 +174,13 @@ sub _generate_slot_initializer {
         $default = '$instance->'.$attr->builder;
     }
 
-    if ( defined $attr->init_arg ) {
+    if ( defined(my $init_arg = $attr->init_arg) ) {
       return (
-          'if(exists $params->{\'' . $attr->init_arg . '\'}){' . "\n" .
+          'if(exists $params->{\'' . $init_arg . '\'}){' . "\n" .
                 $self->_meta_instance->inline_set_slot_value(
                     '$instance',
                     $attr->name,
-                    '$params->{\'' . $attr->init_arg . '\'}' ) . "\n" .
+                    '$params->{\'' . $init_arg . '\'}' ) . "\n" .
            '} ' . (!defined $default ? '' : 'else {' . "\n" .
                 $self->_meta_instance->inline_set_slot_value(
                     '$instance',