| 1 | package App::NDTools::NDDiff; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use parent 'App::NDTools::NDTool'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Algorithm::Diff qw(compact_diff); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use JSON qw(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use App::NDTools::Slurp qw(s_dump); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Log::Log4Cli 0.18; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Struct::Diff 0.96 qw(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Struct::Path 0.80 qw(path path_delta); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Struct::Path::PerlStyle 0.80 qw(str2path path2str); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Term::ANSIColor qw(color); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | our $VERSION = '0.46'; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | my $JSON = JSON->new->canonical->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | my %COLOR; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub arg_opts { | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 66 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arg_opts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | $self->SUPER::arg_opts(), | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'A!' => \$self->{OPTS}->{diff}->{A}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 'N!' => \$self->{OPTS}->{diff}->{N}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 'O!' => \$self->{OPTS}->{diff}->{O}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'R!' => \$self->{OPTS}->{diff}->{R}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'U!' => \$self->{OPTS}->{diff}->{U}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | 'brief' => sub { $self->{OPTS}->{ofmt} = $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'colors!' => \$self->{OPTS}->{colors}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'ctx-text=i' => \$self->{OPTS}->{'ctx-text'}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'full' => \$self->{OPTS}->{full}, # deprecated | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'full-headers' => \$self->{OPTS}->{'full-headers'}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'grep=s@' => \$self->{OPTS}->{grep}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | 'json' => sub { $self->{OPTS}->{ofmt} = $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'ignore=s@' => \$self->{OPTS}->{ignore}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | 'rules' => sub { $self->{OPTS}->{ofmt} = $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'quiet|q' => \$self->{OPTS}->{quiet}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 'show' => \$self->{OPTS}->{show}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 66 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | sub check_args { | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 66 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_args: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 66 | ▶ | if ($self->{OPTS}->{show}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | die_fatal "At least one argument expected when --show used", 1 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | unless (@_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } elsif (@_ < 2) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | die_fatal "At least two arguments expected for diff", 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 65 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | sub configure { | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 66 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 66 | $self->SUPER::configure(); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | $self->{OPTS}->{colors} = $self->{TTY} | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 65 | ▶ | unless (defined $self->{OPTS}->{colors}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # resolve colors | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 65 | ▶ | while (my ($k, $v) = each %{$self->{OPTS}->{term}->{line}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 455 | ▶ | if ($self->{OPTS}->{colors}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 21 | $COLOR{$k} = color($v); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 21 | $COLOR{"B$k"} = color("bold $v"); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 434 | $COLOR{$k} = $COLOR{"B$k"} = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $COLOR{head} = $self->{OPTS}->{colors} | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 65 | ▶ | ? color($self->{OPTS}->{term}->{head}) : ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 65 | ▶ | $COLOR{reset} = $self->{OPTS}->{colors} ? color('reset') : ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # resolve paths | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 65 | for (@{$self->{OPTS}->{grep}}, @{$self->{OPTS}->{ignore}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | my $tmp = eval { str2path($_) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | ▶ | die_fatal "Failed to parse '$_'", 4 if ($@); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | $_ = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 64 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | sub defaults { | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 66 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | my $out = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 66 | %{$self->SUPER::defaults()}, | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 'ctx-text' => 3, | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 'term' => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 'head' => 'yellow', | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 'line' => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 'A' => 'green', | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 'D' => 'yellow', | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 'U' => 'white', | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 'R' => 'red', | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | '@' => 'magenta', | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 'sign' => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 'A' => '+ ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 'D' => '! ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 'U' => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 'R' => '- ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | '@' => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 'ofmt' => 'term', | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 'diff' => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 'A' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 'N' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 'O' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 'R' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 'U' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 66 | $out->{term}{line}{N} = $out->{term}{line}{A}; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 66 | $out->{term}{line}{O} = $out->{term}{line}{R}; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 66 | $out->{term}{sign}{N} = $out->{term}{sign}{A}; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 66 | $out->{term}{sign}{O} = $out->{term}{sign}{R}; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 66 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | sub diff { | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 59 | ▶ | my ($self, $old, $new) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diff: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 59 | ▶ | if ($self->{OPTS}->{full}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | log_alert { | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | '--full opt is deprecated and will be removed soon. ' . | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | '--U should be used instead' | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | map {$self->{OPTS}->{diff}->{$_} = 1 } keys %{$self->{OPTS}->{diff}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 59 | ▶ | log_debug { "Calculating diff for structure" }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | my $diff = Struct::Diff::diff( | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | $old, $new, | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 64 | map { ("no$_" => 1) } grep { !$self->{OPTS}->{diff}->{$_} } | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 59 | keys %{$self->{OPTS}->{diff}}, | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # retrieve result from wrapper (see load() for more info) | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 59 | ▶ | if (exists $diff->{D}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 54 | $diff = $diff->{D}->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } elsif (exists $diff->{U}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | $diff->{U} = $diff->{U}->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 59 | ▶ | $self->diff_term($diff) if ($self->{OPTS}->{ofmt} eq 'term'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 59 | return $diff; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | sub diff_term { | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 45 | ▶ | my ($self, $diff) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diff_term: called CC=21 SCAR=30.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 45 | ▶ | log_debug { "Calculating diffs for text values" }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 45 | my $dref; # ref to diff | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 45 | my @list = Struct::Diff::list_diff($diff); | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 45 | ▶ | while (@list) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 72 | (undef, $dref) = splice @list, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 72 | ▶ | next unless (exists ${$dref}->{N}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 47 | ▶ | next if (ref ${$dref}->{O} or ref ${$dref}->{N}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref ${$dref;}->{"O"} or ref ${$dref;}->{"N"}
MC/DC50%1/2
ref ${$dref;}->{"O"} or ref ${$dref;}->{"N"}
ref ${$dref;}->{"O"}
ref ${$dref;}->{"N"}
Truth table66%2/3
A or B
A= ref ${$dref;}->{"O"}B= ref ${$dref;}->{"N"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 42 | ▶ | my @old = split($/, ${$dref}->{O}, -1) if (${$dref}->{O}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 42 | ▶ | my @new = split($/, ${$dref}->{N}, -1) if (${$dref}->{N}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 42 | ▶ | if (@old > 1 or @new > 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@old > 1 or @new > 1
MC/DC100%2/2
@old > 1 or @new > 1
@old > 1
@new > 1
Truth table100%3/3
A or B
A= @old > 1B= @new > 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 23 | delete ${$dref}->{O}; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 23 | delete ${$dref}->{N}; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 23 | ▶ | if ($old[-1] eq '' and $new[-1] eq '') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$old[-1] eq "" and $new[-1] eq ""
MC/DC100%2/2
$old[-1] eq "" and $new[-1] eq ""
$old[-1] eq ""
$new[-1] eq ""
Truth table100%3/3
A and B
A= $old[-1] eq ""B= $new[-1] eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 13 | pop @old; # because split by newline and -1 for LIMIT | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 13 | pop @new; # -"- | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 23 | my @cdiff = compact_diff(\@old, \@new); | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 23 | my ($match, $header); | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 23 | ▶ | while (@cdiff > 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 104 | my @del = @old[$cdiff[0] .. $cdiff[2] - 1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 104 | my @add = @new[$cdiff[1] .. $cdiff[3] - 1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 104 | ▶ | if ($match = !$match) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # trailing context | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 56 | ▶ | if ($header) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 33 | my @tail = splice @del, 0, $self->{OPTS}->{'ctx-text'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 33 | push @{${$dref}->{T}}, 'U', \@tail; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 33 | $header->[1] += @tail; | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 33 | $header->[3] += @tail; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # leading context | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 56 | ▶ | if (@cdiff > 4) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | my @rest = splice @del, 0, $self->{OPTS}->{'ctx-text'} | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 48 | ▶ | ? $self->{OPTS}->{'ctx-text'} * -1 : scalar @del; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 48 | ▶ | if (@rest or !$header) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@rest or not $header
MC/DC100%2/2
@rest or not $header
@rest
not $header
Truth table100%3/3
A or not(B)
A= @restB= not $header
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 30 | push @{${$dref}->{T}}, '@', $header = [ | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | $cdiff[2] - @del + 1, 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | $cdiff[3] - @del + 1, 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 48 | ▶ | if (@del) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 17 | push @{${$dref}->{T}}, 'U', \@del; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 17 | $header->[1] += @del; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 17 | $header->[3] += @del; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 48 | ▶ | if (@del) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 40 | push @{${$dref}->{T}}, 'R', \@del; | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | 40 | $header->[1] += @del; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 48 | ▶ | if (@add) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 40 | push @{${$dref}->{T}}, 'A', \@add; | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | 40 | $header->[3] += @add; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 104 | splice @cdiff, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 45 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | sub dump { | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 57 | ▶ | my ($self, $diff) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 57 | ▶ | log_debug { "Dumping results" }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 57 | ▶ | if ($self->{OPTS}->{ofmt} eq 'term') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 42 | $self->dump_term($diff); | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | } elsif ($self->{OPTS}->{ofmt} eq 'brief') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | $self->dump_brief($diff); | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | } elsif ($self->{OPTS}->{ofmt} eq 'rules') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | $self->dump_rules($diff); | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | s_dump(\*STDOUT, $self->{OPTS}->{ofmt}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 10 | {pretty => $self->{OPTS}->{pretty}}, $diff); | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 55 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | sub dump_brief { | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | ▶ | my ($self, $diff) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_brief: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | my ($path, $dref, $tag); | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | 4 | my @list = Struct::Diff::list_diff($diff, sort => 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | ▶ | while (@list) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 10 | ($path, $dref) = splice @list, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | 10 | for $tag (qw{R N A}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | $self->print_brief_block($path, $tag) | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 30 | ▶ | if (exists ${$dref}->{$tag}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | sub dump_rules { | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | ▶ | my ($self, $diff) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_rules: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | my ($path, $dref, $item, @out); | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | my @list = Struct::Diff::list_diff($diff, sort => 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | while (@list) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | ($path, $dref) = splice @list, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | for (qw{R N A}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 12 | ▶ | next unless (exists ${$dref}->{$_}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | unshift @out, { | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | modname => $_ eq "R" ? "Remove" : "Insert", | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | path => $self->dump_rules_path($path), | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | ▶ | value => ${$dref}->{$_} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | s_dump(\*STDOUT, 'JSON', {pretty => $self->{OPTS}->{pretty}}, \@out); | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | sub dump_rules_path { # to be able to override | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | ▶ | return path2str($_[1]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_rules_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | sub dump_term { | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 42 | ▶ | my ($self, $diff) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_term: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 42 | my ($path, $dref, $tag); | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | 42 | my @list = Struct::Diff::list_diff($diff, sort => 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 42 | ▶ | while (@list) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 69 | ($path, $dref) = splice @list, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 69 | for $tag (qw{R O N A T}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 89 | $self->print_term_block(${$dref}->{$tag}, $path, $tag) | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | 345 | ▶ | if (exists ${$dref}->{$tag}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | sub exec { | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 59 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exec: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 59 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 59 | ▶ | while (@{$self->{ARGV}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 115 | my $name = shift @{$self->{ARGV}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | 115 | my $data = $self->load($name); | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 115 | my $diff; | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 115 | ▶ | if ($self->{OPTS}->{show}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 3 | $self->print_term_header($name); | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | 3 | $diff = $data->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | ▶ | if (my @errs = Struct::Diff::valid_diff($diff)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | ▶ | while (@errs) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | my ($path, $type) = splice @errs, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | log_error { "$name: $type " . path2str($path) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | die_fatal "Diff validation failed", 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 112 | push @items, { name => $name, data => $data }; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 112 | ▶ | next unless (@items > 1); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 56 | $self->print_term_header($items[0]->{name}, $items[1]->{name}); | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 56 | $diff = $self->diff($items[0]->{data}, $items[1]->{data}); | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 56 | shift @items; | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 58 | ▶ | $self->dump($diff) unless ($self->{OPTS}->{quiet}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 56 | ▶ | $self->{status} = 8 unless (not keys %{$diff} or exists $diff->{U}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not keys %{$diff;} or exists $diff->{"U"}
MC/DC100%2/2
not keys %{$diff;} or exists $diff->{"U"}
not keys %{$diff;}
exists $diff->{"U"}
Truth table100%3/3
not(A) or B
A= not keys %{$diff;}B= exists $diff->{"U"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 56 | ▶ | die_info "All done, no difference found", 0 unless ($self->{status}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 52 | die_info "Difference found", 8; | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 121 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 121 | my @data = $self->load_struct($_[0], $self->{OPTS}->{ifmt}); | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # array used to indicate absent value for grep result | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | @data = $self->grep($self->{OPTS}->{grep}, $data[0]) | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 121 | ▶ | if (@{$self->{OPTS}->{grep}}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 121 | ▶ | if (@data and ref $data[0]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@data and ref $data[0]
MC/DC100%2/2
@data and ref $data[0]
@data
ref $data[0]
Truth table100%3/3
A and B
A= @dataB= ref $data[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 104 | map { path($data[0], $_, delete => 1) } @{$self->{OPTS}->{ignore}} | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 121 | return \@data; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | sub print_brief_block { | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 10 | ▶ | my ($self, $path, $status) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_brief_block: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 10 | ▶ | $status = 'D' if ($status eq 'N'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | my $line = $self->{OPTS}->{term}->{sign}->{$status} . | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 10 | $COLOR{U} . path2str([splice @{$path}, 0, -1]) . $COLOR{reset}; | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | 10 | $line .= $COLOR{"B$status"} . path2str($path) . $COLOR{reset}; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 10 | print $line . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | sub print_term_block { | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 89 | ▶ | my ($self, $value, $path, $status) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_term_block: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 89 | ▶ | log_trace { "'" . path2str($path) . "' ($status)" }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 89 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | 89 | my $dsign = $self->{OPTS}->{term}->{sign}->{$status}; | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # diff for path | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 89 | ▶ | if (@{$path} and my @delta = path_delta($self->{'hdr_path'}, $path)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$path;} and my(@delta) = &path_delta($self->{"hdr_path"}, $path)
MC/DC100%2/2
@{$path;} and my(@delta) = &path_delta($self->{"hdr_path"}, $path)
@{$path;}
my(@delta) = &path_delta($self->{"hdr_path"}, $path)
Truth table100%3/3
A and B
A= @{$path;}B= my(@delta) = &path_delta($self->{"hdr_path"}, $path)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 62 | $self->{'hdr_path'} = [@{$path}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | 62 | ▶ | for (my $s = 0; $s < @{$path}; $s++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 110 | ▶ | next if (not $self->{OPTS}->{'full-headers'} and $s < @{$path} - @delta); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->{"OPTS"}{"full-headers"} and $s < @{$path;} - @delta
MC/DC100%2/2
not $self->{"OPTS"}{"full-headers"} and $s < @{$path;} - @delta
not $self->{"OPTS"}{"full-headers"}
$s < @{$path;} - @delta
Truth table100%3/3
not(A) and B
A= not $self->{"OPTS"}{"full-headers"}B= $s < @{$path;} - @delta
| |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 103 | my $line = " " x $s . path2str([$path->[$s]]); | |||||||||||||||||||||||||||||||||||||||||||||
| 401 | 103 | ▶ | if (($status eq 'A' or $status eq 'R') and $s == $#{$path}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$status eq "A" || $status eq "R" and $s == $#{$path;}
$status eq "A" or $status eq "R"
MC/DC100%3/3
$status eq "A" || $status eq "R" and $s == $#{$path;}
$status eq "A"
$status eq "R"
$s == $#{$path;}
Truth table100%5/5
A or B and C
A= $status eq "A"B= $status eq "R"C= $s == $#{$path;}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 17 | $line = $COLOR{"B$status"} . $dsign . $line . $COLOR{reset}; | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 86 | $line = " $line"; | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 103 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # diff for value | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 89 | push @lines, $self->term_value_diff($value, $status, " " x @{$path}); | |||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 89 | print join("\n", @lines) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | sub print_term_header { | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 64 | ▶ | my ($self, @names) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_term_header: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 64 | ▶ | if ($self->{TTY} and not $self->{OPTS}->{quiet}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"TTY"} and not $self->{"OPTS"}{"quiet"}
MC/DC100%2/2
$self->{"TTY"} and not $self->{"OPTS"}{"quiet"}
$self->{"TTY"}
not $self->{"OPTS"}{"quiet"}
Truth table100%3/3
A and not(B)
A= $self->{"TTY"}B= not $self->{"OPTS"}{"quiet"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | print $COLOR{head} . | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | (@names == 1 ? "!!! $names[0]" : "--- $names[0]\n+++ $names[1]") . | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 3 | ▶ | $COLOR{reset}. "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | sub term_value_diff { | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 89 | ▶ | my ($self, $value, $status, $indent) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
term_value_diff: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 89 | ▶ | return $self->term_value_diff_text($value, $indent) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | if ($status eq 'T'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 68 | return $self->term_value_diff_default($value, $status, $indent); | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | sub term_value_diff_default { | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 68 | ▶ | my ($self, $value, $status, $indent) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
term_value_diff_default: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 68 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 68 | ▶ | $value = $JSON->pretty($self->{OPTS}->{pretty})->encode($value) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $value or not defined $value
MC/DC50%1/2
ref $value or not defined $value
ref $value
not defined $value
Truth table66%2/3
A or not(B)
A= ref $valueB= not defined $value
| |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | if (ref $value or not defined $value); | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 68 | for my $line (split($/, $value)) { | |||||||||||||||||||||||||||||||||||||||||||||
| 444 | 82 | substr($line, 0, 0, $self->{OPTS}->{term}->{sign}->{$status} . $indent); | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 82 | push @out, $COLOR{$status} . $line . $COLOR{reset}; | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 68 | return @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | sub term_value_diff_text { | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 21 | ▶ | my ($self, $diff, $indent) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
term_value_diff_text: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 21 | my (@hdr, $lines, @out, $pfx, $sfx, $status); | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 21 | $sfx = $COLOR{reset}; | |||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 21 | ▶ | while (@{$diff}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 154 | ($status, $lines) = splice @{$diff}, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 154 | $pfx = $COLOR{$status} . $self->{OPTS}->{term}->{sign}->{$status} . | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | $indent; | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 154 | ▶ | if ($status eq '@') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 28 | @hdr = splice @{$lines}; | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | 28 | ▶ | $lines->[0] = "@@ -$hdr[0]" . ($hdr[1] > 1 ? ",$hdr[1] " : "") . | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | " +$hdr[2]" . ($hdr[3] > 1 ? ",$hdr[3] @@" : " @@"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 154 | map { substr($_ , 0, 0, $pfx); $_ .= $sfx; push @out, $_ } @{$lines}; | |||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 21 | return @out; | |||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | 1; # End of App::NDTools::NDDiff | |||||||||||||||||||||||||||||||||||||||||||||