summaryrefslogtreecommitdiffstats
path: root/lib/App/REPL/Plugin/LexicalPersistence.pm
blob: 6c9b1d38dda1558e1c2c11c3fbf3d445e0676d0b (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
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;