From: nothingmuch Date: Mon, 5 May 2008 18:28:32 +0000 (+0000) Subject: make compile return a single value, use is_error to test if it's bad (it's now an... X-Git-Tag: v1.003015~127 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c3bbf326d9e6a1ae2c1d5fd05ff973f5f9d26106;p=p5sagit%2FDevel-REPL.git make compile return a single value, use is_error to test if it's bad (it's now an error object instead of undef + error str) git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@4324 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- diff --git a/lib/Devel/REPL.pm b/lib/Devel/REPL.pm index 406cb42..3c986cb 100644 --- a/lib/Devel/REPL.pm +++ b/lib/Devel/REPL.pm @@ -71,7 +71,7 @@ sub formatted_eval { sub format { my ( $self, @stuff ) = @_; - if ( blessed($stuff[0]) and $stuff[0]->isa("Devel::REPL::Error") ) { + if ( $self->is_error($stuff[0]) ) { return $self->format_error(@stuff); } else { return $self->format_result(@stuff); @@ -89,6 +89,11 @@ sub format_error { return $error->stringify; } +sub is_error { + my ( $self, $thingy ) = @_; + blessed($thingy) and $thingy->isa("Devel::REPL::Error"); +} + sub read { my ($self) = @_; return $self->term->readline($self->prompt); @@ -96,16 +101,15 @@ sub read { sub eval { my ($self, $line) = @_; - my ($to_exec, @rest) = $self->compile($line); - return @rest unless defined($to_exec); - my @ret = $self->execute($to_exec); - return @ret; + my $compiled = $self->compile($line); + return $compiled unless defined($compiled) and not $self->is_error($compiled); + return $self->execute($compiled); } sub compile { my ( $_REPL, @args ) = @_; my $compiled = eval $_REPL->wrap_as_sub(@args); - return (undef, $_REPL->error_return("Compile error", $@)) if $@; + return $_REPL->error_return("Compile error", $@) if $@; return $compiled; }