1 package Devel::REPL::Plugin::History;
3 use Devel::REPL::Plugin;
5 use MooX::Types::MooseLike::Base qw(ArrayRef);
8 isa => ArrayRef, is => 'rw', required => 1, lazy => 1,
12 # lazy so ReadLineHistory Plugin can set this
13 has 'have_readline_history' => (
14 is => 'rw', required => 1, lazy => 1,
19 my ($self, $line) = @_;
20 # Push history is not needed if we have Term::ReadLine
21 # support. We put the test inside push_history() in case
22 # someone has modified it in their code.
23 if ($self->have_readline_history) {
24 # update history to keep consistent with Term::ReadLine
25 $self->history( [ $self->term->GetHistory ] );
27 # not used with Term::ReadLine history support
28 push(@{$self->history}, $line);
32 around 'read' => sub {
34 my ($self, @args) = @_;
35 my $line = $self->$orig(@args);
37 if ($line =~ m/^!(.*)$/) {
39 $line = $self->history_call($call);
41 $self->print($line."\n");
43 return "'Unable to find ${call} in history'";
47 $self->push_history($line);
54 my ($self, $call) = @_;
55 if ($call =~ m/^(-?\d+)$/) { # handle !1 or !-1
57 $idx-- if ($idx > 0); # !1 gets history element 0
58 my $line = $self->history->[$idx];
61 my $re = qr/^\Q${call}\E/;
62 foreach my $line (reverse @{$self->history}) {
63 return $line if ($line =~ $re);
74 Devel::REPL::Plugin::History - Keep track of all input, provide shortcuts !1, !-1