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