plugin metaclass, profiles, commands plugi
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / LexEnv.pm
CommitLineData
85cd2780 1package Devel::REPL::Plugin::LexEnv;
2
3use Moose::Role;
4use namespace::clean -except => [ 'meta' ];
5use Lexical::Persistence;
6
7has 'lexical_environment' => (
8 isa => 'Lexical::Persistence',
9 is => 'rw',
10 required => 1,
11 lazy => 1,
12 default => sub { Lexical::Persistence->new }
13);
14
15around 'mangle_line' => sub {
16 my $orig = shift;
17 my ($self, @rest) = @_;
18 my $line = $self->$orig(@rest);
19 my $lp = $self->lexical_environment;
4d33251a 20 # Collate my declarations for all LP context vars then add '';
21 # so an empty statement doesn't return anything (with a no warnings
22 # to prevent "Useless use ..." warning)
23 return join('', map { "my $_;\n" } keys %{$lp->get_context('_')})
24 .qq{{ no warnings 'void'; ''; }\n}.$line;
85cd2780 25};
26
27around 'execute' => sub {
28 my $orig = shift;
29 my ($self, $to_exec, @rest) = @_;
30 my $wrapped = $self->lexical_environment->wrap($to_exec);
31 return $self->$orig($wrapped, @rest);
32};
33
341;