blob: 0540f96cbecdd1c6f80ef71b3095b76accb9cd1e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package Reply::Plugin::LexicalPersistence;
use strict;
use warnings;
use base 'Reply::Plugin';
use Lexical::Persistence;
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{env} = Lexical::Persistence->new;
return $self;
}
sub compile {
my $self = shift;
my ($next, $line, %args) = @_;
my %c = %{ $self->{env}->get_context('_') };
$args{environment} ||= {};
$args{environment} = {
%{ $args{environment} },
(map { $_ => ref($c{$_}) ? $c{$_} : \$c{$_} } keys %c),
};
my ($code) = $next->($line, %args);
return $self->{env}->wrap($code);
}
1;
|