increment $VERSION after 1.003028 release
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / LexEnv.pm
1 use strict;
2 use warnings;
3 package Devel::REPL::Plugin::CompletionDriver::LexEnv;
4 # ABSTRACT: Complete variable names in the REPL's lexical environment
5
6 our $VERSION = '1.003029';
7
8 use Devel::REPL::Plugin;
9 use Devel::REPL::Plugin::Completion;    # die early if cannot load
10 use namespace::autoclean;
11
12 sub BEFORE_PLUGIN {
13     my $self = shift;
14     $self->load_plugin('Completion');
15 }
16
17 around complete => sub {
18   my $orig = shift;
19   my ($self, $text, $document) = @_;
20
21   my $last = $self->last_ppi_element($document);
22
23   return $orig->(@_)
24     unless $last->isa('PPI::Token::Symbol');
25
26   my ($sigil, $name) = split(//, $last, 2);
27   my $re = qr/^\Q$name/;
28
29   return $orig->(@_),
30          # ReadLine is weirdly inconsistent
31          map  { $sigil eq '%' ? '%' . $_ : $_ }
32          grep { /$re/ }
33          map  { substr($_, 1) } # drop lexical's sigil
34          '$_REPL', keys %{$self->lexical_environment->get_context('_')};
35 };
36
37 1;
38
39 __END__
40
41 =pod
42
43 =head1 AUTHOR
44
45 Shawn M Moore, C<< <sartak at gmail dot com> >>
46
47 =cut