resolve rt.cpan#44919 fix deprecated use of compute_all_applicable_methods
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / CompletionDriver / LexEnv.pm
1 package Devel::REPL::Plugin::CompletionDriver::LexEnv;
2 use Devel::REPL::Plugin;
3 use namespace::clean -except => [ 'meta' ];
4
5 sub BEFORE_PLUGIN {
6     my $self = shift;
7     $self->load_plugin('Completion');
8 }
9
10 around complete => sub {
11   my $orig = shift;
12   my ($self, $text, $document) = @_;
13
14   my $last = $self->last_ppi_element($document);
15
16   return $orig->(@_)
17     unless $last->isa('PPI::Token::Symbol');
18
19   my $sigil = substr($last, 0, 1, '');
20   my $re = qr/^\Q$last/;
21
22   return $orig->(@_),
23          # ReadLine is weirdly inconsistent
24          map  { $sigil eq '%' ? '%' . $_ : $_ }
25          grep { /$re/ }
26          map  { substr($_, 1) } # drop lexical's sigil
27          '$_REPL', keys %{$self->lexical_environment->get_context('_')};
28 };
29
30 1;
31
32 __END__
33
34 =head1 NAME
35
36 Devel::REPL::Plugin::CompletionDriver::LexEnv - Complete variable names in the REPL's lexical environment
37
38 =head1 AUTHOR
39
40 Shawn M Moore, C<< <sartak at gmail dot com> >>
41
42 =cut
43