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