r79775@onn: sartak | 2009-02-06 15:56:59 -0500
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / Keywords.pm
CommitLineData
1989c3d2 1package Devel::REPL::Plugin::CompletionDriver::Keywords;
2use Devel::REPL::Plugin;
3use B::Keywords qw/@Functions @Barewords/;
4use namespace::clean -except => [ 'meta' ];
5
3a400715 6sub BEFORE_PLUGIN {
7 my $self = shift;
8 $self->load_plugin('Completion');
9}
6631e15c 10
1989c3d2 11around complete => sub {
12 my $orig = shift;
13 my ($self, $text, $document) = @_;
14
8051a5e0 15 my $last = $self->last_ppi_element($document);
1989c3d2 16
17 return $orig->(@_)
18 unless $last->isa('PPI::Token::Word');
19
873d8203 20 # don't complete keywords on foo->method
21 return $orig->(@_)
22 if $last->sprevious_sibling
23 && $last->sprevious_sibling->isa('PPI::Token::Operator')
24 && $last->sprevious_sibling->content eq '->';
25
1989c3d2 26 my $re = qr/^\Q$last/;
27
28 return $orig->(@_),
29 grep { $_ =~ $re } @Functions, @Barewords;
30};
31
321;
33
cfd1094b 34__END__
35
36=head1 NAME
37
38Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
39
30b459d4 40=head1 AUTHOR
41
42Shawn M Moore, C<< <sartak at gmail dot com> >>
43
cfd1094b 44=cut
45