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