line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
2810
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
2
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
99
|
|
3
|
|
|
|
|
|
|
package Devel::REPL::Plugin::History; |
4
|
|
|
|
|
|
|
# ABSTRACT: Keep track of all input, provide shortcuts !1, !-1 |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.003027'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
6
|
use Devel::REPL::Plugin; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
9
|
2
|
|
|
2
|
|
9351
|
use namespace::autoclean; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
21
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'history' => ( |
12
|
|
|
|
|
|
|
isa => 'ArrayRef', is => 'rw', |
13
|
|
|
|
|
|
|
lazy => 1, |
14
|
|
|
|
|
|
|
default => sub { [] } |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# lazy so ReadLineHistory Plugin can set this |
18
|
|
|
|
|
|
|
has 'have_readline_history' => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
lazy => 1, |
21
|
|
|
|
|
|
|
default => sub { 0 } |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub push_history { |
25
|
0
|
|
|
0
|
0
|
|
my ($self, $line) = @_; |
26
|
|
|
|
|
|
|
# Push history is not needed if we have Term::ReadLine |
27
|
|
|
|
|
|
|
# support. We put the test inside push_history() in case |
28
|
|
|
|
|
|
|
# someone has modified it in their code. |
29
|
0
|
0
|
|
|
|
|
if ($self->have_readline_history) { |
30
|
|
|
|
|
|
|
# update history to keep consistent with Term::ReadLine |
31
|
0
|
|
|
|
|
|
$self->history( [ $self->term->GetHistory ] ); |
32
|
|
|
|
|
|
|
} else { |
33
|
|
|
|
|
|
|
# not used with Term::ReadLine history support |
34
|
0
|
|
|
|
|
|
push(@{$self->history}, $line); |
|
0
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
around 'read' => sub { |
39
|
|
|
|
|
|
|
my $orig = shift; |
40
|
|
|
|
|
|
|
my ($self, @args) = @_; |
41
|
|
|
|
|
|
|
my $line = $self->$orig(@args); |
42
|
|
|
|
|
|
|
if (defined $line) { |
43
|
|
|
|
|
|
|
if ($line =~ m/^!(.*)$/) { |
44
|
|
|
|
|
|
|
my $call = $1; |
45
|
|
|
|
|
|
|
$line = $self->history_call($call); |
46
|
|
|
|
|
|
|
if (defined $line) { |
47
|
|
|
|
|
|
|
$self->print($line."\n"); |
48
|
|
|
|
|
|
|
} else { |
49
|
|
|
|
|
|
|
return "'Unable to find ${call} in history'"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
if ($line =~ m/\S/) { |
53
|
|
|
|
|
|
|
$self->push_history($line); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
return $line; |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub history_call { |
60
|
0
|
|
|
0
|
0
|
|
my ($self, $call) = @_; |
61
|
0
|
0
|
|
|
|
|
if ($call =~ m/^(-?\d+)$/) { # handle !1 or !-1 |
62
|
0
|
|
|
|
|
|
my $idx = $1; |
63
|
0
|
0
|
|
|
|
|
$idx-- if ($idx > 0); # !1 gets history element 0 |
64
|
0
|
|
|
|
|
|
my $line = $self->history->[$idx]; |
65
|
0
|
|
|
|
|
|
return $line; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
my $re = qr/^\Q${call}\E/; |
68
|
0
|
|
|
|
|
|
foreach my $line (reverse @{$self->history}) { |
|
0
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
return $line if ($line =~ $re); |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
return; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=pod |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=encoding UTF-8 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Devel::REPL::Plugin::History - Keep track of all input, provide shortcuts !1, !-1 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 VERSION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
version 1.003027 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>). |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
99
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |