From: Matt S Trout Date: Fri, 12 Dec 2008 08:36:13 +0000 (+0000) Subject: move across to _eval_closure hashref style X-Git-Tag: 0.65~20^2~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1aeb15481cdb866ee2e451a320619ffe591f2d19;p=gitmo%2FMoose.git move across to _eval_closure hashref style --- diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 3d40db8..2b399e6 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -21,17 +21,18 @@ sub _eval_code { # NOTE: # set up the environment - my $environment = q{ - my $attr = $self->associated_attribute; - my $attr_name = $attr->name; - my $meta = $self; - - my $type_constraint_obj = $attr->type_constraint; - my $type_constraint_name = $type_constraint_obj && $type_constraint_obj->name; - my $type_constraint = $type_constraint_obj + my $attr = $self->associated_attribute; + my $type_constraint_obj = $attr->type_constraint; + my $environment = { + '$attr' => \$attr, + '$attr_name' => \$attr->name, + '$meta' => \$self, + '$type_constraint_obj' => \$type_constraint_obj, + '$type_constraint_name' => \($type_constraint_obj && $type_constraint_obj->name), + '$type_constraint' => \($type_constraint_obj ? $type_constraint_obj->_compiled_type_constraint - : undef; -}; + : undef), + }; #warn "code for $attr_name =>\n" . $code . "\n"; my $sub = $self->_eval_closure($environment, $code); diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index e420b5a..d622ac5 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -150,13 +150,16 @@ sub initialize_body { warn $source if $self->options->{debug}; my $code; - my $environment = q{ - my $meta = $self; # FIXME for _inline_throw_error... + my $attrs = $self->attributes; + my @type_constraints = map { + $_->can('type_constraint') ? $_->type_constraint : undef + } @$attrs; + my $environment = { - # NOTE: - # create the nessecary lexicals - # to be picked up in the eval - my $attrs = $self->attributes; + # lexicals for the scope within which we will be constructed + + '$meta' => \$self, # FIXME for _inline_throw_error... + '$attrs' => \$attrs, # We need to check if the attribute ->can('type_constraint') # since we may be trying to immutabilize a Moose meta class, @@ -167,13 +170,11 @@ sub initialize_body { # because the inlined code is using the index of the attributes # to determine where to find the type constraint - my @type_constraints = map { - $_->can('type_constraint') ? $_->type_constraint : undef - } @$attrs; + '@type_constraints' => \@type_constraints, - my @type_constraint_bodies = map { + '@type_constraint_bodies' => [ map { defined $_ ? $_->_compiled_type_constraint : undef; - } @type_constraints; + } @type_constraints ] }; $code = $self->_eval_closure($environment, $source); $self->throw_error("Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source ) if $@;