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