even turtles hate PPI
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Turtles.pm
index ca16591..4ab7eab 100644 (file)
@@ -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;