make room for $VERSION after package declaration (newer [PkgVersion] requires it)
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / Keywords.pm
1 use strict;
2 use warnings;
3 package Devel::REPL::Plugin::CompletionDriver::Keywords;
4
5 use Devel::REPL::Plugin;
6 use Devel::REPL::Plugin::Completion;    # die early if cannot load
7 use B::Keywords qw/@Functions @Barewords/;
8 use namespace::autoclean;
9
10 sub BEFORE_PLUGIN {
11     my $self = shift;
12     $self->load_plugin('Completion');
13 }
14
15 around complete => sub {
16   my $orig = shift;
17   my ($self, $text, $document) = @_;
18
19   my $last = $self->last_ppi_element($document);
20
21   return $orig->(@_)
22     unless $last->isa('PPI::Token::Word');
23
24   # don't complete keywords on foo->method
25   return $orig->(@_)
26     if $last->sprevious_sibling
27     && $last->sprevious_sibling->isa('PPI::Token::Operator')
28     && $last->sprevious_sibling->content eq '->';
29
30   my $re = qr/^\Q$last/;
31
32   return $orig->(@_),
33          grep { $_ =~ $re } @Functions, @Barewords;
34 };
35
36 1;
37
38 __END__
39
40 =head1 NAME
41
42 Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
43
44 =head1 AUTHOR
45
46 Shawn M Moore, C<< <sartak at gmail dot com> >>
47
48 =cut
49