[Moose-commits] r7324 - Moose/trunk/lib/Moose/Meta/Method

nothingmuch at code2.0beta.co.uk nothingmuch at code2.0beta.co.uk
Sun Jan 18 00:24:39 GMT 2009


Author: nothingmuch
Date: 2009-01-17 16:24:38 -0800 (Sat, 17 Jan 2009)
New Revision: 7324

Modified:
   Moose/trunk/lib/Moose/Meta/Method/Accessor.pm
   Moose/trunk/lib/Moose/Meta/Method/Constructor.pm
   Moose/trunk/lib/Moose/Meta/Method/Destructor.pm
Log:
Merge commit 'svn/method_generation_cleanup'

Modified: Moose/trunk/lib/Moose/Meta/Method/Accessor.pm
===================================================================
--- Moose/trunk/lib/Moose/Meta/Method/Accessor.pm	2009-01-17 22:59:55 UTC (rev 7323)
+++ Moose/trunk/lib/Moose/Meta/Method/Accessor.pm	2009-01-18 00:24:38 UTC (rev 7324)
@@ -21,19 +21,22 @@
 
     # NOTE:
     # set up the environment
-    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";
-    eval $self->_prepare_code( code => $code )
-        or $self->throw_error("Could not create writer for '$attr_name' because $@ \n code: $code", error => $@, data => $code );
+    $self->_compile_code( environment => $environment, code => $code )
+        or $self->throw_error("Could not create writer for '${\$self->associated_attribute->name}' because $@ \n code: $code", error => $@, data => $code );
 }
 
 sub generate_accessor_method_inline {
@@ -226,7 +229,7 @@
     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 {

Modified: Moose/trunk/lib/Moose/Meta/Method/Constructor.pm
===================================================================
--- Moose/trunk/lib/Moose/Meta/Method/Constructor.pm	2009-01-17 22:59:55 UTC (rev 7323)
+++ Moose/trunk/lib/Moose/Meta/Method/Constructor.pm	2009-01-18 00:24:38 UTC (rev 7324)
@@ -142,42 +142,42 @@
         $self->_generate_slot_initializer($_)
     } 0 .. (@{$self->attributes} - 1));
 
-    $source .= ";\n" . $self->_generate_triggers();    
+    $source .= ";\n" . $self->_generate_triggers();
     $source .= ";\n" . $self->_generate_BUILDALL();
 
     $source .= ";\n" . 'return $instance';
     $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;
 }
 

Modified: Moose/trunk/lib/Moose/Meta/Method/Destructor.pm
===================================================================
--- Moose/trunk/lib/Moose/Meta/Method/Destructor.pm	2009-01-17 22:59:55 UTC (rev 7323)
+++ Moose/trunk/lib/Moose/Meta/Method/Destructor.pm	2009-01-18 00:24:38 UTC (rev 7324)
@@ -88,11 +88,11 @@
     $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->_compile_code(
+        environment => {},
+        code => $source,
+    ) or $self->throw_error("Could not eval the destructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source);
+
     $self->{'body'} = $code;
 }
 




More information about the Moose-commits mailing list