1 package Devel::REPL::Plugin::History;
4 use namespace::clean -except => [ 'meta' ];
7 isa => 'ArrayRef', is => 'rw', required => 1, lazy => 1,
12 my ($self, $line) = @_;
13 push(@{$self->history}, $line);
16 around 'read' => sub {
18 my ($self, @args) = @_;
19 my $line = $self->$orig(@args);
21 if ($line =~ m/^!(.*)$/) {
23 $line = $self->history_call($call);
25 $self->print($line."\n");
27 return "'Unable to find ${call} in history'";
31 $self->push_history($line);
38 my ($self, $call) = @_;
39 if ($call =~ m/^(-?\d+)$/) { # handle !1 or !-1
41 $idx-- if ($idx > 0); # !1 gets history element 0
42 my $line = $self->history->[$idx];
45 my $re = qr/^\Q${call}\E/;
46 foreach my $line (reverse @{$self->history}) {
47 return $line if ($line =~ $re);