Have LexEnv wrap find_variable to first look at lexical variables. The around doesn...
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / LexEnv.pm
index 2d48746..fd91a91 100644 (file)
@@ -4,6 +4,8 @@ use Moose::Role;
 use namespace::clean -except => [ 'meta' ];
 use Lexical::Persistence;
 
+with 'Devel::REPL::Plugin::FindVariable';
+
 has 'lexical_environment' => (
   isa => 'Lexical::Persistence',
   is => 'rw',
@@ -42,4 +44,12 @@ around 'execute' => sub {
   return $self->$orig($wrapped, @rest);
 };
 
+around 'find_variable' => sub {
+  my $orig = shift;
+  my ($self, $name) = @_;
+  my $variable = $self->lexical_environment->get_context('_')->{$name};
+  return \$variable if $variable;
+  return $orig->(@_);
+};
+
 1;