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=9781cc2be0fab2c5c7849a0eb3c73f9972e089d9;hp=c412237ce7c0b3776350b7fcc057bf4f945f42da;hb=e2d0b0198529e2e06593df8ebab7a8413bc932e1;hpb=cfd1094b45c394258ccda08216f1435bf40e1d50 diff --git a/lib/Devel/REPL/Plugin/Turtles.pm b/lib/Devel/REPL/Plugin/Turtles.pm index c412237..9781cc2 100644 --- a/lib/Devel/REPL/Plugin/Turtles.pm +++ b/lib/Devel/REPL/Plugin/Turtles.pm @@ -3,26 +3,30 @@ use Devel::REPL::Plugin; use Scalar::Util qw(reftype); -use MooseX::AttributeHelpers; - -use namespace::clean -except => [ 'meta' ]; +use namespace::sweep; +use MooX::Types::MooseLike::Base qw(RegexpRef ArrayRef CodeRef AnyOf); has default_command_prefix => ( - isa => "RegexpRef", + isa => RegexpRef, is => "rw", + lazy => 1, default => sub { qr/\#/ }, ); has turtles_matchers => ( - metaclass => "Collection::Array", - isa => "ArrayRef[RegexpRef|CodeRef]", + isa => ArrayRef[AnyOf[RegexpRef,CodeRef]], is => "rw", - default => sub { my $prefix = shift->default_command_prefix; [qr/^ $prefix (\w+) \s* (.*) /x] }, - provides => { - unshift => "add_turtles_matcher", + lazy => 1, + default => sub { + my $prefix = shift->default_command_prefix; [qr/^ $prefix (\w+) \s* (.*) /x] }, ); +sub add_turtles_matcher { + my $self = shift; + unshift @{$self->turtles_matchers}, @_; +} + around 'formatted_eval' => sub { my $next = shift; my ($self, $line, @args) = @_; @@ -74,5 +78,19 @@ __END__ Devel::REPL::Plugin::Turtles - Generic command creation using a read hook +=head1 DESCRIPTION + +By default, this plugin allows calling commands using a read hook +to detect a default_command_prefix followed by the command name, +say MYCMD as an example. The actual routine to call for the +command is constructed by looking for subs named 'command_MYCMD' +or 'expr_MYCMD' and executing them. + +=head2 NOTE + +The C is C so care must be taken +if other uses for that character are needed (e.g., '#' for the +shell escape character in the PDL shell. + =cut