3 package Devel::REPL::Plugin::History;
5 our $VERSION = '1.003027';
7 use Devel::REPL::Plugin;
8 use namespace::autoclean;
11 isa => 'ArrayRef', is => 'rw',
16 # lazy so ReadLineHistory Plugin can set this
17 has 'have_readline_history' => (
24 my ($self, $line) = @_;
25 # Push history is not needed if we have Term::ReadLine
26 # support. We put the test inside push_history() in case
27 # someone has modified it in their code.
28 if ($self->have_readline_history) {
29 # update history to keep consistent with Term::ReadLine
30 $self->history( [ $self->term->GetHistory ] );
32 # not used with Term::ReadLine history support
33 push(@{$self->history}, $line);
37 around 'read' => sub {
39 my ($self, @args) = @_;
40 my $line = $self->$orig(@args);
42 if ($line =~ m/^!(.*)$/) {
44 $line = $self->history_call($call);
46 $self->print($line."\n");
48 return "'Unable to find ${call} in history'";
52 $self->push_history($line);
59 my ($self, $call) = @_;
60 if ($call =~ m/^(-?\d+)$/) { # handle !1 or !-1
62 $idx-- if ($idx > 0); # !1 gets history element 0
63 my $line = $self->history->[$idx];
66 my $re = qr/^\Q${call}\E/;
67 foreach my $line (reverse @{$self->history}) {
68 return $line if ($line =~ $re);
79 Devel::REPL::Plugin::History - Keep track of all input, provide shortcuts !1, !-1