Commit | Line | Data |
1716b200 |
1 | use strict; |
2 | use warnings; |
314f2293 |
3 | package Devel::REPL::Plugin::CompletionDriver::LexEnv; |
4 | use Devel::REPL::Plugin; |
b1c83802 |
5 | use Devel::REPL::Plugin::Completion; # die early if cannot load |
aa8b7647 |
6 | use namespace::autoclean; |
314f2293 |
7 | |
75a08365 |
8 | sub BEFORE_PLUGIN { |
9 | my $self = shift; |
10 | $self->load_plugin('Completion'); |
11 | } |
12 | |
314f2293 |
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 | |
9b7bfb6a |
22 | my ($sigil, $name) = split(//, $last, 2); |
23 | my $re = qr/^\Q$name/; |
314f2293 |
24 | |
25 | return $orig->(@_), |
26 | # ReadLine is weirdly inconsistent |
27 | map { $sigil eq '%' ? '%' . $_ : $_ } |
28 | grep { /$re/ } |
29 | map { substr($_, 1) } # drop lexical's sigil |
06df0767 |
30 | '$_REPL', keys %{$self->lexical_environment->get_context('_')}; |
314f2293 |
31 | }; |
32 | |
33 | 1; |
34 | |
cfd1094b |
35 | __END__ |
36 | |
37 | =head1 NAME |
38 | |
39 | Devel::REPL::Plugin::CompletionDriver::LexEnv - Complete variable names in the REPL's lexical environment |
40 | |
30b459d4 |
41 | =head1 AUTHOR |
42 | |
43 | Shawn M Moore, C<< <sartak at gmail dot com> >> |
44 | |
cfd1094b |
45 | =cut |
46 | |