3 package Devel::REPL::Plugin::History;
5 use Devel::REPL::Plugin;
6 use namespace::autoclean;
9 isa => 'ArrayRef', is => 'rw',
14 # lazy so ReadLineHistory Plugin can set this
15 has 'have_readline_history' => (
22 my ($self, $line) = @_;
23 # Push history is not needed if we have Term::ReadLine
24 # support. We put the test inside push_history() in case
25 # someone has modified it in their code.
26 if ($self->have_readline_history) {
27 # update history to keep consistent with Term::ReadLine
28 $self->history( [ $self->term->GetHistory ] );
30 # not used with Term::ReadLine history support
31 push(@{$self->history}, $line);
35 around 'read' => sub {
37 my ($self, @args) = @_;
38 my $line = $self->$orig(@args);
40 if ($line =~ m/^!(.*)$/) {
42 $line = $self->history_call($call);
44 $self->print($line."\n");
46 return "'Unable to find ${call} in history'";
50 $self->push_history($line);
57 my ($self, $call) = @_;
58 if ($call =~ m/^(-?\d+)$/) { # handle !1 or !-1
60 $idx-- if ($idx > 0); # !1 gets history element 0
61 my $line = $self->history->[$idx];
64 my $re = qr/^\Q${call}\E/;
65 foreach my $line (reverse @{$self->history}) {
66 return $line if ($line =~ $re);
77 Devel::REPL::Plugin::History - Keep track of all input, provide shortcuts !1, !-1