Commit | Line | Data |
---|---|---|
1716b200 | 1 | use strict; |
2 | use warnings; | |
1989c3d2 | 3 | package Devel::REPL::Plugin::CompletionDriver::Keywords; |
9d2a4940 | 4 | # ABSTRACT: Complete Perl keywords and operators |
6f4f9516 | 5 | |
77327851 | 6 | our $VERSION = '1.003030'; |
54beb05d | 7 | |
1989c3d2 | 8 | use Devel::REPL::Plugin; |
b1c83802 | 9 | use Devel::REPL::Plugin::Completion; # die early if cannot load |
1989c3d2 | 10 | use B::Keywords qw/@Functions @Barewords/; |
aa8b7647 | 11 | use namespace::autoclean; |
1989c3d2 | 12 | |
3a400715 | 13 | sub BEFORE_PLUGIN { |
14 | my $self = shift; | |
15 | $self->load_plugin('Completion'); | |
16 | } | |
6631e15c | 17 | |
1989c3d2 | 18 | around complete => sub { |
19 | my $orig = shift; | |
20 | my ($self, $text, $document) = @_; | |
21 | ||
8051a5e0 | 22 | my $last = $self->last_ppi_element($document); |
1989c3d2 | 23 | |
24 | return $orig->(@_) | |
25 | unless $last->isa('PPI::Token::Word'); | |
26 | ||
873d8203 | 27 | # don't complete keywords on foo->method |
28 | return $orig->(@_) | |
29 | if $last->sprevious_sibling | |
30 | && $last->sprevious_sibling->isa('PPI::Token::Operator') | |
31 | && $last->sprevious_sibling->content eq '->'; | |
32 | ||
1989c3d2 | 33 | my $re = qr/^\Q$last/; |
34 | ||
35 | return $orig->(@_), | |
36 | grep { $_ =~ $re } @Functions, @Barewords; | |
37 | }; | |
38 | ||
39 | 1; | |
40 | ||
cfd1094b | 41 | __END__ |
42 | ||
9d2a4940 | 43 | =pod |
cfd1094b | 44 | |
30b459d4 | 45 | =head1 AUTHOR |
46 | ||
47 | Shawn M Moore, C<< <sartak at gmail dot com> >> | |
48 | ||
cfd1094b | 49 | =cut |