X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FEval%2FWithLexicals.pm;h=fab265c66655b6f419830f6cf6e539a49e2ec3f5;hb=3044b1dac308a6691f4f50d2e5732e2eacbf9527;hp=c7b5fcaf71168a02e29814f713b32f3759a65b1f;hpb=e764ce9b0e0a0dbb3b51ecab734b0a6bf111b6c8;p=p5sagit%2FEval-WithLexicals.git diff --git a/lib/Eval/WithLexicals.pm b/lib/Eval/WithLexicals.pm index c7b5fca..fab265c 100644 --- a/lib/Eval/WithLexicals.pm +++ b/lib/Eval/WithLexicals.pm @@ -3,7 +3,7 @@ package Eval::WithLexicals; use Moo; use Sub::Quote; -our $VERSION = '1.000000'; # 1.0.0 +our $VERSION = '1.001000'; # 1.1.0 $VERSION = eval $VERSION; has lexicals => (is => 'rw', default => quote_sub q{ {} }); @@ -25,6 +25,10 @@ has in_package => ( is => 'rw', default => quote_sub q{ 'Eval::WithLexicals::Scratchpad' } ); +has prelude => ( + is => 'rw', default => quote_sub q{ 'use strictures 1;' } +); + sub eval { my ($self, $to_eval) = @_; local *Eval::WithLexicals::Cage::current_line; @@ -32,7 +36,8 @@ sub eval { local *Eval::WithLexicals::Cage::grab_captures; my $setup = Sub::Quote::capture_unroll('$_[2]', $self->lexicals, 2); my $package = $self->in_package; - local our $current_code = qq!use strictures 1; + my $prelude = $self->prelude; + local our $current_code = qq!${prelude} ${setup} sub Eval::WithLexicals::Cage::current_line { package ${package}; @@ -155,6 +160,7 @@ Eval::WithLexicals - pure perl eval with persistent lexical variables lexicals => { '$x' => \1 }, # default {} in_package => 'PackageToEvalIn', # default Eval::WithLexicals::Scratchpad context => 'scalar', # default 'list' + prelude => 'use warnings', # default 'use strictures 1' ); =head2 eval @@ -179,13 +185,21 @@ Eval::WithLexicals - pure perl eval with persistent lexical variables $eval->context($new_context); # 'list', 'scalar' or 'void' +=head2 prelude + +Code to run before evaling code. Loads L by default. + + my $current_prelude = $eval->prelude; + + $eval->prelude(q{use warnings}); # only warnings, not strict. + =head1 AUTHOR Matt S. Trout =head1 CONTRIBUTORS -None required yet. Maybe this module is perfect (hahahahaha ...). +David Leadbeater =head1 COPYRIGHT