[Bast-commits] r4324 - trunk/Devel-REPL/lib/Devel
nothingmuch at dev.catalyst.perl.org
nothingmuch at dev.catalyst.perl.org
Mon May 5 19:28:32 BST 2008
Author: nothingmuch
Date: 2008-05-05 19:28:32 +0100 (Mon, 05 May 2008)
New Revision: 4324
Modified:
trunk/Devel-REPL/lib/Devel/REPL.pm
Log:
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)
Modified: trunk/Devel-REPL/lib/Devel/REPL.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL.pm 2008-05-05 18:22:11 UTC (rev 4323)
+++ trunk/Devel-REPL/lib/Devel/REPL.pm 2008-05-05 18:28:32 UTC (rev 4324)
@@ -71,7 +71,7 @@
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 @@
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 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;
}
More information about the Bast-commits
mailing list