context sensitivity
[p5sagit/Eval-WithLexicals.git] / lib / Eval / WithLexicals.pm
index 95194a8..cb6f33d 100644 (file)
@@ -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<strictures> 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<Eval::WithLexicals::With*>.
+
+Current plugins are:
+
+=over 4
+
+=item * HintPersistence
+
+When enabled this will persist pragams and other compile hints between evals
+(for example the L<strict> and L<warnings> flags in effect). See
+L<Eval::WithLexicals::WithHintPersistence> for further details.
+
+=back
+
 =head1 AUTHOR
 
 Matt S. Trout <mst@shadowcat.co.uk>