r61340@onn: sartak | 2008-05-31 12:17:19 -0400
[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
6631e15c 6with qw(
7 Devel::REPL::Plugin::Completion
8);
9
1989c3d2 10around complete => sub {
11 my $orig = shift;
12 my ($self, $text, $document) = @_;
13
8051a5e0 14 my $last = $self->last_ppi_element($document);
1989c3d2 15
16 return $orig->(@_)
17 unless $last->isa('PPI::Token::Word');
18
873d8203 19 # don't complete keywords on foo->method
20 return $orig->(@_)
21 if $last->sprevious_sibling
22 && $last->sprevious_sibling->isa('PPI::Token::Operator')
23 && $last->sprevious_sibling->content eq '->';
24
1989c3d2 25 my $re = qr/^\Q$last/;
26
27 return $orig->(@_),
28 grep { $_ =~ $re } @Functions, @Barewords;
29};
30
311;
32
cfd1094b 33__END__
34
35=head1 NAME
36
37Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
38
30b459d4 39=head1 AUTHOR
40
41Shawn M Moore, C<< <sartak at gmail dot com> >>
42
cfd1094b 43=cut
44