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