distarify
[p5sagit/Eval-WithLexicals.git] / bin / tinyrepl
CommitLineData
51e1f1e1 1#!/usr/bin/env perl
2
6f914695 3use strictures 1;
4use Eval::WithLexicals;
5use Term::ReadLine;
51e1f1e1 6use Data::Dumper;
8d732f30 7use Getopt::Long;
8
9GetOptions(
10 "plugin=s" => \my @plugins
11);
51e1f1e1 12
13$SIG{INT} = sub { warn "SIGINT\n" };
14
15{ package Data::Dumper; no strict 'vars';
16 $Terse = $Indent = $Useqq = $Deparse = $Sortkeys = 1;
17 $Quotekeys = 0;
18}
6f914695 19
8d732f30 20my $eval = @plugins
21 ? Eval::WithLexicals->with_plugins(@plugins)->new
22 : Eval::WithLexicals->new;
23
6f914695 24my $read = Term::ReadLine->new('Perl REPL');
25while (1) {
26 my $line = $read->readline('re.pl$ ');
27 exit unless defined $line;
51e1f1e1 28 my @ret; eval {
6f914695 29 local $SIG{INT} = sub { die "Caught SIGINT" };
51e1f1e1 30 @ret = $eval->eval($line); 1;
31 } or @ret = ("Error!", $@);
6f914695 32 print Dumper @ret;
33}
ed9faa55 34
35__END__
36
37=head1 NAME
38
39tinyrepl - Tiny REPL
40
41=head1 SYNOPSIS
42
43 $ tinyrepl
44 re.pl$ "s" x 5
45 "sssss"
46 re.pl$ exit
47
48 $ tinyrepl --plugin HintPersistence
49
50=head1 DESCRIPTION
51
52tinyrepl is a minimal pure-Perl REPL. It is just a small wrapper
53around L<Eval::WithLexicals>.
54
55=head1 OPTIONS
56
57=over 4
58
59=item C<--plugin=>
60
61Loads a plugin into the REPL. See L<Eval::WithLexicals/with_plugins>.
62
63=back
64
65=head1 AUTHOR
66
67Matt S. Trout <mst@shadowcat.co.uk>
68
69=head1 CONTRIBUTORS
70
71David Leadbeater <dgl@dgl.cx>
72
73=head1 COPYRIGHT
74
75Copyright (c) 2012 the Eval::WithLexicals L</AUTHOR> and L</CONTRIBUTORS>
76as listed above.
77
78=head1 LICENSE
79
80This library is free software and may be distributed under the same terms
81as perl itself.
82
83=cut