I no longer use this plugin in my bundle
[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
54beb05d 5our $VERSION = '1.003027';
6
1989c3d2 7use Devel::REPL::Plugin;
b1c83802 8use Devel::REPL::Plugin::Completion; # die early if cannot load
1989c3d2 9use B::Keywords qw/@Functions @Barewords/;
aa8b7647 10use namespace::autoclean;
1989c3d2 11
3a400715 12sub BEFORE_PLUGIN {
13 my $self = shift;
14 $self->load_plugin('Completion');
15}
6631e15c 16
1989c3d2 17around 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
381;
39
cfd1094b 40__END__
41
42=head1 NAME
43
44Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
45
30b459d4 46=head1 AUTHOR
47
48Shawn M Moore, C<< <sartak at gmail dot com> >>
49
cfd1094b 50=cut
51