r80567@dhcp117: nothingmuch | 2008-05-14 19:51:22 +0900
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / Keywords.pm
1 package Devel::REPL::Plugin::CompletionDriver::Keywords;
2 use Devel::REPL::Plugin;
3 use B::Keywords qw/@Functions @Barewords/;
4 use namespace::clean -except => [ 'meta' ];
5
6 around complete => sub {
7   my $orig = shift;
8   my ($self, $text, $document) = @_;
9
10   # recursively find the last element
11   my $last = $document;
12   while ($last->can('last_element') && defined($last->last_element)) {
13       $last = $last->last_element;
14   }
15
16   return $orig->(@_)
17     unless $last->isa('PPI::Token::Word');
18
19   my $re = qr/^\Q$last/;
20
21   return $orig->(@_),
22          grep { $_ =~ $re } @Functions, @Barewords;
23 };
24
25 1;
26