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