From: Dave Rolsky Date: Mon, 21 May 2012 02:54:13 +0000 (-0500) Subject: Make inline vars arrays instead of arrayrefs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Ftopic%2Finline-constructor-tweak;p=gitmo%2FMoose.git Make inline vars arrays instead of arrayrefs --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 65fb500..120fa99 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -626,7 +626,7 @@ sub _inline_init_attr_from_constructor { ); push @initial_value, ( - '$attrs->[' . $idx . ']->set_initial_value(', + '$attrs[' . $idx . ']->set_initial_value(', '$instance,', $attr->_inline_instance_get('$instance'), ');', @@ -645,7 +645,7 @@ sub _inline_init_attr_from_default { my @initial_value = $attr->_inline_set_value('$instance', $default); push @initial_value, ( - '$attrs->[' . $idx . ']->set_initial_value(', + '$attrs[' . $idx . ']->set_initial_value(', '$instance,', $attr->_inline_instance_get('$instance'), ');', @@ -666,10 +666,10 @@ sub _inline_default_value { # in which case we can just deal with them # in the code we eval. if ($attr->is_default_a_coderef) { - return '$defaults->[' . $index . ']->($instance)'; + return '$defaults[' . $index . ']->($instance)'; } else { - return '$defaults->[' . $index . ']'; + return '$defaults[' . $index . ']'; } } elsif ($attr->has_builder) { @@ -701,10 +701,10 @@ sub _eval_environment { my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes; - my $defaults = [map { $_->default } @attrs]; + my @defaults = map { $_->default } @attrs; return { - '$defaults' => \$defaults, + '@defaults' => \@defaults, }; } diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 5649794..bb48b25 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -397,7 +397,7 @@ sub _inline_init_attr_from_constructor { ); push @initial_value, ( - '$attrs->[' . $idx . ']->set_initial_value(', + '$attrs[' . $idx . ']->set_initial_value(', '$instance,', $attr->_inline_instance_get('$instance'), ');', @@ -427,7 +427,7 @@ sub _inline_init_attr_from_default { ); push @initial_value, ( - '$attrs->[' . $idx . ']->set_initial_value(', + '$attrs[' . $idx . ']->set_initial_value(', '$instance,', $attr->_inline_instance_get('$instance'), ');', @@ -459,7 +459,7 @@ sub _inline_triggers { push @trigger_calls, 'if (exists $params->{\'' . $init_arg . '\'}) {', - '$triggers->[' . $i . ']->(', + '$triggers[' . $i . ']->(', '$instance,', $attr->_inline_instance_get('$instance') . ',', ');', @@ -488,10 +488,10 @@ sub _eval_environment { my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes; - my $triggers = [ + my @triggers = ( map { $_->can('has_trigger') && $_->has_trigger ? $_->trigger : undef } @attrs - ]; + ); # We need to check if the attribute ->can('type_constraint') # since we may be trying to immutabilize a Moose meta class, @@ -525,9 +525,9 @@ sub _eval_environment { return { %{ $self->SUPER::_eval_environment }, ((any { defined && $_->has_initializer } @attrs) - ? ('$attrs' => \[@attrs]) + ? ('@attrs' => \@attrs) : ()), - '$triggers' => \$triggers, + '@triggers' => \@triggers, '@type_coercions' => \@type_coercions, '@type_constraint_bodies' => \@type_constraint_bodies, '@type_constraint_messages' => \@type_constraint_messages,