X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=blobdiff_plain;f=lib%2FDevel%2FREPL%2FPlugin%2FTurtles.pm;h=4ab7eab72506b4c9cc5271a1b5f126c95183e9f9;hp=ca16591af78e3d331a43fe4a172b20bfb1bdcaff;hb=0cbfa9217cbe7714e72b92abc05ed8b21bc46f00;hpb=49946f5ce52c6859a628226f36c7c99ae7a65069 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;