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=3c986cb0d4839985933e2e2a43a27dc881e1d445;hb=796cd7ec80de14e45ca8221d545aceb7b9bc0b71;hpb=c3bbf326d9e6a1ae2c1d5fd05ff973f5f9d26106
diff --git a/lib/Devel/REPL.pm b/lib/Devel/REPL.pm
index 3c986cb..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.002001'; # 1.2.1
-
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
@@ -157,30 +167,177 @@ Alternatively, use the 're.pl' script installed with the distribution
system$ re.pl
-=head1 AUTHOR
+=head1 DESCRIPTION
-Matt S Trout - mst (at) shadowcatsystems.co.uk (L)
+This is an interactive shell for Perl, commonly known as a REPL - Read,
+Evaluate, Print, Loop. The shell provides for rapid development or testing
+of code without the need to create a temporary source code file.
-=head1 CONTRIBUTORS
+Through a plugin system, many features are available on demand. You can also
+tailor the environment through the use of profiles and run control files, for
+example to pre-load certain Perl modules when working on a particular project.
-=over 4
+=head1 USAGE
-=item Stevan Little - stevan (at) iinteractive.com
+To start a shell, follow one of the examples in the L"SYNOPSIS"> above.
-=item Alexis Sukrieh - sukria+perl (at) sukria.net
+Once running, the shell accepts and will attempt to execute any code given. If
+the code executes successfully you'll be shown the result, otherwise an error
+message will be returned. Here are a few examples:
-=item epitaph
+ $_ print "Hello, world!\n"
+ Hello, world!
+ 1
+ $_ nosuchfunction
+ Compile error: Bareword "nosuchfunction" not allowed while "strict subs" in use at (eval 130) line 5.
-=item mgrimes - mgrimes (at) cpan dot org
+ $_
-=item Shawn M Moore - sartak (at) gmail.com
+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
+that example, an error is returned when the execution of some code fails.
-=back
+Note that the lack of semicolon on the end is not a mistake - the code is
+run inside a Block structure (to protect the REPL in case the code blows up),
+which means a single statement doesn't require the semicolon. You can add one
+if you like, though.
-=head1 LICENSE
+If you followed the first example in the L"SYNOPSIS"> above, you'll have the
+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
+C keyword will automatically persist between statements executed in the
+REPL shell.
-This library is free software under the same terms as perl itself
+When you C