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