VTide/Command/History.pm

filter: Statementstmt 41.0% 23 / 56 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 28.8% 32 / 111 CC 17 SCAR 53.4
CC
17
Cov
26%
run
306.0
details_sub
2.0
auto_complete
2.0
CRAP 208.5
↑ Summary VTide/Command/Start.pm »
1 package App::VTide::Command::History;
2  
3 # Created on: 2016-03-22 15:42:06
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 extends 'App::VTide::Command::Run';
17  
18 1 our $VERSION = version->new('1.0.6');
19 1 our $NAME = 'history';
20 1 our $OPTIONS =
21 [ 'number|n=i', 'uniq|u', 'search|s=s', 'ignore|i=s', 'verbose|v+', ];
22 0 ▶sub details_sub { return ( $NAME, $OPTIONS ) }
Subroutine details_sub: not called CC=1 SCAR=6.9
Pod documented
23  
24 0 ▶sub run {
Subroutine run: not called CC=17 SCAR=57.2
Pod documented
25 0 my ($self) = @_;
26 0 my @history;
27 my %uniq;
28 0 ▶ my $max = $self->defaults->{number} || 10;
Condition0%0/2
$self->defaults->{'number'} || 10
l!l
00
MC/DC0%0/1
$self->defaults->{'number'} || 10
$self->defaults->{'number'}
Truth table0%0/2
A
A= $self->defaults->{'number'}
Aresult
11
00
29 0 ▶ my $run_line = @ARGV && $ARGV[$#ARGV] =~ /^\d+$/ ? pop @ARGV : -1;
Branch: 1 branch
BranchTrueFalseTotal
@ARGV && $ARGV[$#ARGV] =~ /^\d+$/ ? : 0 0 0
Condition0%0/3
@ARGV and $ARGV[$#ARGV] =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
@ARGV and $ARGV[$#ARGV] =~ /^\d+$/
@ARGV $ARGV[$#ARGV] =~ /^\d+$/
Truth table0%0/3
A and B
A= @ARGVB= $ARGV[$#ARGV] =~ /^\d+$/
ABresult
0X0
100
111
30  
31 0 my $fh = $self->config->history_file->openr;
32 0 my $search = $self->defaults->{search};
33 0 my $ignore = $self->defaults->{ignore};
34 0 my $lineno = 0;
35 0 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
36 0 $lineno++;
37 0 my ( $date, $command ) = $line =~ /^\[([^\]]+)\]\s+(.*?)\s+$/;
38 0 ▶ next if !$command;
Branch: 1 branch
BranchTrueFalseTotal
unless $command 0 0 0
39 next
40 0 ▶ if $search
Branch: 1 branch
BranchTrueFalseTotal
if $search and not $command =~ /$search/ 0 0 0
Condition0%0/3
$search and not $command =~ /$search/
!ll&&!rl&&r
000
MC/DC0%0/2
$search and not $command =~ /$search/
$search not $command =~ /$search/
Truth table0%0/3
A and not(B)
A= $searchB= not $command =~ /$search/
ABresult
0X0
100
111
41 && $command !~ /$search/;
42 next
43 0 ▶ if $ignore
Branch: 1 branch
BranchTrueFalseTotal
if $ignore and $command =~ /$ignore/ 0 0 0
Condition0%0/3
$ignore and $command =~ /$ignore/
!ll&&!rl&&r
000
MC/DC0%0/2
$ignore and $command =~ /$ignore/
$ignore $command =~ /$ignore/
Truth table0%0/3
A and B
A= $ignoreB= $command =~ /$ignore/
ABresult
0X0
100
111
44 && $command =~ /$ignore/;
45  
46 0 ▶ if ( $lineno == $run_line ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lineno == $run_line) 0 0 0
47 0 exec "vtide $command";
48 }
49 0 ▶ if ( $self->defaults->{uniq} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{'uniq'}) { } 0 0 0
50 0 ▶ if ( defined $uniq{$command} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uniq{$command}) 0 0 0
51 0 my $size = @history;
52  
53 @history = (
54 @history[ 0 .. ( $uniq{$command} - 1 ) ],
55 0 @history[ ( $uniq{$command} + 1 ) .. $#history ]
56 );
57  
58 0 ▶ if ( @history != $size - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@history != $size - 1) 0 0 0
59 0 warn 'No change in history';
60 }
61 }
62 0 $uniq{$command} = scalar @history;
63 0 push @history, [ $date, $lineno, $command ];
64  
65 }
66 else {
67 0 push @history, [ $date, $lineno, $command ];
68 }
69 }
70  
71 0 my $max_line = length "$history[$#history][1]";
72 0 @history = ( ( reverse @history )[ 0 .. $max - 1 ] );
73 0 for my $item ( reverse @history ) {
74 0 ▶ next if !$item || !@$item;
Branch: 1 branch
BranchTrueFalseTotal
unless $item and @$item 0 0 0
Condition0%0/3
$item and @$item
!ll&&!rl&&r
000
MC/DC0%0/2
$item and @$item
$item @$item
Truth table0%0/3
A and B
A= $itemB= @$item
ABresult
0X0
100
111
75 0 printf "%-25s [%${max_line}d] vtide %s\n", @$item;
76 }
77  
78 0 return;
79 }
80  
81 0 ▶sub auto_complete {
Subroutine auto_complete: not called CC=1 SCAR=6.9
Pod documented
82 0 my ($self) = @_;
83 }
84  
85 1 1;
86  
87 __END__
↑ Summary VTide/Command/Start.pm »