| 1 | package PDF::Make::Markup::Diff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use File::Temp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use PDF::Make (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use PDF::Make::Builder (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use PDF::Make::Parser (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use PDF::Make::Reader (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.15'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 20 | ▶ | sub pages { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pages: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | my ($class, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 20 | my ($fh, $tmp) = File::Temp::tempfile(SUFFIX => '.pdf', UNLINK => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 20 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 20 | print {$fh} $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 20 | ▶ | close $fh or die "PDF::Make::Markup::Diff: scratch write failed: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 20 | my $parser = PDF::Make::Parser->from_bytes($bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 20 | $parser->parse; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 20 | my $count = PDF::Make::Reader->new($parser)->page_count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Not $b: the sort below wants its own, and a lexical $b in scope | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # shadows the one sort sets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 20 | my $builder = PDF::Make::Builder->new(file_name => 'unsaved'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 20 | my @pages; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 20 | for my $page (0 .. $count - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 20 | = eval { $builder->extract_structured($tmp, page => $page) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 20 | my @words; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 20 | ▶ | if ($result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | for my $block ($result->blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 22 | for my $line ($block->lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 47 | for my $word ($line->words) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # x1 and size are working state for the glue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # below and are dropped before this is returned; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # x and y stay rounded to the point, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # sub-point noise cannot flag a page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 534 | push @words, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | text => $word->text, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | x => int($word->x0 + 0.5), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | y => int($word->y0 + 0.5), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | x0 => $word->x0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | x1 => $word->x1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | size => $word->font_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | push @pages, _coalesce([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 20 | ▶ | sort { $b->{y} <=> $a->{y} || $a->{x} <=> $b->{x} } @words | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$PDF::Make::Markup::Diff::b->{'y'} <=> $PDF::Make::Markup::Diff::a->{'y'} || $PDF::Make::Markup::Diff::a->{'x'} <=> $PDF::Make::Markup::Diff::b->{'x'}
MC/DC0%0/2
$PDF::Make::Markup::Diff::b->{'y'} <=> $PDF::Make::Markup::Diff::a->{'y'} || $PDF::Make::Markup::Diff::a->{'x'} <=> $PDF::Make::Markup::Diff::b->{'x'}
$PDF::Make::Markup::Diff::b->{'y'} <=> $PDF::Make::Markup::Diff::a->{'y'}
$PDF::Make::Markup::Diff::a->{'x'} <=> $PDF::Make::Markup::Diff::b->{'x'}
Truth table66%2/3
A || B
A= $PDF::Make::Markup::Diff::b->{'y'} <=> $PDF::Make::Markup::Diff::a->{'y'}B= $PDF::Make::Markup::Diff::a->{'x'} <=> $PDF::Make::Markup::Diff::b->{'x'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 20 | unlink $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 20 | return \@pages; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | my $JOIN_EM = 0.15; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 20 | ▶ | sub _coalesce { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coalesce: called CC=10 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 20 | my ($words) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 20 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 20 | for my $w (@$words) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 534 | ▶ | my $prev = @out ? $out[-1] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 534 | ▶ | if ($prev && $prev->{y} == $w->{y}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev and $prev->{"y"} == $w->{"y"}
MC/DC100%2/2
$prev and $prev->{"y"} == $w->{"y"}
$prev
$prev->{"y"} == $w->{"y"}
Truth table100%3/3
A and B
A= $prevB= $prev->{"y"} == $w->{"y"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # The gap is measured unrounded: x and y are rounded to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # point for comparison, and a half-point of rounding either | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # way is a large fraction of the threshold. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 487 | ▶ | my $em = $w->{size} || $prev->{size} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$w->{'size'} || $prev->{'size'} || 0
$w->{"size"} or $prev->{"size"}
MC/DC0%0/2
$w->{'size'} || $prev->{'size'} || 0
$w->{"size"}
$prev->{"size"}
Truth table33%1/3
A or B
A= $w->{"size"}B= $prev->{"size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 487 | my $gap = $w->{x0} - $prev->{x1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 487 | ▶ | if ($gap <= $em * $JOIN_EM) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $prev->{text} .= $w->{text}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $prev->{x1} = $w->{x1} > $prev->{x1} ? $w->{x1} : $prev->{x1}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 534 | push @out, { %$w }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 20 | delete @{$_}{qw(x0 x1 size)} for @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 20 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # diff($bytes_a, $bytes_b): { pages_a, pages_b, changed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # pages => [ { page, changed, removed => [...], added => [...], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # moved => [...] } ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 9 | ▶ | sub diff { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diff: called CC=10 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 9 | my ($class, $bytes_a, $bytes_b) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 9 | my $a = $class->pages($bytes_a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 9 | my $b = $class->pages($bytes_b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 9 | ▶ | my $n = @$a > @$b ? @$a : @$b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 9 | my @pages; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 9 | for my $i (0 .. $n - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 9 | ▶ | my $wa = $a->[$i] || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a->[$i] || []
MC/DC0%0/1
$a->[$i] || []
$a->[$i]
Truth table50%1/2
A
A= $a->[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 9 | ▶ | my $wb = $b->[$i] || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$b->[$i] || []
MC/DC0%0/1
$b->[$i] || []
$b->[$i]
Truth table50%1/2
A
A= $b->[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 9 | my ($removed, $added, $moved) = _compare($wa, $wb); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 9 | ▶ | push @pages, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%9/12
@$removed or @$added or @$moved or $i >= @$a or $i >= @$b
@$removed or @$added or @$moved or $i >= @$a
@$removed or @$added or @$moved
@$removed or @$added
MC/DC40%2/5
@$removed or @$added or @$moved or $i >= @$a or $i >= @$b
@$removed
@$added
@$moved
$i >= @$a
$i >= @$b
Truth table50%3/6
A or B or C or D or E
A= @$removedB= @$addedC= @$movedD= $i >= @$aE= $i >= @$b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | page => $i + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | changed => (@$removed || @$added || @$moved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | || $i >= @$a || $i >= @$b) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | removed => $removed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | added => $added, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | moved => $moved, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | pages_a => scalar @$a, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | pages_b => scalar @$b, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 9 | changed => scalar(grep { $_->{changed} } @pages), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | pages => \@pages, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | my $CAP = 40; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 9 | ▶ | sub _compare { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compare: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | my ($wa, $wb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 9 | my @ta = map { $_->{text} } @$wa; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 9 | my @tb = map { $_->{text} } @$wb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | my $pairs = _align(\@ta, \@tb); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | my (%kept_a, %kept_b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | my @moved; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 9 | for my $p (@$pairs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 42 | my ($i, $j) = @$p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 42 | $kept_a{$i} = $kept_b{$j} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | push @moved, $wa->[$i]{text} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 42 | ▶ | if $wa->[$i]{x} != $wb->[$j]{x} || $wa->[$i]{y} != $wb->[$j]{y}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$wa->[$i]{"x"} != $wb->[$j]{"x"} or $wa->[$i]{"y"} != $wb->[$j]{"y"}
MC/DC50%1/2
$wa->[$i]{"x"} != $wb->[$j]{"x"} or $wa->[$i]{"y"} != $wb->[$j]{"y"}
$wa->[$i]{"x"} != $wb->[$j]{"x"}
$wa->[$i]{"y"} != $wb->[$j]{"y"}
Truth table66%2/3
A or B
A= $wa->[$i]{"x"} != $wb->[$j]{"x"}B= $wa->[$i]{"y"} != $wb->[$j]{"y"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | my @removed = map { $ta[$_] } grep { !$kept_a{$_} } 0 .. $#ta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | my @added = map { $tb[$_] } grep { !$kept_b{$_} } 0 .. $#tb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Movement is only news when nothing was written or deleted: edit a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # word and everything after it on the line shifts, and reporting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # that is how the report became unreadable in the first place. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # page is still flagged as changed either way - by the text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 9 | ▶ | @moved = () if @removed || @added; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@removed or @added
MC/DC50%1/2
@removed or @added
@removed
@added
Truth table66%2/3
A or B
A= @removedB= @added
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | splice @$_, $CAP for grep { @$_ > $CAP } \@removed, \@added, \@moved; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 9 | return (\@removed, \@added, \@moved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | my $LCS_MAX = 400; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 9 | ▶ | sub _align { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_align: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 9 | my ($ta, $tb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 9 | my ($na, $nb) = (scalar @$ta, scalar @$tb); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 9 | my $head = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 9 | ▶ | $head++ while $head < $na && $head < $nb | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$head < $na and $head < $nb and $ta->[$head] eq $tb->[$head]
$head < $na and $head < $nb
MC/DC66%2/3
$head < $na and $head < $nb and $ta->[$head] eq $tb->[$head]
$head < $na
$head < $nb
$ta->[$head] eq $tb->[$head]
Truth table75%3/4
A and B and C
A= $head < $naB= $head < $nbC= $ta->[$head] eq $tb->[$head]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | && $ta->[$head] eq $tb->[$head]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 9 | my $tail = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 9 | ▶ | $tail++ while $tail < $na - $head && $tail < $nb - $head | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$tail < $na - $head and $tail < $nb - $head and $$ta[$na - 1 - $tail] eq $$tb[$nb - 1 - $tail]
$tail < $na - $head and $tail < $nb - $head
MC/DC100%3/3
$tail < $na - $head and $tail < $nb - $head and $$ta[$na - 1 - $tail] eq $$tb[$nb - 1 - $tail]
$tail < $na - $head
$tail < $nb - $head
$$ta[$na - 1 - $tail] eq $$tb[$nb - 1 - $tail]
Truth table100%4/4
A and B and C
A= $tail < $na - $headB= $tail < $nb - $headC= $$ta[$na - 1 - $tail] eq $$tb[$nb - 1 - $tail]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | && $ta->[$na - 1 - $tail] eq $tb->[$nb - 1 - $tail]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 9 | my @pairs = map { [ $_, $_ ] } 0 .. $head - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 9 | push @pairs, [ $na - 1 - $_, $nb - 1 - $_ ] for reverse 0 .. $tail - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 9 | my ($ma, $mb) = ($na - $head - $tail, $nb - $head - $tail); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 9 | ▶ | return [ sort { $a->[0] <=> $b->[0] } @pairs ] if !$ma || !$mb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ma and $mb
MC/DC100%2/2
$ma and $mb
$ma
$mb
Truth table100%3/3
A and B
A= $maB= $mb
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 6 | ▶ | my @middle = ($ma > $LCS_MAX || $mb > $LCS_MAX) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ma > $LCS_MAX or $mb > $LCS_MAX
MC/DC0%0/2
$ma > $LCS_MAX or $mb > $LCS_MAX
$ma > $LCS_MAX
$mb > $LCS_MAX
Truth table33%1/3
A or B
A= $ma > $LCS_MAXB= $mb > $LCS_MAX
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ? _greedy_middle($ta, $tb, $head, $ma, $mb) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | : _lcs_middle($ta, $tb, $head, $ma, $mb); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 6 | return [ sort { $a->[0] <=> $b->[0] } @pairs, @middle ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 6 | ▶ | sub _lcs_middle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lcs_middle: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | my ($ta, $tb, $head, $ma, $mb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Row-at-a-time table, walked back through the stored rows. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 6 | my @rows = ([ (0) x ($mb + 1) ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 6 | for my $i (1 .. $ma) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 215 | my $prev = $rows[$i - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 215 | my @row = (0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 215 | for my $j (1 .. $mb) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 40062 | ▶ | $row[$j] = $ta->[$head + $i - 1] eq $tb->[$head + $j - 1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ? $prev->[$j - 1] + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | : ($prev->[$j] >= $row[$j - 1] ? $prev->[$j] : $row[$j - 1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 215 | push @rows, \@row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 6 | my @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 6 | my ($i, $j) = ($ma, $mb); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 6 | ▶ | while ($i > 0 && $j > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i > 0 and $j > 0
MC/DC50%1/2
$i > 0 and $j > 0
$i > 0
$j > 0
Truth table66%2/3
A and B
A= $i > 0B= $j > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 216 | ▶ | if ($ta->[$head + $i - 1] eq $tb->[$head + $j - 1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | unshift @pairs, [ $head + $i - 1, $head + $j - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | $i--; $j--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 213 | elsif ($rows[$i - 1][$j] >= $rows[$i][$j - 1]) { $i-- } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | else { $j-- } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | return @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub _greedy_middle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_greedy_middle: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ($ta, $tb, $head, $ma, $mb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my %next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | push @{ $next{ $tb->[$head + $_] } }, $head + $_ for 0 .. $mb - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $floor = $head - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | for my $i (0 .. $ma - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | my $list = $next{ $ta->[$head + $i] } or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | shift @$list while @$list && $list->[0] <= $floor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$list and $list->[0] <= $floor
MC/DC0%0/2
@$list and $list->[0] <= $floor
@$list
$list->[0] <= $floor
Truth table0%0/3
A and B
A= @$listB= $list->[0] <= $floor
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | next unless @$list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $j = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $floor = $j; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | push @pairs, [ $head + $i, $j ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||