add use strict; use warnings to modules, just to be sure
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / Keywords.pm
CommitLineData
1716b200 1use strict;
2use warnings;
1989c3d2 3package Devel::REPL::Plugin::CompletionDriver::Keywords;
4use Devel::REPL::Plugin;
5use B::Keywords qw/@Functions @Barewords/;
aa8b7647 6use namespace::autoclean;
1989c3d2 7
3a400715 8sub BEFORE_PLUGIN {
9 my $self = shift;
10 $self->load_plugin('Completion');
11}
6631e15c 12
1989c3d2 13around 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
341;
35
cfd1094b 36__END__
37
38=head1 NAME
39
40Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
41
30b459d4 42=head1 AUTHOR
43
44Shawn M Moore, C<< <sartak at gmail dot com> >>
45
cfd1094b 46=cut
47