make plugins be M::I features so dependencies are optional
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / LexEnv.pm
CommitLineData
314f2293 1package Devel::REPL::Plugin::CompletionDriver::LexEnv;
2use Devel::REPL::Plugin;
3use namespace::clean -except => [ 'meta' ];
4
314f2293 5around complete => sub {
6 my $orig = shift;
7 my ($self, $text, $document) = @_;
8
8051a5e0 9 my $last = $self->last_ppi_element($document);
314f2293 10
11 return $orig->(@_)
12 unless $last->isa('PPI::Token::Symbol');
13
14 my $sigil = substr($last, 0, 1, '');
15 my $re = qr/^\Q$last/;
16
17 return $orig->(@_),
18 # ReadLine is weirdly inconsistent
19 map { $sigil eq '%' ? '%' . $_ : $_ }
20 grep { /$re/ }
21 map { substr($_, 1) } # drop lexical's sigil
06df0767 22 '$_REPL', keys %{$self->lexical_environment->get_context('_')};
314f2293 23};
24
251;
26
cfd1094b 27__END__
28
29=head1 NAME
30
31Devel::REPL::Plugin::CompletionDriver::LexEnv - Complete variable names in the REPL's lexical environment
32
30b459d4 33=head1 AUTHOR
34
35Shawn M Moore, C<< <sartak at gmail dot com> >>
36
cfd1094b 37=cut
38