X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=bin%2Ftinyrepl;h=4b786182eb49bd3fbc470fae4e13583e22ec684a;hb=3fb66cc7c134ee8da56ac1378d87eb653c7b7619;hp=352ad9715eca77d79a0fa85ab4fa27d8ae0aae33;hpb=6f914695d80ef46fe45ac39758eb956f0f5389a6;p=p5sagit%2FEval-WithLexicals.git diff --git a/bin/tinyrepl b/bin/tinyrepl old mode 100644 new mode 100755 index 352ad97..4b78618 --- a/bin/tinyrepl +++ b/bin/tinyrepl @@ -1,19 +1,34 @@ +#!/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; }