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=a46fbbe04c4540d674cecd3fbedec5756f1de90c;hp=c52f0bf0405c617237f20828957609a7ff4ea70b;hb=97d28d6b74a5aa91b2af19a28c438caa193bfac0;hpb=48ddfeae8a9840b39113a97c4889bfe210509cdd diff --git a/lib/Devel/REPL.pm b/lib/Devel/REPL.pm index c52f0bf..a46fbbe 100644 --- a/lib/Devel/REPL.pm +++ b/lib/Devel/REPL.pm @@ -3,6 +3,9 @@ package Devel::REPL; use Term::ReadLine; use Moose; use namespace::clean -except => [ 'meta' ]; +use 5.008001; # backwards compat, doesn't warn like 5.8.1 + +our $VERSION = '1.002001'; # 1.2.1 with 'MooseX::Object::Pluggable'; @@ -33,7 +36,13 @@ sub run_once { my $line = $self->read; return unless defined($line); # undefined value == EOF my @ret = $self->eval($line); - $self->print(@ret); + eval { + $self->print(@ret); + }; + if ($@) { + my $error = $@; + eval { $self->print("Error printing! - $error\n"); }; + } return 1; } @@ -51,9 +60,9 @@ sub eval { } sub compile { - my $REPL = shift; - my $compiled = eval $REPL->wrap_as_sub($_[0]); - return (undef, $REPL->error_return("Compile error", $@)) if $@; + my $_REPL = shift; + my $compiled = eval $_REPL->wrap_as_sub($_[0]); + return (undef, $_REPL->error_return("Compile error", $@)) if $@; return $compiled; } @@ -82,7 +91,49 @@ sub error_return { sub print { my ($self, @ret) = @_; my $fh = $self->out_fh; + no warnings 'uninitialized'; print $fh "@ret"; + print $fh "\n" if $self->term->ReadLine =~ /Gnu/; } +=head1 NAME + +Devel::REPL - a modern perl interactive shell + +=head1 SYNOPSIS + + my $repl = Devel::REPL->new; + $repl->load_plugin($_) for qw(History LexEnv); + $repl->run + +Alternatively, use the 're.pl' script installed with the distribution + + system$ re.pl + +=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 + +=back + +=head1 LICENSE + +This library is free software under the same terms as perl itself + +=cut + 1;