X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FEval-WithLexicals.git;a=blobdiff_plain;f=bin%2Ftinyrepl;h=f9087ea034fabec235070a4d1311f7bd621e6bd6;hp=352ad9715eca77d79a0fa85ab4fa27d8ae0aae33;hb=8d732f3064bb88d682504f365ef1af62c6598b8c;hpb=6f914695d80ef46fe45ac39758eb956f0f5389a6 diff --git a/bin/tinyrepl b/bin/tinyrepl old mode 100644 new mode 100755 index 352ad97..f9087ea --- a/bin/tinyrepl +++ b/bin/tinyrepl @@ -1,19 +1,33 @@ +#!/usr/bin/env perl + use strictures 1; use Eval::WithLexicals; use Term::ReadLine; -use Data::Dumper::Concise; -use Try::Tiny; +use Data::Dumper; +use Getopt::Long; + +GetOptions( + "plugin=s" => \my @plugins +); + +$SIG{INT} = sub { warn "SIGINT\n" }; + +{ package Data::Dumper; no strict 'vars'; + $Terse = $Indent = $Useqq = $Deparse = $Sortkeys = 1; + $Quotekeys = 0; +} + +my $eval = @plugins + ? Eval::WithLexicals->with_plugins(@plugins)->new + : Eval::WithLexicals->new; -my $eval = Eval::WithLexicals->new; my $read = Term::ReadLine->new('Perl REPL'); while (1) { my $line = $read->readline('re.pl$ '); exit unless defined $line; - my @ret; try { + my @ret; eval { local $SIG{INT} = sub { die "Caught SIGINT" }; - @ret = $eval->eval($line); - } catch { - @ret = ("Error!", $_); - }; + @ret = $eval->eval($line); 1; + } or @ret = ("Error!", $@); print Dumper @ret; }