Commit | Line | Data |
314f2293 |
1 | package Devel::REPL::Plugin::CompletionDriver::LexEnv; |
2 | use Devel::REPL::Plugin; |
3 | use namespace::clean -except => [ 'meta' ]; |
4 | |
5 | sub AFTER_PLUGIN { |
6 | my ($_REPL) = @_; |
7 | |
8 | if (!$_REPL->can('lexical_environment')) { |
9 | warn "Devel::REPL::Plugin::CompletionDriver::LexEnv requires Devel::REPL::Plugin::LexEnv."; |
10 | } |
11 | } |
12 | |
13 | around complete => sub { |
14 | my $orig = shift; |
15 | my ($self, $text, $document) = @_; |
16 | |
8051a5e0 |
17 | my $last = $self->last_ppi_element($document); |
314f2293 |
18 | |
19 | return $orig->(@_) |
20 | unless $last->isa('PPI::Token::Symbol'); |
21 | |
22 | my $sigil = substr($last, 0, 1, ''); |
23 | my $re = qr/^\Q$last/; |
24 | |
25 | return $orig->(@_), |
26 | # ReadLine is weirdly inconsistent |
27 | map { $sigil eq '%' ? '%' . $_ : $_ } |
28 | grep { /$re/ } |
29 | map { substr($_, 1) } # drop lexical's sigil |
30 | keys %{$self->lexical_environment->get_context('_')}; |
31 | }; |
32 | |
33 | 1; |
34 | |