decc6c8a2e4513efc1310062d7e66807e3f0a89f
[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 with qw(
7   Devel::REPL::Plugin::Completion
8 );
9
10 around complete => sub {
11   my $orig = shift;
12   my ($self, $text, $document) = @_;
13
14   my $last = $self->last_ppi_element($document);
15
16   return $orig->(@_)
17     unless $last->isa('PPI::Token::Word');
18
19   # don't complete keywords on foo->method
20   return $orig->(@_)
21     if $last->sprevious_sibling
22     && $last->sprevious_sibling->isa('PPI::Token::Operator')
23     && $last->sprevious_sibling->content eq '->';
24
25   my $re = qr/^\Q$last/;
26
27   return $orig->(@_),
28          grep { $_ =~ $re } @Functions, @Barewords;
29 };
30
31 1;
32
33 __END__
34
35 =head1 NAME
36
37 Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
38
39 =head1 AUTHOR
40
41 Shawn M Moore, C<< <sartak at gmail dot com> >>
42
43 =cut
44