1 package Devel::REPL::Plugin::LexEnv;
4 use namespace::clean -except => [ 'meta' ];
5 use Lexical::Persistence;
7 has 'lexical_environment' => (
8 isa => 'Lexical::Persistence',
12 default => sub { Lexical::Persistence->new }
18 predicate => '_has_hints',
21 around 'mangle_line' => sub {
23 my ($self, @rest) = @_;
24 my $line = $self->$orig(@rest);
25 my $lp = $self->lexical_environment;
26 # Collate my declarations for all LP context vars then add '';
27 # so an empty statement doesn't return anything (with a no warnings
28 # to prevent "Useless use ..." warning)
30 'BEGIN { if ( $_REPL->_has_hints ) { ( $^H, %^H ) = @{ $_REPL->_hints } } }',
31 ( map { "my $_;\n" } keys %{$lp->get_context('_')} ),
32 qq{{ no warnings 'void'; ''; }\n},
34 '; BEGIN { $_REPL->_hints([ $^H, %^H ]) }',
38 around 'execute' => sub {
40 my ($self, $to_exec, @rest) = @_;
41 my $wrapped = $self->lexical_environment->wrap($to_exec);
42 return $self->$orig($wrapped, @rest);