Diff.pm

filter: Statementstmt 96.5% 194 / 201 Branchbran 85.7% 96 / 112 Conditioncond 71.8% 23 / 32 MC/DCmcdc 52.3% 11 / 21 Subroutinesub 94.5% 35 / 37 Podpod 0.0% 0 / 1 totaltotal 88.8% 359 / 404 CC 70 SCAR 27.6
CC
70
Cov
91%
diff
38.8
hunk
8.0
_range
8.0
CRAP 15.9
« Diff/Table.pm ↑ Summary Diff/Config.pm »
1 package Text::Diff;
2  
3 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Carp qw/ croak confess /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Algorithm::Diff ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 our $VERSION = '1.46';
11 6 our @ISA = qw/ Exporter /;
12 6 our @EXPORT = qw/ diff /;
13  
14 ## Hunks are made of ops. An op is the starting index for each
15 ## sequence and the opcode:
16 6 ▶use constant A => 0; # Array index before match/discard
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use constant B => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use constant OPCODE => 2; # "-", " ", "+"
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use constant FLAG => 3; # What to display if not OPCODE "!"
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 6 my %internal_styles = (
22 Unified => undef,
23 Context => undef,
24 OldStyle => undef,
25 Table => undef, ## "internal", but in another module
26 );
27  
28 32 ▶sub diff {
Subroutine diff: called CC=36 SCAR=36.6
Pod undocumented
29 32 my @seqs = ( shift, shift );
30 32 ▶ my $options = shift || {};
Condition100%2/2
shift() || {}
l!l
2012
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
31  
32 32 for my $i ( 0 .. 1 ) {
33 64 my $seq = $seqs[$i];
34 64 my $type = ref $seq;
35  
36 64 ▶ while ( $type eq "CODE" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "CODE") 4 64 68
37 4 $seqs[$i] = $seq = $seq->( $options );
38 4 $type = ref $seq;
39 }
40  
41 64 ▶ my $AorB = !$i ? "A" : "B";
Branch: 1 branch
BranchTrueFalseTotal
!$i ? : 32 32 64
42  
43 64 ▶ if ( $type eq "ARRAY" ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 32 32 64
elsif ($type eq 'SCALAR') { } 24 8 32
elsif (not $type) { } 4 4 8
elsif ($type eq 'GLOB' or UNIVERSAL::isa($seq, 'IO::Handle')) { } 4 0 4
44 ## This is most efficient :)
45 $options->{"OFFSET_$AorB"} = 0
46 32 ▶ unless defined $options->{"OFFSET_$AorB"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$options{"OFFSET_$AorB"} 32 0 32
47 }
48 elsif ( $type eq "SCALAR" ) {
49 24 $seqs[$i] = [split( /^/m, $$seq )];
50 $options->{"OFFSET_$AorB"} = 1
51 24 ▶ unless defined $options->{"OFFSET_$AorB"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$options{"OFFSET_$AorB"} 24 0 24
52 }
53 elsif ( ! $type ) {
54 $options->{"OFFSET_$AorB"} = 1
55 4 ▶ unless defined $options->{"OFFSET_$AorB"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$options{"OFFSET_$AorB"} 4 0 4
56 $options->{"FILENAME_$AorB"} = $seq
57 4 ▶ unless defined $options->{"FILENAME_$AorB"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$options{"FILENAME_$AorB"} 4 0 4
58 $options->{"MTIME_$AorB"} = (stat($seq))[9]
59 4 ▶ unless defined $options->{"MTIME_$AorB"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$options{"MTIME_$AorB"} 4 0 4
60  
61 4 local $/ = "\n";
62 4 ▶ open F, "<$seq" or croak "$!: $seq";
Branch: 1 branch
BranchTrueFalseTotal
open F, "<$seq" or croak("$!: $seq") 4 0 4
63 4 $seqs[$i] = [<F>];
64 4 close F;
65  
66 }
67 ▶ elsif ( $type eq "GLOB" || UNIVERSAL::isa( $seq, "IO::Handle" ) ) {
Condition33%1/3
$type eq "GLOB" or UNIVERSAL::isa($seq, "IO::Handle")
l!l&&r!l&&!r
400
MC/DC0%0/2
$type eq "GLOB" or UNIVERSAL::isa($seq, "IO::Handle")
$type eq "GLOB" UNIVERSAL::isa($seq, "IO::Handle")
Truth table33%1/3
A or B
A= $type eq "GLOB"B= UNIVERSAL::isa($seq, "IO::Handle")
ABresult
1X1
011
000
68 $options->{"OFFSET_$AorB"} = 1
69 4 ▶ unless defined $options->{"OFFSET_$AorB"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$options{"OFFSET_$AorB"} 4 0 4
70 4 local $/ = "\n";
71 4 $seqs[$i] = [<$seq>];
72 }
73 else {
74 0 confess "Can't handle input of type ", ref;
75 }
76 }
77  
78 ## Config vars
79 32 my $output;
80 32 my $output_handler = $options->{OUTPUT};
81 32 my $type = ref $output_handler ;
82 32 ▶ if ( ! defined $output_handler ) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $output_handler) { } 28 4 32
elsif ($type eq 'CODE') { } 1 3 4
elsif ($type eq 'SCALAR') { } 0 3 3
elsif ($type eq 'ARRAY') { } 1 2 3
elsif ($type eq 'GLOB' or UNIVERSAL::isa($output_handler, 'IO::Handle')) { } 2 0 2
83 28 $output = "";
84 28 ▶ $output_handler = sub { $output .= shift };
Subroutine __ANON__: called CC=1 SCAR=0.0
85 }
86 elsif ( $type eq "CODE" ) {
87 ## No problems, mate.
88 }
89 elsif ( $type eq "SCALAR" ) {
90 0 my $out_ref = $output_handler;
91 0 ▶ $output_handler = sub { $$out_ref .= shift };
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 }
93 elsif ( $type eq "ARRAY" ) {
94 1 my $out_ref = $output_handler;
95 1 ▶ $output_handler = sub { push @$out_ref, shift };
Subroutine __ANON__: called CC=1 SCAR=0.0
96 }
97 ▶ elsif ( $type eq "GLOB" || UNIVERSAL::isa $output_handler, "IO::Handle" ) {
Condition66%2/3
$type eq "GLOB" or UNIVERSAL::isa($output_handler, "IO::Handle")
l!l&&r!l&&!r
110
MC/DC0%0/2
$type eq "GLOB" or UNIVERSAL::isa($output_handler, "IO::Handle")
$type eq "GLOB" UNIVERSAL::isa($output_handler, "IO::Handle")
Truth table66%2/3
A or B
A= $type eq "GLOB"B= UNIVERSAL::isa($output_handler, "IO::Handle")
ABresult
1X1
011
000
98 2 my $output_handle = $output_handler;
99 2 ▶ $output_handler = sub { print $output_handle shift };
Subroutine __ANON__: called CC=1 SCAR=0.0
100 }
101 else {
102 0 croak "Unrecognized output type: $type";
103 }
104  
105 32 my $style = $options->{STYLE};
106 32 ▶ $style = "Unified" unless defined $options->{STYLE};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options->{"STYLE"} 19 13 32
107 32 ▶ $style = "Text::Diff::$style" if exists $internal_styles{$style};
Branch: 1 branch
BranchTrueFalseTotal
if exists $internal_styles{$style} 31 1 32
108  
109 32 ▶ if ( ! $style->can( "hunk" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($style->can("hunk")) 2 30 32
110 2 ▶ eval "require $style; 1" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $style; 1" or die $@ 2 0 2
111 }
112  
113 32 ▶ $style = $style->new if ! ref $style && $style->can( "new" );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $style and $style->can("new") 31 1 32
Condition66%2/3
not ref $style and $style->can("new")
!ll&&!rl&&r
0131
MC/DC50%1/2
not ref $style and $style->can("new")
not ref $style $style->can("new")
Truth table66%2/3
not(A) and B
A= not ref $styleB= $style->can("new")
ABresult
0X0
100
111
114  
115 32 my $ctx_lines = $options->{CONTEXT};
116 32 ▶ $ctx_lines = 3 unless defined $ctx_lines;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctx_lines 29 3 32
117 32 ▶ $ctx_lines = 0 if $style->isa( "Text::Diff::OldStyle" );
Branch: 1 branch
BranchTrueFalseTotal
if $style->isa("Text::Diff::OldStyle") 1 31 32
118  
119 my @keygen_args = $options->{KEYGEN_ARGS}
120 32 ▶ ? @{$options->{KEYGEN_ARGS}}
Branch: 1 branch
BranchTrueFalseTotal
$options->{'KEYGEN_ARGS'} ? : 1 31 32
121 : ();
122  
123 ## State vars
124 32 my $diffs = 0; ## Number of discards this hunk
125 32 my $ctx = 0; ## Number of " " (ctx_lines) ops pushed after last diff.
126 32 my @ops; ## ops (" ", +, -) in this hunk
127 32 my $hunks = 0; ## Number of hunks
128  
129 31 ▶ my $emit_ops = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
130 31 ▶ $output_handler->( $style->file_header( @seqs, $options ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $hunks++ 24 7 31
131 unless $hunks++;
132 31 $output_handler->( $style->hunk_header( @seqs, @_, $options ) );
133 31 $output_handler->( $style->hunk ( @seqs, @_, $options ) );
134 31 $output_handler->( $style->hunk_footer( @seqs, @_, $options ) );
135 32 };
136  
137 ## We keep 2*ctx_lines so that if a diff occurs
138 ## at 2*ctx_lines we continue to grow the hunk instead
139 ## of emitting diffs and context as we go. We
140 ## need to know the total length of both of the two
141 ## subsequences so the line count can be printed in the
142 ## header.
143 32 ▶ my $dis_a = sub {push @ops, [@_[0,1],"-"]; ++$diffs ; $ctx = 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
144 32 ▶ my $dis_b = sub {push @ops, [@_[0,1],"+"]; ++$diffs ; $ctx = 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
145  
146 Algorithm::Diff::traverse_sequences(
147 @seqs,
148 {
149 118 ▶ MATCH => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
150 118 push @ops, [@_[0,1]," "];
151  
152 118 ▶ if ( $diffs && ++$ctx > $ctx_lines * 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diffs and ++$ctx > $ctx_lines * 2) 11 107 118
Condition100%3/3
$diffs and ++$ctx > $ctx_lines * 2
!ll&&!rl&&r
911611
MC/DC100%2/2
$diffs and ++$ctx > $ctx_lines * 2
$diffs ++$ctx > $ctx_lines * 2
Truth table100%3/3
A and B
A= $diffsB= ++$ctx > $ctx_lines * 2
ABresult
0X0
100
111
153 11 $emit_ops->( [ splice @ops, 0, $#ops - $ctx_lines ] );
154 11 $ctx = $diffs = 0;
155 }
156  
157 ## throw away context lines that aren't needed any more
158 118 ▶ shift @ops if ! $diffs && @ops > $ctx_lines;
Branch: 1 branch
BranchTrueFalseTotal
if not $diffs and @ops > $ctx_lines 47 71 118
Condition100%3/3
not $diffs and @ops > $ctx_lines
!ll&&!rl&&r
165547
MC/DC100%2/2
not $diffs and @ops > $ctx_lines
not $diffs @ops > $ctx_lines
Truth table100%3/3
not(A) and B
A= not $diffsB= @ops > $ctx_lines
ABresult
0X0
100
111
159 },
160 DISCARD_A => $dis_a,
161 DISCARD_B => $dis_b,
162 },
163 $options->{KEYGEN}, # pass in user arguments for key gen function
164 32 @keygen_args,
165 );
166  
167 32 ▶ if ( $diffs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diffs) 20 12 32
168 20 ▶ $#ops -= $ctx - $ctx_lines if $ctx > $ctx_lines;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx > $ctx_lines 0 20 20
169 20 $emit_ops->( \@ops );
170 }
171  
172 32 ▶ $output_handler->( $style->file_footer( @seqs, $options ) ) if $hunks;
Branch: 1 branch
BranchTrueFalseTotal
if $hunks 24 8 32
173  
174 32 ▶ return defined $output ? $output : $hunks;
Branch: 1 branch
BranchTrueFalseTotal
defined $output ? : 28 4 32
175 }
176  
177 14 ▶sub _header {
Subroutine _header: called CC=5 SCAR=16.6
178 14 my ( $h ) = @_;
179 14 my ( $p1, $fn1, $t1, $p2, $fn2, $t2 ) = @{$h}{
180 14 "FILENAME_PREFIX_A",
181 "FILENAME_A",
182 "MTIME_A",
183 "FILENAME_PREFIX_B",
184 "FILENAME_B",
185 "MTIME_B"
186 };
187  
188 ## remember to change Text::Diff::Table if this logic is tweaked.
189 14 ▶ return "" unless defined $fn1 && defined $fn2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fn1 and defined $fn2 9 5 14
Condition66%2/3
defined $fn1 and defined $fn2
!ll&&!rl&&r
905
MC/DC50%1/2
defined $fn1 and defined $fn2
defined $fn1 defined $fn2
Truth table66%2/3
A and B
A= defined $fn1B= defined $fn2
ABresult
0X0
100
111
190  
191 5 ▶ return join( "",
Branch: 2 branches
BranchTrueFalseTotal
defined $t1 ? : 5 0 5
defined $t2 ? : 5 0 5
192 $p1, " ", $fn1, defined $t1 ? "\t" . localtime $t1 : (), "\n",
193 $p2, " ", $fn2, defined $t2 ? "\t" . localtime $t2 : (), "\n",
194 );
195 }
196  
197 ## _range encapsulates the building of, well, ranges. Turns out there are
198 ## a few nuances.
199 42 ▶sub _range {
Subroutine _range: called CC=8 SCAR=20.8
200 42 my ( $ops, $a_or_b, $format ) = @_;
201  
202 42 my $start = $ops->[ 0]->[$a_or_b];
203 42 my $after = $ops->[-1]->[$a_or_b];
204  
205 ## The sequence indexes in the lines are from *before* the OPCODE is
206 ## executed, so we bump the last index up unless the OP indicates
207 ## it didn't change.
208 42 ▶ ++$after
Branch: 2 branches
BranchTrueFalseTotal
unless $ops->[-1][2] eq ($a_or_b == 0 ? "+" : "-") 23 19 42
$a_or_b == 0 ? : 21 21 42
209 unless $ops->[-1]->[OPCODE] eq ( $a_or_b == A ? "+" : "-" );
210  
211 ## convert from 0..n index to 1..(n+1) line number. The unless modifier
212 ## handles diffs with no context, where only one file is affected. In this
213 ## case $start == $after indicates an empty range, and the $start must
214 ## not be incremented.
215 42 my $empty_range = $start == $after;
216 42 ▶ ++$start unless $empty_range;
Branch: 1 branch
BranchTrueFalseTotal
unless $empty_range 36 6 42
217  
218 return
219 42 ▶ $start == $after
Branch: 3 branches
BranchTrueFalseTotal
$start == $after ? : 18 24 42
$format eq 'unified' && $empty_range ? : 2 16 18
$format eq 'unified' ? : 22 2 24
Condition100%3/3
$format eq "unified" and $empty_range
!ll&&!rl&&r
1242
MC/DC100%2/2
$format eq "unified" and $empty_range
$format eq "unified" $empty_range
Truth table100%3/3
A and B
A= $format eq "unified"B= $empty_range
ABresult
0X0
100
111
220 ? $format eq "unified" && $empty_range
221 ? "$start,0"
222 : $start
223 : $format eq "unified"
224 ? "$start,".($after-$start+1)
225 : "$start,$after";
226 }
227  
228 115 ▶sub _op_to_line {
Subroutine _op_to_line: called CC=7 SCAR=19.6
229 115 my ( $seqs, $op, $a_or_b, $op_prefixes ) = @_;
230  
231 115 my $opcode = $op->[OPCODE];
232 115 ▶ return () unless defined $op_prefixes->{$opcode};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $op_prefixes->{$opcode} 12 103 115
233  
234 103 ▶ my $op_sym = defined $op->[FLAG] ? $op->[FLAG] : $opcode;
Branch: 1 branch
BranchTrueFalseTotal
defined $op->[3] ? : 4 99 103
235 103 $op_sym = $op_prefixes->{$op_sym};
236 103 ▶ return () unless defined $op_sym;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $op_sym 0 103 103
237  
238 103 ▶ $a_or_b = $op->[OPCODE] ne "+" ? 0 : 1 unless defined $a_or_b;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $a_or_b 69 34 103
$op->[2] ne '+' ? : 55 14 69
239 103 my @line = ( $op_sym, $seqs->[$a_or_b][$op->[$a_or_b]] );
240 103 ▶ unless ( $line[1] =~ /(?:\n|\r\n)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line[1] =~ /(?:\n|\r\n)$/) 0 103 103
241 0 $line[1] .= "\n\\ No newline at end of file\n";
242 }
243 103 return @line;
244 }
245  
246 SCOPE: {
247 package Text::Diff::Base;
248  
249 23 ▶ sub new {
Subroutine new: called CC=2 SCAR=8.1
250 23 my $proto = shift;
251 23 ▶ return bless { @_ }, ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0230
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
252 }
253  
254 9 ▶ sub file_header { return "" }
Subroutine file_header: called CC=1 SCAR=0.0
255  
256 8 ▶ sub hunk_header { return "" }
Subroutine hunk_header: called CC=1 SCAR=0.0
257  
258 0 ▶ sub hunk { return "" }
Subroutine hunk: not called CC=1 SCAR=6.9
259  
260 29 ▶ sub hunk_footer { return "" }
Subroutine hunk_footer: called CC=1 SCAR=0.0
261  
262 15 ▶ sub file_footer { return "" }
Subroutine file_footer: called CC=1 SCAR=0.0
263 }
264  
265 6 @Text::Diff::Unified::ISA = qw( Text::Diff::Base );
266  
267 12 ▶sub Text::Diff::Unified::file_header {
Subroutine file_header: called CC=1 SCAR=0.0
268 12 shift; ## No instance data
269 12 my $options = pop ;
270  
271 12 _header(
272 { FILENAME_PREFIX_A => "---", FILENAME_PREFIX_B => "+++", %$options }
273 );
274 }
275  
276 14 ▶sub Text::Diff::Unified::hunk_header {
Subroutine hunk_header: called CC=1 SCAR=0.0
277 14 shift; ## No instance data
278 14 pop; ## Ignore options
279 14 my $ops = pop;
280  
281 14 return join( "",
282 "@@ -",
283 _range( $ops, A, "unified" ),
284 " +",
285 _range( $ops, B, "unified" ),
286 " @@\n",
287 );
288 }
289  
290 14 ▶sub Text::Diff::Unified::hunk {
Subroutine hunk: called CC=1 SCAR=0.0
291 14 shift; ## No instance data
292 14 pop; ## Ignore options
293 14 my $ops = pop;
294  
295 14 my $prefixes = { "+" => "+", " " => " ", "-" => "-" };
296  
297 14 return join "", map _op_to_line( \@_, $_, undef, $prefixes ), @$ops
298 }
299  
300 6 @Text::Diff::Context::ISA = qw( Text::Diff::Base );
301  
302 2 ▶sub Text::Diff::Context::file_header {
Subroutine file_header: called CC=1 SCAR=0.0
303 2 _header { FILENAME_PREFIX_A=>"***", FILENAME_PREFIX_B=>"---", %{$_[-1]} };
304 }
305  
306 4 ▶sub Text::Diff::Context::hunk_header {
Subroutine hunk_header: called CC=1 SCAR=0.0
307 4 return "***************\n";
308 }
309  
310 4 ▶sub Text::Diff::Context::hunk {
Subroutine hunk: called CC=8 SCAR=20.8
311 4 shift; ## No instance data
312 4 pop; ## Ignore options
313 4 my $ops = pop;
314 ## Leave the sequences in @_[0,1]
315  
316 4 my $a_range = _range( $ops, A, "" );
317 4 my $b_range = _range( $ops, B, "" );
318  
319 ## Sigh. Gotta make sure that differences that aren't adds/deletions
320 ## get prefixed with "!", and that the old opcodes are removed.
321 4 my $after;
322 4 ▶ for ( my $start = 0; $start <= $#$ops ; $start = $after ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start <= $ops->$#*) 17 4 21
323 ## Scan until next difference
324 17 $after = $start + 1;
325 17 my $opcode = $ops->[$start]->[OPCODE];
326 17 ▶ next if $opcode eq " ";
Branch: 1 branch
BranchTrueFalseTotal
if $opcode eq " " 11 6 17
327  
328 6 my $bang_it;
329 6 ▶ while ( $after <= $#$ops && $ops->[$after]->[OPCODE] ne " " ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after <= $ops->$#* and $ops->[$after][2] ne " ") 2 6 8
Condition100%3/3
$after <= $ops->$#* and $ops->[$after][2] ne " "
!ll&&!rl&&r
332
MC/DC100%2/2
$after <= $ops->$#* and $ops->[$after][2] ne " "
$after <= $ops->$#* $ops->[$after][2] ne " "
Truth table100%3/3
A and B
A= $after <= $ops->$#*B= $ops->[$after][2] ne " "
ABresult
0X0
100
111
330 2 ▶ $bang_it ||= $ops->[$after]->[OPCODE] ne $opcode;
Condition33%1/3
$bang_it ||= $ops->[$after][2] ne $opcode
l!l&&r!l&&!r
020
MC/DC0%0/2
$bang_it ||= $ops->[$after][2] ne $opcode
$bang_it $ops->[$after][2] ne $opcode
Truth table33%1/3
A ||= B
A= $bang_itB= $ops->[$after][2] ne $opcode
ABresult
1X1
011
000
331 2 ++$after;
332 }
333  
334 6 ▶ if ( $bang_it ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bang_it) 2 4 6
335 2 for my $i ( $start..($after-1) ) {
336 4 $ops->[$i]->[FLAG] = "!";
337 }
338 }
339 }
340  
341 4 my $b_prefixes = { "+" => "+ ", " " => " ", "-" => undef, "!" => "! " };
342 4 my $a_prefixes = { "+" => undef, " " => " ", "-" => "- ", "!" => "! " };
343  
344 4 return join( "",
345 "*** ", $a_range, " ****\n",
346 map( _op_to_line( \@_, $_, A, $a_prefixes ), @$ops ),
347 "--- ", $b_range, " ----\n",
348 map( _op_to_line( \@_, $_, B, $b_prefixes ), @$ops ),
349 );
350 }
351  
352 6 @Text::Diff::OldStyle::ISA = qw( Text::Diff::Base );
353  
354 6 ▶sub _op {
Subroutine _op: called CC=4 SCAR=13.9
355 6 my $ops = shift;
356 6 my $op = $ops->[0]->[OPCODE];
357 6 ▶ $op = "c" if grep $_->[OPCODE] ne $op, @$ops;
Branch: 1 branch
BranchTrueFalseTotal
if grep(($_->[2] ne $op), @$ops) 2 4 6
358 6 ▶ $op = "a" if $op eq "+";
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "+" 2 4 6
359 6 ▶ $op = "d" if $op eq "-";
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "-" 2 4 6
360 6 return $op;
361 }
362  
363 3 ▶sub Text::Diff::OldStyle::hunk_header {
Subroutine hunk_header: called CC=1 SCAR=0.0
364 3 shift; ## No instance data
365 3 pop; ## ignore options
366 3 my $ops = pop;
367  
368 3 my $op = _op $ops;
369  
370 3 return join "", _range( $ops, A, "" ), $op, _range( $ops, B, "" ), "\n";
371 }
372  
373 3 ▶sub Text::Diff::OldStyle::hunk {
Subroutine hunk: called CC=2 SCAR=6.9
374 3 shift; ## No instance data
375 3 pop; ## ignore options
376 3 my $ops = pop;
377 ## Leave the sequences in @_[0,1]
378  
379 3 my $a_prefixes = { "+" => undef, " " => undef, "-" => "< " };
380 3 my $b_prefixes = { "+" => "> ", " " => undef, "-" => undef };
381  
382 3 my $op = _op $ops;
383  
384 3 ▶ return join( "",
Branch: 1 branch
BranchTrueFalseTotal
$op eq 'c' ? : 1 2 3
385 map( _op_to_line( \@_, $_, A, $a_prefixes ), @$ops ),
386 $op eq "c" ? "---\n" : (),
387 map( _op_to_line( \@_, $_, B, $b_prefixes ), @$ops ),
388 );
389 }
390  
391 6 1;
392  
393 __END__
« Diff/Table.pm ↑ Summary Diff/Config.pm »