get hints from strictures as late as possible
[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 use Getopt::Long;
8
9 GetOptions(
10   "plugin=s" => \my @plugins
11 );
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 }
19
20 my $eval = @plugins
21  ? Eval::WithLexicals->with_plugins(@plugins)->new
22  : Eval::WithLexicals->new;
23
24 my $read = Term::ReadLine->new('Perl REPL');
25 while (1) {
26   my $line = $read->readline('re.pl$ ');
27   exit unless defined $line;
28   my @ret; eval {
29     local $SIG{INT} = sub { die "Caught SIGINT" };
30     @ret = $eval->eval($line); 1;
31   } or @ret = ("Error!", $@);
32   print Dumper @ret;
33 }
34
35 __END__
36
37 =head1 NAME
38
39 tinyrepl - 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
52 tinyrepl is a minimal pure-Perl REPL.  It is just a small wrapper
53 around L<Eval::WithLexicals>.
54
55 =head1 OPTIONS
56
57 =over 4
58
59 =item C<--plugin=>
60
61 Loads a plugin into the REPL. See L<Eval::WithLexicals/with_plugins>.
62
63 =back
64
65 =head1 SUPPORT
66
67 See L<Eval::WithLexicals> for support and contact information.
68
69 =head1 AUTHORS
70
71 See L<Eval::WithLexicals> for authors.
72
73 =head1 COPYRIGHT AND LICENSE
74
75 See L<Eval::WithLexicals> for the copyright and license.
76
77 =cut