X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=blobdiff_plain;f=lib%2FDevel%2FREPL%2FPlugin%2FCompletionDriver%2FKeywords.pm;h=decc6c8a2e4513efc1310062d7e66807e3f0a89f;hp=08e9f2b3cd4796f9e66983719e77bba9b28e0dda;hb=6631e15ccd2313ff350fd9bfa44c1ccdbac77100;hpb=1989c3d297823e55034a9cd22d79089fefcb93c3 diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm b/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm index 08e9f2b..decc6c8 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm @@ -3,19 +3,25 @@ use Devel::REPL::Plugin; use B::Keywords qw/@Functions @Barewords/; use namespace::clean -except => [ 'meta' ]; +with qw( + Devel::REPL::Plugin::Completion +); + around complete => sub { my $orig = shift; my ($self, $text, $document) = @_; - # recursively find the last element - my $last = $document; - while ($last->can('last_element') && defined($last->last_element)) { - $last = $last->last_element; - } + my $last = $self->last_ppi_element($document); return $orig->(@_) unless $last->isa('PPI::Token::Word'); + # don't complete keywords on foo->method + return $orig->(@_) + if $last->sprevious_sibling + && $last->sprevious_sibling->isa('PPI::Token::Operator') + && $last->sprevious_sibling->content eq '->'; + my $re = qr/^\Q$last/; return $orig->(@_), @@ -24,3 +30,15 @@ around complete => sub { 1; +__END__ + +=head1 NAME + +Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators + +=head1 AUTHOR + +Shawn M Moore, C<< >> + +=cut +