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