make room for $VERSION after package declaration (newer [PkgVersion] requires it)
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / Keywords.pm
CommitLineData
1716b200 1use strict;
2use warnings;
1989c3d2 3package Devel::REPL::Plugin::CompletionDriver::Keywords;
6f4f9516 4
1989c3d2 5use Devel::REPL::Plugin;
b1c83802 6use Devel::REPL::Plugin::Completion; # die early if cannot load
1989c3d2 7use B::Keywords qw/@Functions @Barewords/;
aa8b7647 8use namespace::autoclean;
1989c3d2 9
3a400715 10sub BEFORE_PLUGIN {
11 my $self = shift;
12 $self->load_plugin('Completion');
13}
6631e15c 14
1989c3d2 15around 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
361;
37
cfd1094b 38__END__
39
40=head1 NAME
41
42Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
43
30b459d4 44=head1 AUTHOR
45
46Shawn M Moore, C<< <sartak at gmail dot com> >>
47
cfd1094b 48=cut
49