From: nothingmuch Date: Mon, 5 May 2008 09:41:20 +0000 (+0000) Subject: even turtles hate PPI X-Git-Tag: v1.003015~132 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0cbfa9217cbe7714e72b92abc05ed8b21bc46f00;p=p5sagit%2FDevel-REPL.git even turtles hate PPI git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@4318 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- diff --git a/lib/Devel/REPL/Plugin/MultiLine/PPI.pm b/lib/Devel/REPL/Plugin/MultiLine/PPI.pm index a812b27..b7957f0 100644 --- a/lib/Devel/REPL/Plugin/MultiLine/PPI.pm +++ b/lib/Devel/REPL/Plugin/MultiLine/PPI.pm @@ -20,24 +20,33 @@ around 'read' => sub { 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; + } +}; + +sub continue_reading_if_necessary { + my ( $self, $line, @args ) = @_; + + while ($self->line_needs_continuation($line)) { + my $orig_prompt = $self->prompt; + $self->prompt($self->continuation_prompt); - $self->line_depth($self->line_depth + 1); - my $append = $self->read(@args); - $self->line_depth($self->line_depth - 1); + $self->line_depth($self->line_depth + 1); + my $append = $self->read(@args); + $self->line_depth($self->line_depth - 1); - $line .= $append if defined($append); + $line .= $append if defined($append); - $self->prompt($orig_prompt); + $self->prompt($orig_prompt); - # ^D means "shut up and eval already" - return $line if !defined($append); - } + # ^D means "shut up and eval already" + return $line if !defined($append); } + return $line; -}; +} sub line_needs_continuation { diff --git a/lib/Devel/REPL/Plugin/Turtles.pm b/lib/Devel/REPL/Plugin/Turtles.pm index ca16591..4ab7eab 100644 --- a/lib/Devel/REPL/Plugin/Turtles.pm +++ b/lib/Devel/REPL/Plugin/Turtles.pm @@ -3,15 +3,24 @@ use Moose::Role; 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;