X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDevel%2FREPL%2FPlugin%2FCompletionDriver%2FKeywords.pm;fp=lib%2FDevel%2FREPL%2FPlugin%2FCompletionDriver%2FKeywords.pm;h=08e9f2b3cd4796f9e66983719e77bba9b28e0dda;hb=1989c3d297823e55034a9cd22d79089fefcb93c3;hp=0000000000000000000000000000000000000000;hpb=cb3b891f24d8cf8b0b669bcb9cbb1135df12dace;p=p5sagit%2FDevel-REPL.git diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm b/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm new file mode 100644 index 0000000..08e9f2b --- /dev/null +++ b/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm @@ -0,0 +1,26 @@ +package Devel::REPL::Plugin::CompletionDriver::Keywords; +use Devel::REPL::Plugin; +use B::Keywords qw/@Functions @Barewords/; +use namespace::clean -except => [ 'meta' ]; + +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; + } + + return $orig->(@_) + unless $last->isa('PPI::Token::Word'); + + my $re = qr/^\Q$last/; + + return $orig->(@_), + grep { $_ =~ $re } @Functions, @Barewords; +}; + +1; +