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