X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FClass-MOP.git;a=blobdiff_plain;f=lib%2FClass%2FMOP%2FMethod%2FAccessor.pm;fp=lib%2FClass%2FMOP%2FMethod%2FAccessor.pm;h=b4377e9d21b32a22e3e82cef99d8bddad4883c37;hp=5ba0f3db3dd807713c256b113e910dd4a1bd4c05;hb=15961c86cfd845e6f46b6c362cc1a4b94ffb45db;hpb=5f90deee7aaaa91b691b9bee49ed681daa311b69 diff --git a/lib/Class/MOP/Method/Accessor.pm b/lib/Class/MOP/Method/Accessor.pm index 5ba0f3d..b4377e9 100644 --- a/lib/Class/MOP/Method/Accessor.pm +++ b/lib/Class/MOP/Method/Accessor.pm @@ -6,6 +6,7 @@ use warnings; use Carp 'confess'; use Scalar::Util 'blessed', 'weaken'; +use Try::Tiny; our $VERSION = '1.11'; $VERSION = eval $VERSION; @@ -133,14 +134,20 @@ sub _generate_accessor_method_inline { my $self = shift; my $attr = $self->associated_attribute; - my ( $code, $e ) = $self->_eval_closure( - {}, - 'sub {' - . $attr->inline_set( '$_[0]', '$_[1]' ) - . ' if scalar(@_) == 2; ' - . $attr->inline_get('$_[0]') . '}' - ); - confess "Could not generate inline accessor because : $e" if $e; + my $code = try { + $self->_compile_code( + source => [ + 'sub {', + $attr->inline_set( '$_[0]', '$_[1]' ) + . ' if scalar(@_) == 2;', + $attr->inline_get('$_[0]') . ';', + '}', + ] + ); + } + catch { + confess "Could not generate inline accessor because : $_"; + }; return $code; } @@ -149,13 +156,20 @@ sub _generate_reader_method_inline { my $self = shift; my $attr = $self->associated_attribute; - my ( $code, $e ) = $self->_eval_closure( - {}, - 'sub {' - . 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;' - . $attr->inline_get('$_[0]') . '}' - ); - confess "Could not generate inline reader because : $e" if $e; + my $code = try { + $self->_compile_code( + source => [ + 'sub {', + 'confess "Cannot assign a value to a read-only accessor" ' + . 'if @_ > 1;', + $attr->inline_get('$_[0]') . ';', + '}', + ], + ); + } + catch { + confess "Could not generate inline reader because : $_"; + }; return $code; } @@ -164,11 +178,18 @@ sub _generate_writer_method_inline { my $self = shift; my $attr = $self->associated_attribute; - my ( $code, $e ) = $self->_eval_closure( - {}, - 'sub {' . $attr->inline_set( '$_[0]', '$_[1]' ) . '}' - ); - confess "Could not generate inline writer because : $e" if $e; + my $code = try { + $self->_compile_code( + source => [ + 'sub {', + $attr->inline_set( '$_[0]', '$_[1]' ) . ';', + '}', + ], + ); + } + catch { + confess "Could not generate inline writer because : $_"; + }; return $code; } @@ -177,11 +198,18 @@ sub _generate_predicate_method_inline { my $self = shift; my $attr = $self->associated_attribute; - my ( $code, $e ) = $self->_eval_closure( - {}, - 'sub {' . $attr->inline_has('$_[0]') . '}' - ); - confess "Could not generate inline predicate because : $e" if $e; + my $code = try { + $self->_compile_code( + source => [ + 'sub {', + $attr->inline_has('$_[0]') . ';', + '}', + ], + ); + } + catch { + confess "Could not generate inline predicate because : $_"; + }; return $code; } @@ -190,11 +218,18 @@ sub _generate_clearer_method_inline { my $self = shift; my $attr = $self->associated_attribute; - my ( $code, $e ) = $self->_eval_closure( - {}, - 'sub {' . $attr->inline_clear('$_[0]') . '}' - ); - confess "Could not generate inline clearer because : $e" if $e; + my $code = try { + $self->_compile_code( + source => [ + 'sub {', + $attr->inline_clear('$_[0]') . ';', + '}', + ], + ); + } + catch { + confess "Could not generate inline clearer because : $_"; + }; return $code; }