Commit | Line | Data |
e958cbc6 |
1 | package Devel::REPL::Plugin::Turtles; |
2 | use Moose::Role; |
48ddfeae |
3 | use namespace::clean -except => [ 'meta' ]; |
e958cbc6 |
4 | |
5 | around 'eval' => sub { |
0cbfa921 |
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); |
e958cbc6 |
11 | } |
0cbfa921 |
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"); |
e958cbc6 |
19 | } |
0cbfa921 |
20 | } |
21 | else { |
22 | return $next->($self, $line); |
23 | } |
e958cbc6 |
24 | }; |
25 | |
48ddfeae |
26 | 1; |