r61091@onn: sartak | 2008-05-26 21:32:50 -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
6around complete => sub {
7 my $orig = shift;
8 my ($self, $text, $document) = @_;
9
8051a5e0 10 my $last = $self->last_ppi_element($document);
1989c3d2 11
12 return $orig->(@_)
13 unless $last->isa('PPI::Token::Word');
14
873d8203 15 # don't complete keywords on foo->method
16 return $orig->(@_)
17 if $last->sprevious_sibling
18 && $last->sprevious_sibling->isa('PPI::Token::Operator')
19 && $last->sprevious_sibling->content eq '->';
20
1989c3d2 21 my $re = qr/^\Q$last/;
22
23 return $orig->(@_),
24 grep { $_ =~ $re } @Functions, @Barewords;
25};
26
271;
28
cfd1094b 29__END__
30
31=head1 NAME
32
33Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
34
35=cut
36