X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=blobdiff_plain;f=lib%2FDevel%2FREPL%2FPlugin%2FCompletionDriver%2FLexEnv.pm;h=63a05fd0b26953e88874534edef2f7f687ec7e1b;hp=87a588f8037b37d6a50d7af871f02f24b84da943;hb=b1c838027a427ea0e16bdf60024826b3ed1574f8;hpb=30b459d4fbeb6f2406a3013c7cbcc46a6d0ccf0d diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/LexEnv.pm b/lib/Devel/REPL/Plugin/CompletionDriver/LexEnv.pm index 87a588f..63a05fd 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/LexEnv.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/LexEnv.pm @@ -1,13 +1,13 @@ +use strict; +use warnings; package Devel::REPL::Plugin::CompletionDriver::LexEnv; use Devel::REPL::Plugin; -use namespace::clean -except => [ 'meta' ]; +use Devel::REPL::Plugin::Completion; # die early if cannot load +use namespace::autoclean; -sub AFTER_PLUGIN { - my ($_REPL) = @_; - - if (!$_REPL->can('lexical_environment')) { - warn "Devel::REPL::Plugin::CompletionDriver::LexEnv requires Devel::REPL::Plugin::LexEnv."; - } +sub BEFORE_PLUGIN { + my $self = shift; + $self->load_plugin('Completion'); } around complete => sub { @@ -19,15 +19,15 @@ around complete => sub { return $orig->(@_) unless $last->isa('PPI::Token::Symbol'); - my $sigil = substr($last, 0, 1, ''); - my $re = qr/^\Q$last/; + my ($sigil, $name) = split(//, $last, 2); + my $re = qr/^\Q$name/; return $orig->(@_), # ReadLine is weirdly inconsistent map { $sigil eq '%' ? '%' . $_ : $_ } grep { /$re/ } map { substr($_, 1) } # drop lexical's sigil - keys %{$self->lexical_environment->get_context('_')}; + '$_REPL', keys %{$self->lexical_environment->get_context('_')}; }; 1;