| 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
MC/DC0%0/1
$self->defaults->{'number'} || 10
$self->defaults->{'number'}
Truth table0%0/2
A
A= $self->defaults->{'number'}
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my $run_line = @ARGV && $ARGV[$#ARGV] =~ /^\d+$/ ? pop @ARGV : -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@ARGV and $ARGV[$#ARGV] =~ /^\d+$/
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+$/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 36 | 0 | $lineno++; | |||||||||||||||||||||||||||
| 37 | 0 | my ( $date, $command ) = $line =~ /^\[([^\]]+)\]\s+(.*?)\s+$/; | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | next if !$command; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | next | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if $search | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$search and not $command =~ /$search/
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/
| |||||||||||||||||||||||||||||
| 41 | && $command !~ /$search/; | ||||||||||||||||||||||||||||
| 42 | next | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if $ignore | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ignore and $command =~ /$ignore/
MC/DC0%0/2
$ignore and $command =~ /$ignore/
$ignore
$command =~ /$ignore/
Truth table0%0/3
A and B
A= $ignoreB= $command =~ /$ignore/
| |||||||||||||||||||||||||||||
| 44 | && $command =~ /$ignore/; | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( $lineno == $run_line ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | exec "vtide $command"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( $self->defaults->{uniq} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( defined $uniq{$command} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$item and @$item
MC/DC0%0/2
$item and @$item
$item
@$item
Truth table0%0/3
A and B
A= $itemB= @$item
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||