X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FEval-WithLexicals.git;a=blobdiff_plain;f=bin%2Ftinyrepl;h=6d52ba6e9c8ee53090b322fd5d7834e113608105;hp=352ad9715eca77d79a0fa85ab4fa27d8ae0aae33;hb=52ec47288bfbf9d8f6d9798d13b023af3fe7cdc0;hpb=2c8bc7a3af2bee608b9b567851cea2f6a1dcb988 diff --git a/bin/tinyrepl b/bin/tinyrepl index 352ad97..6d52ba6 100755 --- a/bin/tinyrepl +++ b/bin/tinyrepl @@ -1,19 +1,77 @@ +#!/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; } + +__END__ + +=head1 NAME + +tinyrepl - Tiny REPL + +=head1 SYNOPSIS + + $ tinyrepl + re.pl$ "s" x 5 + "sssss" + re.pl$ exit + + $ tinyrepl --plugin HintPersistence + +=head1 DESCRIPTION + +tinyrepl is a minimal pure-Perl REPL. It is just a small wrapper +around L. + +=head1 OPTIONS + +=over 4 + +=item C<--plugin=> + +Loads a plugin into the REPL. See L. + +=back + +=head1 SUPPORT + +See L for support and contact information. + +=head1 AUTHORS + +See L for authors. + +=head1 COPYRIGHT AND LICENSE + +See L for the copyright and license. + +=cut