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