Merge 'trunk' into 'method_generation_cleanup'
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor.pm
index 9fab4d7..3d40db8 100644 (file)
@@ -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;
 
 }
@@ -228,7 +230,7 @@ sub _inline_trigger {
     my ($self, $instance, $value) = @_;
     my $attr = $self->associated_attribute;
     return '' unless $attr->has_trigger;
-    return sprintf('$attr->trigger->(%s, %s, $attr);', $instance, $value);
+    return sprintf('$attr->trigger->(%s, %s);', $instance, $value);
 }
 
 sub _inline_get {