[Bast-commits] r3186 - trunk/Devel-REPL/lib/Devel
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Tue Apr 10 04:22:53 GMT 2007
Author: matthewt
Date: 2007-04-10 04:22:46 +0100 (Tue, 10 Apr 2007)
New Revision: 3186
Modified:
trunk/Devel-REPL/lib/Devel/REPL.pm
Log:
switch Devel::REPL to sub {} generation and split functionality for maximum ease of overriding
Modified: trunk/Devel-REPL/lib/Devel/REPL.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL.pm 2007-04-09 20:41:34 UTC (rev 3185)
+++ trunk/Devel-REPL/lib/Devel/REPL.pm 2007-04-10 03:22:46 UTC (rev 3186)
@@ -32,7 +32,7 @@
my ($self) = @_;
my $line = $self->read;
return unless defined($line); # undefined value == EOF
- my @ret = $self->execute($line);
+ my @ret = $self->eval($line);
$self->print(@ret);
return 1;
}
@@ -42,13 +42,43 @@
return $self->term->readline($self->prompt);
}
+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;
+}
+
+sub compile {
+ my ($self, $line) = @_;
+ my $compiled = eval $self->wrap_as_sub($line);
+ return (undef, $self->error_return("Compile error", $@)) if $@;
+ return $compiled;
+}
+
+sub wrap_as_sub {
+ my ($self, $line) = @_;
+ return qq!sub {\n!.$self->mangle_line($line).qq!\n}\n!;
+}
+
+sub mangle_line {
+ my ($self, $line) = @_;
+ return $line;
+}
+
sub execute {
- my ($self, $to_exec) = @_;
- my @ret = eval $to_exec;
- @ret = ("ERROR: $@") if $@;
+ my ($self, $to_exec, @args) = @_;
+ my @ret = eval { $to_exec->(@args) };
+ return $self->error_return("Runtime error", $@) if $@;
return @ret;
}
+sub error_return {
+ my ($self, $type, $error) = @_;
+ return "${type}: ${error}";
+}
+
sub print {
my ($self, @ret) = @_;
my $fh = $self->out_fh;
More information about the Bast-commits
mailing list