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