[Bast-commits] r4318 - in trunk/Devel-REPL/lib/Devel/REPL/Plugin: .
MultiLine
nothingmuch at dev.catalyst.perl.org
nothingmuch at dev.catalyst.perl.org
Mon May 5 10:41:20 BST 2008
Author: nothingmuch
Date: 2008-05-05 10:41:20 +0100 (Mon, 05 May 2008)
New Revision: 4318
Modified:
trunk/Devel-REPL/lib/Devel/REPL/Plugin/MultiLine/PPI.pm
trunk/Devel-REPL/lib/Devel/REPL/Plugin/Turtles.pm
Log:
even turtles hate PPI
Modified: trunk/Devel-REPL/lib/Devel/REPL/Plugin/MultiLine/PPI.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL/Plugin/MultiLine/PPI.pm 2008-05-05 08:37:19 UTC (rev 4317)
+++ trunk/Devel-REPL/lib/Devel/REPL/Plugin/MultiLine/PPI.pm 2008-05-05 09:41:20 UTC (rev 4318)
@@ -20,24 +20,33 @@
my $line = $self->$orig(@args);
if (defined $line) {
- while ($self->line_needs_continuation($line)) {
- my $orig_prompt = $self->prompt;
- $self->prompt($self->continuation_prompt);
+ return $self->continue_reading_if_necessary($line, @args);
+ } else {
+ return $line;
+ }
+};
- $self->line_depth($self->line_depth + 1);
- my $append = $self->read(@args);
- $self->line_depth($self->line_depth - 1);
+sub continue_reading_if_necessary {
+ my ( $self, $line, @args ) = @_;
- $line .= $append if defined($append);
+ while ($self->line_needs_continuation($line)) {
+ my $orig_prompt = $self->prompt;
+ $self->prompt($self->continuation_prompt);
- $self->prompt($orig_prompt);
+ $self->line_depth($self->line_depth + 1);
+ my $append = $self->read(@args);
+ $self->line_depth($self->line_depth - 1);
- # ^D means "shut up and eval already"
- return $line if !defined($append);
- }
+ $line .= $append if defined($append);
+
+ $self->prompt($orig_prompt);
+
+ # ^D means "shut up and eval already"
+ return $line if !defined($append);
}
+
return $line;
-};
+}
sub line_needs_continuation
{
Modified: trunk/Devel-REPL/lib/Devel/REPL/Plugin/Turtles.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL/Plugin/Turtles.pm 2008-05-05 08:37:19 UTC (rev 4317)
+++ trunk/Devel-REPL/lib/Devel/REPL/Plugin/Turtles.pm 2008-05-05 09:41:20 UTC (rev 4318)
@@ -3,15 +3,24 @@
use namespace::clean -except => [ 'meta' ];
around 'eval' => sub {
- my $next = shift;
- my ($self, $line) = @_;
- if ($line =~ /^#(.*)/) {
- return $next->($self, ('$_REPL->' . $1 . '; return();'));
+ my $next = shift;
+ my ($self, $line) = @_;
+ if ( my ( $command, $rest ) = ( $line =~ /^#(\w+)\s*(.*)/ ) ) {
+ if ( my $cont = $self->can("continue_reading_if_necessary") ) {
+ $rest = $self->$cont($rest);
}
- else {
- return $next->($self, $line);
+
+ my $method = "command_$command";
+
+ if ( $self->can($method) ) {
+ return $self->$method($rest);
+ } else {
+ return $self->error_return("REPL error", "Command '$command' does not exist");
}
-
+ }
+ else {
+ return $next->($self, $line);
+ }
};
1;
More information about the Bast-commits
mailing list