Commit | Line | Data |
1989c3d2 |
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 | |
3a400715 |
6 | sub BEFORE_PLUGIN { |
7 | my $self = shift; |
8 | $self->load_plugin('Completion'); |
9 | } |
6631e15c |
10 | |
1989c3d2 |
11 | around complete => sub { |
12 | my $orig = shift; |
13 | my ($self, $text, $document) = @_; |
14 | |
8051a5e0 |
15 | my $last = $self->last_ppi_element($document); |
1989c3d2 |
16 | |
17 | return $orig->(@_) |
18 | unless $last->isa('PPI::Token::Word'); |
19 | |
873d8203 |
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 | |
1989c3d2 |
26 | my $re = qr/^\Q$last/; |
27 | |
28 | return $orig->(@_), |
29 | grep { $_ =~ $re } @Functions, @Barewords; |
30 | }; |
31 | |
32 | 1; |
33 | |
cfd1094b |
34 | __END__ |
35 | |
36 | =head1 NAME |
37 | |
38 | Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators |
39 | |
30b459d4 |
40 | =head1 AUTHOR |
41 | |
42 | Shawn M Moore, C<< <sartak at gmail dot com> >> |
43 | |
cfd1094b |
44 | =cut |
45 | |