| 1 | package Text::Diff::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # $Id: Parser.pm 530 2009-09-09 10:26:49Z fil $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use 5.00404; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | $VERSION = '0.1001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | $VERSION = eval $VERSION; # see L<perlmodstyle> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 15 | my( $package, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 15 | my $self = bless { changes=>[], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | source=>'' }, $package; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 | my $parms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 15 | ▶ | if( 1==@args ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | if( 'HASH' eq ref $args[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | $parms = $args[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | my $diff = $args[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | if( ref $diff or $diff !~ /\n/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $diff or not $diff =~ /\n/
MC/DC100%2/2
ref $diff or not $diff =~ /\n/
ref $diff
not $diff =~ /\n/
Truth table100%3/3
A or not(B)
A= ref $diffB= not $diff =~ /\n/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | $parms = { File => $diff }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $parms = { Diff => $diff }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | $parms = { @args }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 15 | $self->__init( $parms ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 15 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | sub __init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__init: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 15 | my( $self, $parms ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 15 | ▶ | $self->{verbose} = 1 if $parms->{Verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 15 | $self->{simplify} = $parms->{Simplify}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 15 | $self->{strip} = $parms->{Strip}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 15 | $self->{trustatat} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | ▶ | $self->{trustatat} = $parms->{TrustAtAt} if exists $parms->{TrustAtAt}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | if( $parms->{ File } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | $self->parse_file( $parms->{File} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | elsif( $parms->{ Diff } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | $self->parse( $parms->{Diff} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 15 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | sub source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
source: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | return $self->{source}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | sub changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 34 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changes: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 34 | my( $self, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 34 | my $ret = $self->{changes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 34 | ▶ | if( $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | $ret = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | foreach my $ch ( @{ $self->{changes} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 172 | ▶ | next unless $ch->filename1 eq $file or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ch->filename1 eq $file or $ch->filename2 eq $file
MC/DC100%2/2
$ch->filename1 eq $file or $ch->filename2 eq $file
$ch->filename1 eq $file
$ch->filename2 eq $file
Truth table100%3/3
A or B
A= $ch->filename1 eq $fileB= $ch->filename2 eq $file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | $ch->filename2 eq $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 84 | push @$ret, $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 34 | ▶ | return @$ret if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | return 0+@$ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | sub files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
files: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my %ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | foreach my $ch ( $self->changes ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 40 | $ret{$ch->filename1} = $ch->filename2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | return %ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | sub simplify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simplify: called CC=14 SCAR=28.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 9 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 9 | my @keep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | my $prev; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 9 | foreach my $ch ( $self->changes ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 421 | ▶ | if( $ch->type eq '' ) { # skip no-change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 215 | undef( $prev ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 215 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 206 | ▶ | if( $prev ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 68 | my $size = $prev->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | ## Combine ADD/REMOVE lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 68 | ▶ | if( $prev->type ne $ch->type and # ADD->REMOVE or REMOVE->ADD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
$prev->type ne $ch->type and $prev->filename1 eq $ch->filename1 and $prev->filename2 eq $ch->filename2 and $size == $ch->size
$prev->type ne $ch->type and $prev->filename1 eq $ch->filename1 and $prev->filename2 eq $ch->filename2
$prev->type ne $ch->type and $prev->filename1 eq $ch->filename1
MC/DC25%1/4
$prev->type ne $ch->type and $prev->filename1 eq $ch->filename1 and $prev->filename2 eq $ch->filename2 and $size == $ch->size
$prev->type ne $ch->type
$prev->filename1 eq $ch->filename1
$prev->filename2 eq $ch->filename2
$size == $ch->size
Truth table40%2/5
A and B and C and D
A= $prev->type ne $ch->typeB= $prev->filename1 eq $ch->filename1C= $prev->filename2 eq $ch->filename2D= $size == $ch->size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $prev->filename1 eq $ch->filename1 and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | $prev->filename2 eq $ch->filename2 and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | $size == $ch->size ) { #close | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 38 | ▶ | if( $prev->type eq 'REMOVE' and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$prev->type eq "REMOVE" and $prev->line2 == $ch->line2 and $prev->line1 + $size == $ch->line1
$prev->type eq "REMOVE" and $prev->line2 == $ch->line2
MC/DC33%1/3
$prev->type eq "REMOVE" and $prev->line2 == $ch->line2 and $prev->line1 + $size == $ch->line1
$prev->type eq "REMOVE"
$prev->line2 == $ch->line2
$prev->line1 + $size == $ch->line1
Truth table50%2/4
A and B and C
A= $prev->type eq "REMOVE"B= $prev->line2 == $ch->line2C= $prev->line1 + $size == $ch->line1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | $prev->line2 == $ch->line2 and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ($prev->line1+$size) == $ch->line1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 36 | $prev->{type} = 'MODIFY'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 36 | $prev->{lines} = $ch->{lines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 36 | undef( $prev ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 36 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ▶ | elsif( $prev->type eq 'ADD' and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$prev->type eq "ADD" and $prev->line2 + $size == $ch->line2 and $prev->line1 == $ch->line1
$prev->type eq "ADD" and $prev->line2 + $size == $ch->line2
MC/DC0%0/3
$prev->type eq "ADD" and $prev->line2 + $size == $ch->line2 and $prev->line1 == $ch->line1
$prev->type eq "ADD"
$prev->line2 + $size == $ch->line2
$prev->line1 == $ch->line1
Truth table25%1/4
A and B and C
A= $prev->type eq "ADD"B= $prev->line2 + $size == $ch->line2C= $prev->line1 == $ch->line1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ($prev->line2+$size) == $ch->line2 and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | $prev->line1 == $ch->line1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | $prev->{type} = 'MODIFY'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | undef( $prev ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # same size, same file, but not at the same spot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 168 | push @keep, $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 168 | $prev = $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | $self->{changes} = \@keep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | sub parse_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_file: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 25 | my( $self, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 25 | local $self->{count1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 25 | local $self->{count2}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 25 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 25 | ▶ | if( ref $file ) { # assume it's a file handle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | $self->{source} = 'user filehandle'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | $fh = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 24 | $self->{source} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 24 | $fh = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 24 | ▶ | $fh->open( $file ) or croak "Unable to open $file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 25 | $self->{changes}=[]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 25 | $self->{state}={ OK=>1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 25 | ▶ | while( <$fh> ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 2330 | $self->{state}{context} = "line $. of $self->{source}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 2330 | $self->_parse_line( $_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 25 | my $ok = $self->{state}{OK}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 25 | delete $self->{state}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 25 | ▶ | $self->simplify if $self->{simplify}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 25 | return $ok; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | my( $self, $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | $self->{source} = "user string"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | $self->{changes}=[]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | $self->{state}={ OK=>1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | local $self->{count1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | local $self->{count2}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | my $l=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | ▶ | while( $text =~ /(.+?\n)/g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 38 | $self->{state}{context} = "line $l of string"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 38 | $self->_parse_line( $1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 38 | $l++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | my $ok = $self->{state}{OK}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | delete $self->{state}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | ▶ | $self->simplify if $self->{simplify}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | return $ok; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | sub _parse_line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 2368 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_line: called CC=16 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 2368 | my( $self, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2368 | ▶ | $self->{verbose} and warn "Parsing $line"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2368 | my $state = $self->{state}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2368 | ▶ | if( $state->{unified} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2123 | $self->_unified_line( $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 2123 | ▶ | return if $state->{unified}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | elsif( $state->{standard} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 24 | $self->_standard_line( $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 24 | ▶ | return if $state->{standard}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 258 | my $file = '(?:-r\d(?:\.\d+)+)|(?:[^-].+)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 258 | ▶ | if( $line =~ /^diff\s+($file)\s+($file)\s*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 6 | my @match = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | ▶ | $self->{verbose} and warn "Diff $1 $2"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | $state->{filename1} = $self->_filename( $match[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | $state->{filename2} = $self->_filename( $match[1] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | elsif( $line =~ /^(\d+)(?:,\d+)?[acd](\d+)(?:,\d+)?$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | $state->{standard} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | push @{ $self->{changes} }, bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | at1 => $1, line1 => $1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | at2 => $2, line2 => $2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | filename1 => $state->{filename1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | filename2 => $state->{filename2}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | timestamp1 => '', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | timestamp2 => '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | }, 'Text::Diff::Parser::Change'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | ▶ | $self->{verbose} and warn "Standard diff line1=$1 line2=$2"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ▶ | elsif( $line =~ /^--- (.+?)\t(.+)$/ or | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$line =~ /^--- (.+?)\t(.+)$/ or $line =~ /^--- ([^\s]+)\s+(.+)$/ or $line =~ /^--- ([^\s]+)$/
$line =~ /^--- (.+?)\t(.+)$/ or $line =~ /^--- ([^\s]+)\s+(.+)$/
MC/DC100%3/3
$line =~ /^--- (.+?)\t(.+)$/ or $line =~ /^--- ([^\s]+)\s+(.+)$/ or $line =~ /^--- ([^\s]+)$/
$line =~ /^--- (.+?)\t(.+)$/
$line =~ /^--- ([^\s]+)\s+(.+)$/
$line =~ /^--- ([^\s]+)$/
Truth table100%4/4
A or B or C
A= $line =~ /^--- (.+?)\t(.+)$/B= $line =~ /^--- ([^\s]+)\s+(.+)$/C= $line =~ /^--- ([^\s]+)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | $line =~ /^--- ([^\s]+)\s+(.+)$/ or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | $line =~ /^--- ([^\s]+)$/ ) { # kernel.org style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 41 | $self->{count1} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 41 | $self->{count2} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 41 | $state->{unified} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 41 | my $stamp = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 41 | my $name = $self->_filename( $1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 41 | ▶ | $self->{verbose} and warn "Unified diff"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 41 | push @{ $self->{changes} }, bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | filename1 => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | timestamp1 => $stamp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | }, 'Text::Diff::Parser::Change'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | ▶ | elsif( $line =~ /^\*\*\* (.+?)\t(.+)$/ or | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$line =~ /^\*\*\* (.+?)\t(.+)$/ or $line =~ /^\*\*\* ([^\s]+)\s+(.+)$/
MC/DC0%0/2
$line =~ /^\*\*\* (.+?)\t(.+)$/ or $line =~ /^\*\*\* ([^\s]+)\s+(.+)$/
$line =~ /^\*\*\* (.+?)\t(.+)$/
$line =~ /^\*\*\* ([^\s]+)\s+(.+)$/
Truth table33%1/3
A or B
A= $line =~ /^\*\*\* (.+?)\t(.+)$/B= $line =~ /^\*\*\* ([^\s]+)\s+(.+)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | $line =~ /^\*\*\* ([^\s]+)\s+(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | die "Context diff not yet supported at $state->{context}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | sub _filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 94 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filename: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 94 | my( $self, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 94 | ▶ | return $file unless $self->{strip}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 24 | my $n = $self->{strip}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 24 | ▶ | $file =~ s(^[^/]+/)() while $n--; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 24 | return $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | sub _standard_line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 24 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_standard_line: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 24 | my( $self, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 24 | my %types = ( ' '=>'', '>'=>'ADD', '<'=>'REMOVE' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 24 | my $change = $self->{changes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 24 | ▶ | if( $line =~ /^([<>])(.+)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 14 | my( $mod, $text ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 14 | $mod = $types{$mod}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 14 | $self->_new_line( $mod, $text ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 10 | ▶ | if( $line =~ /^---$/ ) { # pivot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 4 | ▶ | $self->{verbose} and warn "Pivot"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 6 | delete $self->{state}{standard}; # let _parse_file deal with it | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | #################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | sub _unified_line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2123 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unified_line: called CC=18 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 2123 | my( $self, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 2123 | my %types = ( ' '=>'', '+'=>'ADD', '-'=>'REMOVE' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 2123 | my $change = $self->{changes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 2123 | ▶ | if( $line =~ /^\+\+\+ (.+?)\t(.+)$/ or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$line =~ /^\+\+\+ (.+?)\t(.+)$/ or $line =~ /^\+\+\+ ([^\s]+)\s+(.+)$/ or $line =~ /^\+\+\+ ([^\s]+)$/
$line =~ /^\+\+\+ (.+?)\t(.+)$/ or $line =~ /^\+\+\+ ([^\s]+)\s+(.+)$/
MC/DC100%3/3
$line =~ /^\+\+\+ (.+?)\t(.+)$/ or $line =~ /^\+\+\+ ([^\s]+)\s+(.+)$/ or $line =~ /^\+\+\+ ([^\s]+)$/
$line =~ /^\+\+\+ (.+?)\t(.+)$/
$line =~ /^\+\+\+ ([^\s]+)\s+(.+)$/
$line =~ /^\+\+\+ ([^\s]+)$/
Truth table100%4/4
A or B or C
A= $line =~ /^\+\+\+ (.+?)\t(.+)$/B= $line =~ /^\+\+\+ ([^\s]+)\s+(.+)$/C= $line =~ /^\+\+\+ ([^\s]+)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | $line =~ /^\+\+\+ ([^\s]+)\s+(.+)$/ or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | $line =~ /^\+\+\+ ([^\s]+)$/ ) { # kernel.org style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 41 | ▶ | $change->{timestamp2} = ($2||''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$2 || ''
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 41 | $change->{filename2} = $self->_filename( $1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 41 | $change->{lines} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 41 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2082 | ▶ | die "Missing +++ line before $line" unless $change->{filename2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 2082 | ▶ | if( $line =~ /^\@\@ -(\d+)(?:,(\d+))? [+](\d+)(?:,(\d+))? \@\@\s*(.+)?$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 121 | ▶ | my @match = ($1, ($2||0), $3, ($4||0), ($5||'')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$2 || 0
$4 || 0
$5 || ''
MC/DC100%1/1
$2 || 0
$2
MC/DC100%1/1
$4 || 0
$4
MC/DC100%1/1
$5 || ''
$5
Truth table100%2/2
A
A= $2
Truth table100%2/2
A
A= $4
Truth table100%2/2
A
A= $5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 121 | ▶ | if( @{ $change->{lines} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 80 | $change = $self->_new_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 121 | @{ $change }{ qw( line1 size1 line2 size2 function ) } = @match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 121 | $change->{at1} = $change->{line1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 121 | $change->{at2} = $change->{line2}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 121 | $self->{count1} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 121 | $self->{count2} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 121 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | die "Missing \@\@ line before $line at $self->{state}{context}\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1961 | ▶ | unless defined $change->{line1}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # die "No size1 in ", Dumper $change unless defined $change->{size1}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # die "No size2 in ", Dumper $change unless defined $change->{size2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # warn "$change->{size1} > $self->{count1} $change->{size2} > $self->{count2}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1961 | my $done = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1961 | ▶ | if( $self->{trustatat} and ( $change->{size1} > $self->{count1} or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->{"trustatat"} and $change->{"size1"} > $self->{"count1"} || $change->{"size2"} > $self->{"count2"}
$change->{"size1"} > $self->{"count1"} or $change->{"size2"} > $self->{"count2"}
MC/DC66%2/3
$self->{"trustatat"} and $change->{"size1"} > $self->{"count1"} || $change->{"size2"} > $self->{"count2"}
$self->{"trustatat"}
$change->{"size1"} > $self->{"count1"}
$change->{"size2"} > $self->{"count2"}
Truth table75%3/4
A and B or C
A= $self->{"trustatat"}B= $change->{"size1"} > $self->{"count1"}C= $change->{"size2"} > $self->{"count2"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | $change->{size2} > $self->{count2} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1929 | $done = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1961 | ▶ | if( $done and $line =~ /^---/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$done and $line =~ /^---/
MC/DC100%2/2
$done and $line =~ /^---/
$done
$line =~ /^---/
Truth table100%3/3
A and B
A= $doneB= $line =~ /^---/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 3 | $self->{state}{unified} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1958 | ▶ | if( $line =~ /^([-+ ])(.*)?$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1930 | my( $mod, $text ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1930 | $mod = $types{$mod}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1930 | $self->_new_line( $mod, $text ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 1930 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # Anything else is the end of the diff, so fall through to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # diff detection bit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 28 | $self->{state}{unified} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | sub _new_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 500 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_type: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 500 | my( $self, $mod ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 500 | my $change = $self->{changes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 500 | push @{ $self->{changes} }, bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | filename1 => $change->{filename1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | filename2 => $change->{filename2}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | line1 => $change->{at1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | line2 => $change->{at2}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | size1 => $change->{size1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | size2 => $change->{size2}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | at1 => $change->{at1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | at2 => $change->{at2}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | function => $change->{function}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 500 | type => $mod, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | lines => [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | }, 'Text::Diff::Parser::Change'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 500 | return $self->{changes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | sub _new_chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 80 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_chunk: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 80 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 80 | my $change = $self->{changes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 80 | push @{ $self->{changes} }, bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | type => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | filename1 => $change->{filename1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | filename2 => $change->{filename2}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 80 | lines => [] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | }, 'Text::Diff::Parser::Change'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 80 | return $self->{changes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | sub _new_line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 1944 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_line: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1944 | my( $self, $mod, $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 1944 | ▶ | $self->{count1}++ if $mod ne 'ADD'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1944 | ▶ | $self->{count2}++ if $mod ne 'REMOVE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1944 | ▶ | $self->{verbose} and warn "_new_line"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 1944 | my $change = $self->{changes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 1944 | ▶ | if( defined $change->{type} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1895 | ▶ | if( $change->{type} ne $mod ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 500 | ▶ | $self->{verbose} and warn "_new_type"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 500 | $change = $self->_new_type( $mod ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 49 | $change->{type} = $mod; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1944 | ▶ | $change->{at1}++ unless $mod eq 'ADD'; # - or ' ', advance in file1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1944 | ▶ | $change->{at2}++ unless $mod eq 'REMOVE'; # + or ' ', advance in file2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1944 | push @{ $change->{lines} }, $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | package Text::Diff::Parser::Change; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 440 | ▶ | sub filename1 { $_[0]->{filename1} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filename1: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 405 | ▶ | sub filename2 { $_[0]->{filename2} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filename2: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 168 | ▶ | sub line1 { $_[0]->{line1} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line1: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 168 | ▶ | sub line2 { $_[0]->{line2} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line2: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 79 | ▶ | sub function { $_[0]->{function} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
function: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 228 | ▶ | sub size { 0+@{$_[0]->{lines}} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | sub type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 689 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 689 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | return $self->{type} if $self->{type} eq 'ADD' or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | $self->{type} eq 'REMOVE' or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 689 | ▶ | $self->{type} eq 'MODIFY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->{"type"} eq "ADD" or $self->{"type"} eq "REMOVE" or $self->{"type"} eq "MODIFY"
$self->{"type"} eq "ADD" or $self->{"type"} eq "REMOVE"
MC/DC100%3/3
$self->{"type"} eq "ADD" or $self->{"type"} eq "REMOVE" or $self->{"type"} eq "MODIFY"
$self->{"type"} eq "ADD"
$self->{"type"} eq "REMOVE"
$self->{"type"} eq "MODIFY"
Truth table100%4/4
A or B or C
A= $self->{"type"} eq "ADD"B= $self->{"type"} eq "REMOVE"C= $self->{"type"} eq "MODIFY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 246 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | sub text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 2 | my( $self, $n ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 2 | ▶ | return @{ $self->{lines} } if 1==@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | return $self->{lines}[$n]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||