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