Psh/Builtins/History.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 50 CC 8 SCAR 41.6
CC
8
Cov
0%
bi_history
72.0
BEGIN
2.0
CRAP 64.2
1 package Psh::Builtins::History;
2  
3 require Psh::Util;
4  
5 =item * C<history> [n]
6  
7 Prints out [the last n] entries in the history
8  
9 =item * C<history> text [n]
10  
11 Searches [the last n] entries in the command history and
12 prints them if they contain "text".
13  
14 =cut
15  
16  
17 sub bi_history
18 {
19 my $i;
20 my $num = @Psh::history;
21 my $grep= undef;
22  
23 return (0,undef) unless $num;
24  
25 if ($_[1]) {
26 my @args=@{$_[1]};
27 while (my $arg=shift @args) {
28 if ($arg=~/^\d+$/) {
29 $num=$arg if $arg<$num;
30 }
31 if ($arg=~/^\S+$/) {
32 $grep=$arg;
33 }
34 }
35 }
36  
37 my $success=0;
38 my $max= @Psh::history;
39 if ($grep) {
40 $max--;
41 }
42 for ($i=@Psh::history-$num; $i<$max; $i++) {
43 next if $grep and $Psh::history[$i]!~/\Q$grep\E/;
44 Psh::Util::print_out(' '.sprintf('%3d',$i+1).' '.$Psh::history[$i]."\n");
45 $success=1;
46 }
47 return ($success,undef);
48 }
49  
50  
51  
52 1;
53  
54 # Local Variables:
55 # mode:perl
56 # tab-width:4
57 # indent-tabs-mode:t
58 # c-basic-offset:4
59 # perl-label-offset:0
60 # perl-indent-level:4
61 # cperl-indent-level:4
62 # cperl-label-offset:0
63 # End: