move across to _eval_closure hashref style
Matt S Trout [Fri, 12 Dec 2008 08:36:13 +0000 (08:36 +0000)]
lib/Moose/Meta/Method/Accessor.pm
lib/Moose/Meta/Method/Constructor.pm

index 3d40db8..2b399e6 100644 (file)
@@ -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);
index e420b5a..d622ac5 100644 (file)
@@ -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 $@;