[Moose-commits] r7319 - Moose/branches/method_generation_cleanup/lib/Moose/Meta/Method

nothingmuch at code2.0beta.co.uk nothingmuch at code2.0beta.co.uk
Sat Jan 17 22:02:53 GMT 2009


Author: nothingmuch
Date: 2009-01-17 14:02:53 -0800 (Sat, 17 Jan 2009)
New Revision: 7319

Modified:
   Moose/branches/method_generation_cleanup/lib/Moose/Meta/Method/Constructor.pm
Log:
use _compile_code in Constructor

Modified: Moose/branches/method_generation_cleanup/lib/Moose/Meta/Method/Constructor.pm
===================================================================
--- Moose/branches/method_generation_cleanup/lib/Moose/Meta/Method/Constructor.pm	2009-01-17 22:02:37 UTC (rev 7318)
+++ Moose/branches/method_generation_cleanup/lib/Moose/Meta/Method/Constructor.pm	2009-01-17 22:02:53 UTC (rev 7319)
@@ -149,35 +149,35 @@
     $source .= ";\n" . '}';
     warn $source if $self->options->{debug};
 
-    my $code;
-    {
-        my $meta = $self; # FIXME for _inline_throw_error...
+    # We need to check if the attribute ->can('type_constraint')
+    # since we may be trying to immutabilize a Moose meta class,
+    # which in turn has attributes which are Class::MOP::Attribute
+    # objects, rather than Moose::Meta::Attribute. And
+    # Class::MOP::Attribute attributes have no type constraints.
+    # However we need to make sure we leave an undef value there
+    # because the inlined code is using the index of the attributes
+    # to determine where to find the type constraint
 
-        # NOTE:
-        # create the nessecary lexicals
-        # to be picked up in the eval
-        my $attrs = $self->attributes;
+    my $attrs = $self->attributes;
 
-        # We need to check if the attribute ->can('type_constraint')
-        # since we may be trying to immutabilize a Moose meta class,
-        # which in turn has attributes which are Class::MOP::Attribute
-        # objects, rather than Moose::Meta::Attribute. And 
-        # Class::MOP::Attribute attributes have no type constraints.
-        # However we need to make sure we leave an undef value there
-        # 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;
-        
-        my @type_constraint_bodies = map {
-            defined $_ ? $_->_compiled_type_constraint : undef;
-        } @type_constraints;
+    my @type_constraints = map {
+        $_->can('type_constraint') ? $_->type_constraint : undef
+    } @$attrs;
 
-        $code = eval $source;
-        $self->throw_error("Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source ) if $@;
-    }
+    my @type_constraint_bodies = map {
+        defined $_ ? $_->_compiled_type_constraint : undef;
+    } @type_constraints;
+
+    my $code = $self->_compile_code(
+        code => $source,
+        environment => {
+            '$meta'  => \$self,
+            '$attrs' => \$attrs,
+            '@type_constraints' => \@type_constraints,
+            '@type_constraint_bodies' => \@type_constraint_bodies,
+        },
+    ) or $self->throw_error("Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source );
+
     $self->{'body'} = $code;
 }
 




More information about the Moose-commits mailing list