4b786182eb49bd3fbc470fae4e13583e22ec684a
[p5sagit/Eval-WithLexicals.git] / bin / tinyrepl
1 #!/usr/bin/env perl
2
3 use strictures 1;
4 use Eval::WithLexicals;
5 use Term::ReadLine;
6 use Data::Dumper;
7
8 use Getopt::Long;
9
10 GetOptions(
11   "plugin=s" => \my @plugins
12 );
13
14 $SIG{INT} = sub { warn "SIGINT\n" };
15
16 { package Data::Dumper; no strict 'vars';
17   $Terse = $Indent = $Useqq = $Deparse = $Sortkeys = 1;
18   $Quotekeys = 0;
19 }
20
21 my $eval = @plugins
22  ? Eval::WithLexicals->with_plugins(@plugins)->new
23  : Eval::WithLexicals->new;
24
25 my $read = Term::ReadLine->new('Perl REPL');
26 while (1) {
27   my $line = $read->readline('re.pl$ ');
28   exit unless defined $line;
29   my @ret; eval {
30     local $SIG{INT} = sub { die "Caught SIGINT" };
31     @ret = $eval->eval($line); 1;
32   } or @ret = ("Error!", $@);
33   print Dumper @ret;
34 }