[Moose-commits] r7744 - Class-MOP/trunk/lib/Class/MOP/Method

autarch at code2.0beta.co.uk autarch at code2.0beta.co.uk
Fri Feb 20 17:20:28 GMT 2009


Author: autarch
Date: 2009-02-20 09:20:28 -0800 (Fri, 20 Feb 2009)
New Revision: 7744

Modified:
   Class-MOP/trunk/lib/Class/MOP/Method/Accessor.pm
   Class-MOP/trunk/lib/Class/MOP/Method/Constructor.pm
   Class-MOP/trunk/lib/Class/MOP/Method/Generated.pm
Log:
I'm a dumbass.

We were checking that code compiled, but I switched to check where the
code is eval'd. This means we see _all_ the code in the error message.

Also, my previous changes broke all the code generation because it
wasn't returning the generated sub.

Modified: Class-MOP/trunk/lib/Class/MOP/Method/Accessor.pm
===================================================================
--- Class-MOP/trunk/lib/Class/MOP/Method/Accessor.pm	2009-02-20 17:11:43 UTC (rev 7743)
+++ Class-MOP/trunk/lib/Class/MOP/Method/Accessor.pm	2009-02-20 17:20:28 UTC (rev 7744)
@@ -67,8 +67,7 @@
         ($self->is_inline ? 'inline' : ())
     );
 
-    eval { $self->{'body'} = $self->$method_name() };
-    die $@ if $@;
+    $self->{'body'} = $self->$method_name();
 }
 
 ## generators
@@ -119,17 +118,14 @@
     my $attr_name     = $attr->name;
     my $meta_instance = $attr->associated_class->instance_metaclass;
 
-    my $code = $self->_eval_closure(
+    return $self->_eval_closure(
         {},
         'sub {'
-        . $meta_instance->inline_set_slot_value('$_[0]', "'$attr_name'", '$_[1]')
+        . $meta_instance->inline_set_slot_value('$_[0]', $attr_name, '$_[1]')
         . ' if scalar(@_) == 2; '
-        . $meta_instance->inline_get_slot_value('$_[0]', "'$attr_name'")
+        . $meta_instance->inline_get_slot_value('$_[0]', $attr_name)
         . '}'
     );
-    confess "Could not generate inline accessor because : $@" if $@;
-
-    return $code;
 }
 
 sub generate_reader_method_inline {
@@ -138,16 +134,13 @@
     my $attr_name     = $attr->name;
     my $meta_instance = $attr->associated_class->instance_metaclass;
 
-    my $code = $self->_eval_closure(
+    return $self->_eval_closure(
          {},
         'sub {'
         . 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;'
         . $meta_instance->inline_get_slot_value('$_[0]', "'$attr_name'")
         . '}'
     );
-    confess "Could not generate inline accessor because : $@" if $@;
-
-    return $code;
 }
 
 sub generate_writer_method_inline {
@@ -156,15 +149,12 @@
     my $attr_name     = $attr->name;
     my $meta_instance = $attr->associated_class->instance_metaclass;
 
-    my $code = $self->_eval_closure(
+    return $self->_eval_closure(
         {},
         'sub {'
         . $meta_instance->inline_set_slot_value('$_[0]', "'$attr_name'", '$_[1]')
         . '}'
     );
-    confess "Could not generate inline accessor because : $@" if $@;
-
-    return $code;
 }
 
 
@@ -174,15 +164,12 @@
     my $attr_name     = $attr->name;
     my $meta_instance = $attr->associated_class->instance_metaclass;
 
-    my $code = $self->_eval_closure(
+    return $self->_eval_closure(
         {},
        'sub {'
        . $meta_instance->inline_is_slot_initialized('$_[0]', "'$attr_name'")
        . '}'
     );
-    confess "Could not generate inline predicate because : $@" if $@;
-
-    return $code;
 }
 
 sub generate_clearer_method_inline {
@@ -191,15 +178,12 @@
     my $attr_name     = $attr->name;
     my $meta_instance = $attr->associated_class->instance_metaclass;
 
-    my $code = $self->_eval_closure(
+    return $self->_eval_closure(
         {},
         'sub {'
         . $meta_instance->inline_deinitialize_slot('$_[0]', "'$attr_name'")
         . '}'
     );
-    confess "Could not generate inline clearer because : $@" if $@;
-
-    return $code;
 }
 
 1;

Modified: Class-MOP/trunk/lib/Class/MOP/Method/Constructor.pm
===================================================================
--- Class-MOP/trunk/lib/Class/MOP/Method/Constructor.pm	2009-02-20 17:11:43 UTC (rev 7743)
+++ Class-MOP/trunk/lib/Class/MOP/Method/Constructor.pm	2009-02-20 17:20:28 UTC (rev 7744)
@@ -107,19 +107,10 @@
     $source .= ";\n" . '}';
     warn $source if $self->options->{debug};
 
-    my $code;
-    {
-        # NOTE:
-        # create the nessecary lexicals
-        # to be picked up in the eval
-
-        $code = $self->_eval_closure(
-            $close_over,
-            $source
-        );
-        confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@;
-    }
-    return $code;
+    return $self->_eval_closure(
+        $close_over,
+        $source
+    );
 }
 
 sub _generate_slot_initializer {

Modified: Class-MOP/trunk/lib/Class/MOP/Method/Generated.pm
===================================================================
--- Class-MOP/trunk/lib/Class/MOP/Method/Generated.pm	2009-02-20 17:11:43 UTC (rev 7743)
+++ Class-MOP/trunk/lib/Class/MOP/Method/Generated.pm	2009-02-20 17:20:28 UTC (rev 7744)
@@ -67,9 +67,11 @@
         ),
         $_[2]
     );
-    eval $code;
+    my $sub = eval $code;
 
     die "$@\n$code" if $@;
+
+    return $sub;
 }
 
 sub _add_line_directive {




More information about the Moose-commits mailing list