X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FEval%2FWithLexicals.pm;h=cb6f33dfc3e1e27ed6fbce469adc8046138f5c44;hb=dg;hp=95194a83449e86f1d044636f6be218fe3ac0077d;hpb=d9087132689f27e3409cf79308b90a67ee7a9ab2;p=p5sagit%2FEval-WithLexicals.git diff --git a/lib/Eval/WithLexicals.pm b/lib/Eval/WithLexicals.pm index 95194a8..cb6f33d 100644 --- a/lib/Eval/WithLexicals.pm +++ b/lib/Eval/WithLexicals.pm @@ -54,6 +54,7 @@ sub eval { my $package = $self->in_package; my $setup_code = join '', $self->setup_code, + # $_[2] being what is passed to _eval_do below Sub::Quote::capture_unroll('$_[2]', $self->lexicals, 2); my $capture_code = join '', $self->capture_code; @@ -92,7 +93,7 @@ sub _run { %{$self->lexicals}, %{$self->_grab_captures}, }); - @ret; + return $self->context eq 'list' ? @ret : $ret[0]; } sub _grab_captures { @@ -150,6 +151,11 @@ Eval::WithLexicals - pure perl eval with persistent lexical variables use Eval::WithLexicals; use Term::ReadLine; use Data::Dumper; + use Getopt::Long; + + GetOptions( + "plugin=s" => \my @plugins + ); $SIG{INT} = sub { warn "SIGINT\n" }; @@ -158,7 +164,10 @@ Eval::WithLexicals - pure perl eval with persistent lexical variables $Quotekeys = 0; } - my $eval = Eval::WithLexicals->new; + my $eval = @plugins + ? Eval::WithLexicals->with_plugins(@plugins)->new + : Eval::WithLexicals->new; + my $read = Term::ReadLine->new('Perl REPL'); while (1) { my $line = $read->readline('re.pl$ '); @@ -223,6 +232,25 @@ Code to run before evaling code. Loads L by default. $eval->prelude(q{use warnings}); # only warnings, not strict. +=head2 with_plugins + + my $eval = Eval::WithLexicals->with_plugins("HintPersistence")->new; + +Construct a class with the given plugins. Plugins are roles located under +a package name like C. + +Current plugins are: + +=over 4 + +=item * HintPersistence + +When enabled this will persist pragams and other compile hints between evals +(for example the L and L flags in effect). See +L for further details. + +=back + =head1 AUTHOR Matt S. Trout