From: Matt S Trout Date: Fri, 5 Dec 2008 03:05:55 +0000 (+0000) Subject: use _eval_closure X-Git-Tag: 0.65~20^2~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5e60e7d6b0f2d65aa4d735f9b8a8e575467a2b06;p=gitmo%2FMoose.git use _eval_closure --- diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index b6852f7..879c018 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -21,19 +21,21 @@ 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 $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 ? $type_constraint_obj->_compiled_type_constraint : undef; +}; #warn "code for $attr_name =>\n" . $code . "\n"; - my $sub = eval $code; - $self->throw_error("Could not create writer for '$attr_name' because $@ \n code: $code", error => $@, data => $code ) if $@; + my $sub = $self->_eval_closure($environment, $code); + $self->throw_error("Could not create writer for '${\$self->associated_attribute->name}' because $@ \n code: $code", error => $@, data => $code ) if $@; return $sub; } diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 644ed93..91da69e 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -150,7 +150,7 @@ sub initialize_body { warn $source if $self->options->{debug}; my $code; - { + my $environment = q{ my $meta = $self; # FIXME for _inline_throw_error... # NOTE: @@ -174,10 +174,9 @@ sub initialize_body { my @type_constraint_bodies = map { defined $_ ? $_->_compiled_type_constraint : undef; } @type_constraints; - - $code = eval $source; - $self->throw_error("Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source ) if $@; - } + }; + $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 $@; $self->{'body'} = $code; } diff --git a/lib/Moose/Meta/Method/Destructor.pm b/lib/Moose/Meta/Method/Destructor.pm index b99cf24..018bb29 100644 --- a/lib/Moose/Meta/Method/Destructor.pm +++ b/lib/Moose/Meta/Method/Destructor.pm @@ -88,11 +88,8 @@ sub initialize_body { $source .= ";\n" . '}'; warn $source if $self->options->{debug}; - my $code; - { - $code = eval $source; - $self->throw_error("Could not eval the destructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source) if $@; - } + my $code = $self->_eval_closure(q{}, $source); + $self->throw_error("Could not eval the destructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source) if $@; $self->{'body'} = $code; }