1 package Devel::REPL::Plugin::History;
3 use Devel::REPL::Plugin;
4 use namespace::autoclean;
7 isa => 'ArrayRef', is => 'rw',
12 # lazy so ReadLineHistory Plugin can set this
13 has 'have_readline_history' => (
20 my ($self, $line) = @_;
21 # Push history is not needed if we have Term::ReadLine
22 # support. We put the test inside push_history() in case
23 # someone has modified it in their code.
24 if ($self->have_readline_history) {
25 # update history to keep consistent with Term::ReadLine
26 $self->history( [ $self->term->GetHistory ] );
28 # not used with Term::ReadLine history support
29 push(@{$self->history}, $line);
33 around 'read' => sub {
35 my ($self, @args) = @_;
36 my $line = $self->$orig(@args);
38 if ($line =~ m/^!(.*)$/) {
40 $line = $self->history_call($call);
42 $self->print($line."\n");
44 return "'Unable to find ${call} in history'";
48 $self->push_history($line);
55 my ($self, $call) = @_;
56 if ($call =~ m/^(-?\d+)$/) { # handle !1 or !-1
58 $idx-- if ($idx > 0); # !1 gets history element 0
59 my $line = $self->history->[$idx];
62 my $re = qr/^\Q${call}\E/;
63 foreach my $line (reverse @{$self->history}) {
64 return $line if ($line =~ $re);
75 Devel::REPL::Plugin::History - Keep track of all input, provide shortcuts !1, !-1