From: Matt S Trout Date: Fri, 12 Dec 2008 08:54:33 +0000 (+0000) Subject: only close over the default values, don't actually need the meta-attributes X-Git-Tag: 0.76~10^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=82cff1ae05f95c0c723a959bf6e9c26086adb1b1;p=gitmo%2FClass-MOP.git only close over the default values, don't actually need the meta-attributes --- diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index e19839a..4099c27 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -101,7 +101,7 @@ sub generate_constructor_method_inline { $source .= "\n" . 'my $instance = ' . $self->meta_instance->inline_create_instance('$class'); $source .= ";\n" . (join ";\n" => map { - $self->_generate_slot_initializer($_) + $self->_generate_slot_initializer($_, $close_over) } 0 .. (@{$self->attributes} - 1)); $source .= ";\n" . 'return $instance'; $source .= ";\n" . '}'; @@ -114,7 +114,7 @@ sub generate_constructor_method_inline { # to be picked up in the eval $code = $self->_eval_closure( - { '$attrs' => \$self->attributes }, + $close_over, $source ); confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@; @@ -125,6 +125,7 @@ sub generate_constructor_method_inline { sub _generate_slot_initializer { my $self = shift; my $index = shift; + my $close = shift; my $attr = $self->attributes->[$index]; @@ -137,7 +138,9 @@ sub _generate_slot_initializer { # in which case we can just deal with them # in the code we eval. if ($attr->is_default_a_coderef) { - $default = '$attrs->[' . $index . ']->default($instance)'; + my $idx = @{$close->{'@defaults'}||=[]}; + push(@{$close->{'@defaults'}}, $attr->default); + $default = '$defaults[' . $idx . ']->($instance)'; } else { $default = $attr->default;