X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FMethod%2FGenerated.pm;h=21351f598c5ef5a51839371de45b03d345c4db9f;hb=ec52b37ad0cba41a9770c8971ee16f54bbfdfc89;hp=6760382a8b89c0d81a0ac78b93f36f336f102cf2;hpb=b92a52994ffe9a3b871a5a5526ccd6b9c9d86187;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Method/Generated.pm b/lib/Class/MOP/Method/Generated.pm index 6760382..21351f5 100644 --- a/lib/Class/MOP/Method/Generated.pm +++ b/lib/Class/MOP/Method/Generated.pm @@ -6,12 +6,14 @@ use warnings; use Carp 'confess'; -our $VERSION = '0.80_01'; +our $VERSION = '0.97'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Method'; +use constant _PRINT_SOURCE => $ENV{MOP_PRINT_SOURCE} ? 1 : 0; + ## accessors sub new { @@ -22,29 +24,38 @@ sub is_inline { $_[0]{is_inline} } sub definition_context { $_[0]{definition_context} } -sub initialize_body { +sub _initialize_body { confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class"; } sub _eval_closure { # my ($self, $captures, $sub_body) = @_; my $__captures = $_[1]; - eval join( - "\n", - ( + + my $code; + + my $e = do { + local $@; + local $SIG{__DIE__}; + my $source = join + "\n", ( map { /^([\@\%\$])/ or die "capture key should start with \@, \% or \$: $_"; - q[my ] - . $_ . q[ = ] - . $1 - . q[{$__captures->{'] - . $_ - . q['}};]; - } keys %$__captures - ), - $_[2] - ); + q[my ] + . $_ . q[ = ] + . $1 + . q[{$__captures->{'] + . $_ . q['}};]; + } keys %$__captures + ), + $_[2]; + print STDERR "\n", $_[0]->name, ":\n", $source, "\n" if _PRINT_SOURCE; + $code = eval $source; + $@; + }; + + return ( $code, $e ); } sub _add_line_directive { @@ -77,7 +88,7 @@ sub _compile_code { my $code = $self->_add_line_directive(%args); - $self->_eval_closure($args{environment}, $code); + return $self->_eval_closure($args{environment}, $code); } 1;