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