| 1 | # Copyright (C) 2014 Rocky Bernstein <rocky@cpan.org> | ||
| 2 | package Term::ReadLine::Perl5::History; | ||
| 3 | 11 | ▶ | eval "use rlib '.' "; # rlib is now optional |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 11 | ▶ | use Term::ReadLine::Perl5::OO::History; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | =pod | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Term::ReadLine::Perl5::History | ||
| 10 | |||
| 11 | =head1 DESCRIPTION | ||
| 12 | |||
| 13 | Variables and functions supporting L<Term::ReadLine::Perl5>'s command | ||
| 14 | history. This pretends to be OO code even though it isn't. It makes | ||
| 15 | use of global package variables and wraps that up as an object to pass | ||
| 16 | to the corresponding OO routine. | ||
| 17 | |||
| 18 | The underlying OO routines are in | ||
| 19 | L<Term::ReadLine::Perl5::OO::History>. | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | 11 | ▶ | use warnings; use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | |||
| 25 | 11 | use vars qw(@EXPORT @ISA @rl_History $rl_HistoryIndex $rl_history_length | |
| 26 | $rl_MaxHistorySize $rl_max_input_history $history_base | ||
| 27 | 11 | ▶ | $history_stifled); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 28 | |||
| 29 | 11 | @ISA = qw(Exporter); | |
| 30 | 11 | @EXPORT = qw(@rl_History $rl_HistoryIndex $rl_history_length | |
| 31 | &add_line_to_history | ||
| 32 | $rl_MaxHistorySize $rl_max_input_history $history_stifled); | ||
| 33 | |||
| 34 | # FIXME: eventually we will remove these variables when we are fully OO. | ||
| 35 | 11 | @rl_History = (); | |
| 36 | 11 | $rl_MaxHistorySize = 100; | |
| 37 | 11 | $rl_history_length = 0; | |
| 38 | 11 | $rl_max_input_history = 0; | |
| 39 | 11 | $rl_history_length = $rl_max_input_history = 0; | |
| 40 | |||
| 41 | 11 | $history_stifled = 0; | |
| 42 | 11 | $history_base = 0; | |
| 43 | |||
| 44 | =head1 SUBROUTINES | ||
| 45 | |||
| 46 | =head2 add_line_to_history | ||
| 47 | |||
| 48 | B<add_line_to_history>(I<$line>, I<$minlength>) | ||
| 49 | |||
| 50 | Insert I<$line> into history list if I<$line> is: | ||
| 51 | |||
| 52 | =over | ||
| 53 | |||
| 54 | =item * | ||
| 55 | |||
| 56 | bigger than the minimal length I<$minlength> | ||
| 57 | |||
| 58 | =item * | ||
| 59 | |||
| 60 | not same as last entry | ||
| 61 | |||
| 62 | =back | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | # Fake up a needed object using global state | ||
| 67 | sub _fake_self() { | ||
| 68 | { | ||
| 69 | 28 | ▶ | rl_History => \@rl_History, |
|
Subroutine
_fake_self: called CC=1 SCAR=0.0
| |||
| 70 | rl_MaxHistorySize => $rl_MaxHistorySize, | ||
| 71 | rl_HistoryIndex => $rl_HistoryIndex, | ||
| 72 | rl_history_length => $rl_history_length, | ||
| 73 | rl_max_input_history => $rl_max_input_history, | ||
| 74 | history_stifled => $history_stifled, | ||
| 75 | }; | ||
| 76 | } | ||
| 77 | |||
| 78 | |||
| 79 | # FIXME: DRY this adding a common routine to fake $self. | ||
| 80 | sub add_line_to_history | ||
| 81 | { | ||
| 82 | 0 | ▶ | my ($line, $minlength) = @_; |
|
Subroutine
add_line_to_history: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 83 | |||
| 84 | 0 | my $self = _fake_self(); | |
| 85 | 0 | Term::ReadLine::Perl5::OO::History::add_line_to_history( | |
| 86 | $self, $line, $minlength); | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | sub add_history | ||
| 91 | { | ||
| 92 | 3 | ▶ | shift; |
|
Subroutine
add_history: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 93 | 3 | my $self = _fake_self(); | |
| 94 | 3 | Term::ReadLine::Perl5::OO::History::add_history($self, @_); | |
| 95 | 3 | $rl_MaxHistorySize = $self->{rl_MaxHistorySize}; | |
| 96 | 3 | $rl_HistoryIndex = $self->{rl_HistoryIndex}; | |
| 97 | 3 | $rl_history_length = $self->{rl_history_length}; | |
| 98 | } | ||
| 99 | |||
| 100 | sub clear_history() | ||
| 101 | { | ||
| 102 | 0 | ▶ | my $self = _fake_self(); |
|
Subroutine
clear_history: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 103 | 0 | Term::ReadLine::Perl5::OO::History::clear_history($self); | |
| 104 | 0 | @rl_History = @{$self->{rl_History}}; | |
| 105 | 0 | $rl_MaxHistorySize = $self->{rl_MaxHistorySize}; | |
| 106 | 0 | $rl_HistoryIndex = $self->{rl_HistoryIndex}; | |
| 107 | 0 | $rl_history_length = $self->{rl_history_length}; | |
| 108 | } | ||
| 109 | |||
| 110 | |||
| 111 | sub GetHistory() | ||
| 112 | { | ||
| 113 | 8 | ▶ | Term::ReadLine::Perl5::OO::History::GetHistory(_fake_self()); |
|
Subroutine
GetHistory: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 114 | } | ||
| 115 | |||
| 116 | sub history_is_stifled($) { | ||
| 117 | 5 | ▶ | shift; |
|
Subroutine
history_is_stifled: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 118 | 5 | my $self = _fake_self(); | |
| 119 | 5 | return Term::ReadLine::Perl5::OO::History::history_is_stifled($self); | |
| 120 | } | ||
| 121 | |||
| 122 | sub read_history($$) { | ||
| 123 | 2 | ▶ | my ($unused, $filename) = @_; |
|
Subroutine
read_history: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 124 | 2 | my $self = _fake_self(); | |
| 125 | 2 | my $ret = Term::ReadLine::Perl5::OO::History::read_history($self, | |
| 126 | $filename); | ||
| 127 | 2 | @rl_History = @{$self->{rl_History}}; | |
| 128 | 2 | $rl_MaxHistorySize = $self->{rl_MaxHistorySize}; | |
| 129 | 2 | $rl_HistoryIndex = $self->{rl_HistoryIndex}; | |
| 130 | 2 | $rl_history_length = $self->{rl_history_length}; | |
| 131 | 2 | return $ret; | |
| 132 | } | ||
| 133 | |||
| 134 | sub ReadHistory($$) { | ||
| 135 | 1 | ▶ | my ($unused, $filename) = @_; |
|
Subroutine
ReadHistory: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 136 | 1 | ! read_history($unused, $filename); | |
| 137 | } | ||
| 138 | |||
| 139 | sub remove_history($) | ||
| 140 | { | ||
| 141 | 1 | ▶ | shift; |
|
Subroutine
remove_history: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 142 | 1 | my ($which) = @_; | |
| 143 | 1 | my $self = _fake_self(); | |
| 144 | 1 | Term::ReadLine::Perl5::OO::History::remove_history($self, $which); | |
| 145 | 1 | @rl_History = @{$self->{rl_History}}; | |
| 146 | 1 | $rl_MaxHistorySize = $self->{rl_MaxHistorySize}; | |
| 147 | 1 | $rl_HistoryIndex = $self->{rl_HistoryIndex}; | |
| 148 | 1 | $rl_history_length = $self->{rl_history_length}; | |
| 149 | } | ||
| 150 | |||
| 151 | sub replace_history_entry { | ||
| 152 | 1 | ▶ | shift; |
|
Subroutine
replace_history_entry: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 153 | 1 | my ($which, $data) = @_; | |
| 154 | 1 | my $self = _fake_self(); | |
| 155 | 1 | my $replaced = | |
| 156 | Term::ReadLine::Perl5::OO::History::replace_history_entry($self, | ||
| 157 | $which, | ||
| 158 | $data); | ||
| 159 | 1 | @rl_History = @{$self->{rl_History}}; | |
| 160 | 1 | $rl_MaxHistorySize = $self->{rl_MaxHistorySize}; | |
| 161 | 1 | $rl_HistoryIndex = $self->{rl_HistoryIndex}; | |
| 162 | 1 | $rl_history_length = $self->{rl_history_length}; | |
| 163 | 1 | return $replaced; | |
| 164 | } | ||
| 165 | |||
| 166 | sub SetHistory | ||
| 167 | { | ||
| 168 | 5 | ▶ | shift; |
|
Subroutine
SetHistory: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 169 | # Fake up a needed object using global state | ||
| 170 | 5 | my $self = _fake_self(); | |
| 171 | 5 | Term::ReadLine::Perl5::OO::History::SetHistory($self, @_); | |
| 172 | 5 | @rl_History = @{$self->{rl_History}}; | |
| 173 | 5 | $rl_MaxHistorySize = $self->{rl_MaxHistorySize}; | |
| 174 | 5 | $rl_HistoryIndex = $self->{rl_HistoryIndex}; | |
| 175 | 5 | $rl_history_length = $self->{rl_history_length}; | |
| 176 | } | ||
| 177 | |||
| 178 | sub unstifle_history($) | ||
| 179 | { | ||
| 180 | 1 | ▶ | shift; |
|
Subroutine
unstifle_history: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 181 | 1 | my $self = _fake_self(); | |
| 182 | 1 | Term::ReadLine::Perl5::OO::History::unstifle_history($self); | |
| 183 | 1 | $history_stifled = $self->{history_stifled}; | |
| 184 | } | ||
| 185 | |||
| 186 | sub write_history($$) { | ||
| 187 | 1 | ▶ | my ($unused, $filename) = @_; |
|
Subroutine
write_history: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 188 | 1 | my $self = _fake_self(); | |
| 189 | 1 | Term::ReadLine::Perl5::OO::History::write_history($self, | |
| 190 | $filename); | ||
| 191 | } | ||
| 192 | |||
| 193 | sub WriteHistory($$) { | ||
| 194 | 1 | ▶ | my ($unused, $filename) = @_; |
|
Subroutine
WriteHistory: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 195 | 1 | my $self = _fake_self(); | |
| 196 | 1 | Term::ReadLine::Perl5::OO::History::WriteHistory($self, | |
| 197 | $filename); | ||
| 198 | } | ||
| 199 | |||
| 200 | |||
| 201 | 11 | 1; | |