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