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   5197 use strict;
  2         4  
  2         69  
2 2     2   11 use warnings;
  2         4  
  2         129  
3             package Devel::REPL::Plugin::CompletionDriver::Keywords;
4             # ABSTRACT: Complete Perl keywords and operators
5              
6             our $VERSION = '1.003027';
7              
8 2     2   10 use Devel::REPL::Plugin;
  2         2  
  2         17  
9 2     2   10404 use Devel::REPL::Plugin::Completion; # die early if cannot load
  2         4  
  2         64  
10 2     2   651 use B::Keywords qw/@Functions @Barewords/;
  2         1096  
  2         334  
11 2     2   13 use namespace::autoclean;
  2         5  
  2         22  
12              
13             sub BEFORE_PLUGIN {
14 1     1 0 3 my $self = shift;
15 1         7 $self->load_plugin('Completion');
16             }
17              
18             around complete => sub {
19             my $orig = shift;
20             my ($self, $text, $document) = @_;
21              
22             my $last = $self->last_ppi_element($document);
23              
24             return $orig->(@_)
25             unless $last->isa('PPI::Token::Word');
26              
27             # don't complete keywords on foo->method
28             return $orig->(@_)
29             if $last->sprevious_sibling
30             && $last->sprevious_sibling->isa('PPI::Token::Operator')
31             && $last->sprevious_sibling->content eq '->';
32              
33             my $re = qr/^\Q$last/;
34              
35             return $orig->(@_),
36             grep { $_ =~ $re } @Functions, @Barewords;
37             };
38              
39             1;
40              
41             __END__
42              
43             =pod
44              
45             =encoding UTF-8
46              
47             =head1 NAME
48              
49             Devel::REPL::Plugin::CompletionDriver::Keywords - Complete Perl keywords and operators
50              
51             =head1 VERSION
52              
53             version 1.003027
54              
55             =head1 AUTHOR
56              
57             Shawn M Moore, C<< <sartak at gmail dot com> >>
58              
59             =head1 COPYRIGHT AND LICENSE
60              
61             This software is copyright (c) 2007 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>).
62              
63             This is free software; you can redistribute it and/or modify it under
64             the same terms as the Perl 5 programming language system itself.
65              
66             =cut