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