f9171634155a6d2ae9e68c9b75b8d0b67be9cc68
[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   my $last = $self->last_ppi_element($document);
11
12   return $orig->(@_)
13     unless $last->isa('PPI::Token::Word');
14
15   # don't complete keywords on foo->method
16   return $orig->(@_)
17     if $last->sprevious_sibling
18     && $last->sprevious_sibling->isa('PPI::Token::Operator')
19     && $last->sprevious_sibling->content eq '->';
20
21   my $re = qr/^\Q$last/;
22
23   return $orig->(@_),
24          grep { $_ =~ $re } @Functions, @Barewords;
25 };
26
27 1;
28
29 __END__
30
31 =head1 NAME
32
33 Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
34
35 =cut
36