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