X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=blobdiff_plain;f=lib%2FDevel%2FREPL.pm;h=03557de3fbc9494b28cac3b0fa38000cc6d33bbc;hp=772031711551f323d017ba07cb8a2bc77f376fc6;hb=796cd7ec80de14e45ca8221d545aceb7b9bc0b71;hpb=79697f6184b05e3778e6090166d5bd9fcbd243b9 diff --git a/lib/Devel/REPL.pm b/lib/Devel/REPL.pm index 7720317..03557de 100644 --- a/lib/Devel/REPL.pm +++ b/lib/Devel/REPL.pm @@ -1,35 +1,44 @@ package Devel::REPL; +# ABSTRACT: A modern perl interactive shell + +our $VERSION = '1.003027'; use Term::ReadLine; use Moose; -use namespace::clean -except => [ 'meta' ]; +use namespace::autoclean; use 5.008001; # backwards compat, doesn't warn like 5.8.1 -our $VERSION = '1.003006'; # 1.3.6 - with 'MooseX::Object::Pluggable'; use Devel::REPL::Error; has 'term' => ( - is => 'rw', required => 1, + is => 'rw', + lazy => 1, default => sub { Term::ReadLine->new('Perl REPL') } ); has 'prompt' => ( - is => 'rw', required => 1, + is => 'rw', default => sub { '$ ' } ); has 'out_fh' => ( - is => 'rw', required => 1, lazy => 1, + is => 'rw', + lazy => 1, default => sub { shift->term->OUT || \*STDOUT; } ); +has 'exit_repl' => ( + is => 'rw', + default => sub { 0 } +); + sub run { my ($self) = @_; while ($self->run_once_safely) { - # keep looping + # keep looping unless we want to exit REPL + last if $self->exit_repl; } } @@ -51,11 +60,11 @@ sub run_once { my ($self) = @_; my $line = $self->read; - return unless defined($line); # undefined value == EOF + return unless defined($line); # undefined value == EOF my @ret = $self->formatted_eval($line); - $self->print(@ret); + $self->print(@ret) unless $self->exit_repl; return 1; } @@ -143,9 +152,10 @@ sub print { print $fh "\n" if $self->term->ReadLine =~ /Gnu/; } -=head1 NAME +1; +__END__ -Devel::REPL - a modern perl interactive shell +=pod =head1 SYNOPSIS @@ -180,8 +190,8 @@ message will be returned. Here are a few examples: 1 $_ nosuchfunction Compile error: Bareword "nosuchfunction" not allowed while "strict subs" in use at (eval 130) line 5. - - $_ + + $_ In the first example above you see the output of the command (C), if any, and then the return value of the statement (C<1>). Following @@ -193,7 +203,8 @@ which means a single statement doesn't require the semicolon. You can add one if you like, though. If you followed the first example in the L above, you'll have the -History and LexEnv plugins loaded (and there are many more available). +L and L +plugins loaded (and there are many more available). Although the shell might support "up-arrow" history, the History plugin adds "bang" history to that so you can re-execute chosen commands (with e.g. C). The LexEnv plugin ensures that lexical variables declared with the @@ -208,16 +219,20 @@ exported functions from that module are available for immediate use: (Do you need to predeclare carp?) Compile error: syntax error at (eval 129) line 5, near "carp "I'm dieeeing!\n"" BEGIN not safe after errors--compilation aborted at (eval 129) line 5. - - $_ use Carp - + + $_ use Carp + $_ carp "I'm dieeeing!\n" I'm dieeeing! at /usr/share/perl5/Lexical/Persistence.pm line 327 1 - $_ + $_ + +To quit from the shell, hit C or C. + + MSWin32 NOTE: control keys won't work if TERM=dumb + because readline functionality will be disabled. -To quit from the shell, hit C or C. =head2 Run Control Files @@ -235,7 +250,7 @@ filename like so: system$ re.pl --rcfile myproject.pc -If the filename happens to contain a forwardslash, then it's used absolutely, +If the filename happens to contain a forward slash, then it's used absolutely, or realive to the current working directory: system$ re.pl --rcfile /path/to/my/project/repl.rc @@ -249,39 +264,28 @@ To allow for the sharing of run control files, you can fashion them into a Perl module for distribution (perhaps via the CPAN). For more information on this feature, please see the L manual page. -A default profile ships with C; it loads the following plugins: - -=over 4 - -=item * - -L - -=item * - -L - -=item * - -L - -=item * - -L - -=item * - -L - -=item * - -L - -=back +A C profile ships with C; it loads the following plugins +(note that some of these require optional features -- or you can also use the +C profile): + +=for :list +* L +* L +* L +* L +* L +* L +* L +* L +* L +* L +* L +* L +* L =head2 Plugins -Plugins are a way to add funcionality to the REPL shell, and take advantage of +Plugins are a way to add functionality to the REPL shell, and take advantage of C being based on the L object system for Perl 5. This means it's simple to 'hook into' many steps of the R-E-P-L process. Plugins can change the way commands are interpreted, or the way their results are @@ -289,7 +293,9 @@ output, or even add commands to the shell environment. A number of plugins ship with C, and more are available on the CPAN. Some of the shipped plugins are loaded in the default profile, mentioned -above. +above. These plugins can be loaded in your F< $HOME/.re.pl/repl.rc > like: + + load_plugin qw( CompletionDriver::Global DumpHistory ); Writing your own plugins is not difficult, and is discussed in the L manual page, along with links to the manual pages of @@ -313,105 +319,25 @@ control files have already been executed: 1 $_ -=head1 REQUIREMENTS - -In addition to the contents of the standard Perl distribution, you will need -the following: - -=over 4 - -=item * - -L >= 0.64 - -=item * - -L >= 0.0009 - -=item * - -L >= 0.15 - -=item * - -L >= 0.14 +=head1 OPTIONAL FEATURES -=item * +In addition to the prerequisites declared in this distribution, which should be automatically installed by your L client, there are a number of optional features, used by +additional plugins. You can install any of these features by installing this +distribution interactively (e.g. C). -L +=for comment I hope to automatically generate this data via a Pod::Weaver section -=item * - -L - -=item * - -L - -=back - -Optionally, some plugins if installed will require the following modules: - -=over 4 - -=item * - -L - -=item * - -L - -=item * - -L - -=item * - -L - -=item * - -L - -=item * - -L - -=item * - -L - -=back - -=head1 AUTHOR - -Matt S Trout - mst (at) shadowcatsystems.co.uk (L) - -=head1 CONTRIBUTORS - -=over 4 - -=item Stevan Little - stevan (at) iinteractive.com - -=item Alexis Sukrieh - sukria+perl (at) sukria.net - -=item epitaph - -=item mgrimes - mgrimes (at) cpan dot org - -=item Shawn M Moore - sartak (at) gmail.com - -=item Oliver Gorwits - oliver on irc.perl.org - -=item Andrew Moore - C<< >> - -=back - -=head1 LICENSE - -This library is free software under the same terms as perl itself +=for :list +* Completion plugin - extensible tab completion +* DDS plugin - better format results with Data::Dump::Streamer +* DDC plugin - even better format results with Data::Dumper::Concise +* INC completion driver - tab complete module names in use and require +* Interrupt plugin - traps SIGINT to kill long-running lines +* Keywords completion driver - tab complete Perl keywords and operators +* LexEnv plugin - variables declared with "my" persist between statements +* MultiLine::PPI plugin - continue reading lines until all blocks are closed +* Nopaste plugin - upload a session\'s input and output to a Pastebin +* PPI plugin - PPI dumping of Perl code +* Refresh plugin - automatically reload libraries with Module::Refresh =cut - -1;