File Coverage

blib/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 27 28 96.4


line stmt bran cond sub pod time code
1 2     2   4404 use strict;
  2         5  
  2         60  
2 2     2   9 use warnings;
  2         6  
  2         104  
3             # ABSTRACT: Complete Perl keywords and operators
4              
5             our $VERSION = '1.003029';
6              
7             use Devel::REPL::Plugin;
8 2     2   10 use Devel::REPL::Plugin::Completion; # die early if cannot load
  2         5  
  2         14  
9 2     2   8955 use B::Keywords qw/@Functions @Barewords/;
  2         5  
  2         61  
10 2     2   645 use namespace::autoclean;
  2         1569  
  2         303  
11 2     2   16  
  2         3  
  2         22  
12             my $self = shift;
13             $self->load_plugin('Completion');
14 1     1 0 3 }
15 1         8  
16             around complete => sub {
17             my $orig = shift;
18             my ($self, $text, $document) = @_;
19              
20             my $last = $self->last_ppi_element($document);
21              
22             return $orig->(@_)
23             unless $last->isa('PPI::Token::Word');
24              
25             # don't complete keywords on foo->method
26             return $orig->(@_)
27             if $last->sprevious_sibling
28             && $last->sprevious_sibling->isa('PPI::Token::Operator')
29             && $last->sprevious_sibling->content eq '->';
30              
31             my $re = qr/^\Q$last/;
32              
33             return $orig->(@_),
34             grep { $_ =~ $re } @Functions, @Barewords;
35             };
36              
37             1;
38              
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
47              
48             =head1 VERSION
49              
50             version 1.003029
51              
52             =head1 SUPPORT
53              
54             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Devel-REPL>
55             (or L<bug-Devel-REPL@rt.cpan.org|mailto:bug-Devel-REPL@rt.cpan.org>).
56              
57             There is also an irc channel available for users of this distribution, at
58             L<C<#devel> on C<irc.perl.org>|irc://irc.perl.org/#devel-repl>.
59              
60             =head1 AUTHOR
61              
62             Shawn M Moore, C<< <sartak at gmail dot com> >>
63              
64             =head1 COPYRIGHT AND LICENCE
65              
66             This software is copyright (c) 2007 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>).
67              
68             This is free software; you can redistribute it and/or modify it under
69             the same terms as the Perl 5 programming language system itself.
70              
71             =cut