From d8a90a03e9c5e8e2732374a10e0e79289ffb793c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 30 May 2013 04:41:11 -0500 Subject: App::REPL -> Reply --- lib/Reply/Plugin/LexicalPersistence.pm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/Reply/Plugin/LexicalPersistence.pm (limited to 'lib/Reply/Plugin/LexicalPersistence.pm') diff --git a/lib/Reply/Plugin/LexicalPersistence.pm b/lib/Reply/Plugin/LexicalPersistence.pm new file mode 100644 index 0000000..0540f96 --- /dev/null +++ b/lib/Reply/Plugin/LexicalPersistence.pm @@ -0,0 +1,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; -- cgit v1.2.3-54-g00ecf