diff options
Diffstat (limited to 'lib/App/REPL/Plugin/LexicalPersistence.pm')
-rw-r--r-- | lib/App/REPL/Plugin/LexicalPersistence.pm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/App/REPL/Plugin/LexicalPersistence.pm b/lib/App/REPL/Plugin/LexicalPersistence.pm new file mode 100644 index 0000000..6c9b1d3 --- /dev/null +++ b/lib/App/REPL/Plugin/LexicalPersistence.pm @@ -0,0 +1,25 @@ +package App::REPL::Plugin::LexicalPersistence; +use strict; +use warnings; + +use base 'App::REPL::Plugin'; + +use Lexical::Persistence; + +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); + $self->{env} = Lexical::Persistence->new; + return $self; +} + +sub evaluate { + my $self = shift; + my ($next, $line, %args) = @_; + + $line = $self->{env}->prepare($line); + my ($code) = $next->($line, %args); + return $self->{env}->call($code); +} + +1; |