From: Dave Rolsky Date: Fri, 20 Feb 2009 17:20:28 +0000 (+0000) Subject: I'm a dumbass. X-Git-Tag: 0.77_01~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ffe92c8b7d896623737c480b5c8bef3c727336ca;p=gitmo%2FClass-MOP.git 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. --- diff --git a/lib/Class/MOP/Method/Accessor.pm b/lib/Class/MOP/Method/Accessor.pm index be4b5b6..e27d318 100644 --- a/lib/Class/MOP/Method/Accessor.pm +++ b/lib/Class/MOP/Method/Accessor.pm @@ -67,8 +67,7 @@ sub initialize_body { ($self->is_inline ? 'inline' : ()) ); - eval { $self->{'body'} = $self->$method_name() }; - die $@ if $@; + $self->{'body'} = $self->$method_name(); } ## generators @@ -119,17 +118,14 @@ sub generate_accessor_method_inline { 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 @@ sub generate_reader_method_inline { 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 @@ sub generate_writer_method_inline { 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 @@ sub generate_predicate_method_inline { 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 @@ sub generate_clearer_method_inline { 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; diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index a3e955e..64fa1eb 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -107,19 +107,10 @@ sub generate_constructor_method_inline { $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 { diff --git a/lib/Class/MOP/Method/Generated.pm b/lib/Class/MOP/Method/Generated.pm index 9392cb9..784757e 100644 --- a/lib/Class/MOP/Method/Generated.pm +++ b/lib/Class/MOP/Method/Generated.pm @@ -67,9 +67,11 @@ sub _eval_closure { ), $_[2] ); - eval $code; + my $sub = eval $code; die "$@\n$code" if $@; + + return $sub; } sub _add_line_directive {