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