Use requires lexical_environment instead of manually checking in AFTER_PLUGIN
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / LexEnv.pm
CommitLineData
314f2293 1package Devel::REPL::Plugin::CompletionDriver::LexEnv;
2use Devel::REPL::Plugin;
3use namespace::clean -except => [ 'meta' ];
4
4444a830 5requires 'lexical_environment';
314f2293 6
7around complete => sub {
8 my $orig = shift;
9 my ($self, $text, $document) = @_;
10
8051a5e0 11 my $last = $self->last_ppi_element($document);
314f2293 12
13 return $orig->(@_)
14 unless $last->isa('PPI::Token::Symbol');
15
16 my $sigil = substr($last, 0, 1, '');
17 my $re = qr/^\Q$last/;
18
19 return $orig->(@_),
20 # ReadLine is weirdly inconsistent
21 map { $sigil eq '%' ? '%' . $_ : $_ }
22 grep { /$re/ }
23 map { substr($_, 1) } # drop lexical's sigil
24 keys %{$self->lexical_environment->get_context('_')};
25};
26
271;
28