4ab7eab72506b4c9cc5271a1b5f126c95183e9f9
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Turtles.pm
1 package Devel::REPL::Plugin::Turtles;
2 use Moose::Role;
3 use namespace::clean -except => [ 'meta' ];
4
5 around 'eval' => sub {
6   my $next = shift;
7   my ($self, $line) = @_;
8   if ( my ( $command, $rest ) = ( $line =~ /^#(\w+)\s*(.*)/ ) ) {
9     if ( my $cont = $self->can("continue_reading_if_necessary") ) {
10       $rest = $self->$cont($rest);
11     }
12
13     my $method = "command_$command";
14
15     if ( $self->can($method) ) {
16       return $self->$method($rest);
17     } else {
18       return $self->error_return("REPL error", "Command '$command' does not exist");
19     }
20   }
21   else {
22     return $next->($self, $line);
23   }
24 };
25
26 1;