blib/lib/Vcdiff/Xdelta3.pm

filter: Statementstmt 91.8% 56 / 61 Branchbran 70.4% 31 / 44 Conditioncond 33.3% 6 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 69.2% 99 / 143 CC 29 SCAR 27.4
CC
29
Cov
76%
diff
18.3
patch
18.3
_check_ret
3.1
CRAP 15.4
↑ Summary Interface.xs »
1 package Vcdiff::Xdelta3;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Vcdiff;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.104';
10  
11 2 require XSLoader;
12 2 XSLoader::load('Vcdiff::Xdelta3', $VERSION);
13  
14  
15  
16 65 ▶sub diff {
Subroutine diff: called CC=14 SCAR=29.1
Pod undocumented
17 65 my ($source, $input, $output) = @_;
18  
19 65 my ($source_fileno, $source_str, $input_fileno, $input_str, $output_fileno, $output_str);
20  
21 65 $source_fileno = $input_fileno = $output_fileno = -1;
22  
23 65 ▶ if (!defined $source) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $source) { } 0 65 65
elsif (ref $source eq 'GLOB') { } 33 32 65
24 0 croak "diff needs source argument";
25 } elsif (ref $source eq 'GLOB') {
26 33 $source_fileno = fileno($source);
27 33 ▶ croak "source file handle is closed or invalid" if !defined $source_fileno || $source_fileno == -1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $source_fileno or $source_fileno == -1 0 33 33
Condition33%1/3
not defined $source_fileno or $source_fileno == -1
l!l&&r!l&&!r
0033
MC/DC0%0/2
not defined $source_fileno or $source_fileno == -1
not defined $source_fileno $source_fileno == -1
Truth table33%1/3
not(A) or B
A= not defined $source_filenoB= $source_fileno == -1
ABresult
1X1
011
000
28 } else {
29 32 $source_str = $source;
30 }
31  
32 65 ▶ if (!defined $input) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $input) { } 0 65 65
elsif (ref $input eq 'GLOB') { } 32 33 65
33 0 croak "diff needs target argument";
34 } elsif (ref $input eq 'GLOB') {
35 32 $input_fileno = fileno($input);
36 32 ▶ croak "target file handle is closed or invalid" if !defined $input_fileno || $input_fileno == -1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $input_fileno or $input_fileno == -1 0 32 32
Condition33%1/3
not defined $input_fileno or $input_fileno == -1
l!l&&r!l&&!r
0032
MC/DC0%0/2
not defined $input_fileno or $input_fileno == -1
not defined $input_fileno $input_fileno == -1
Truth table33%1/3
not(A) or B
A= not defined $input_filenoB= $input_fileno == -1
ABresult
1X1
011
000
37 } else {
38 33 $input_str = $input;
39 }
40  
41 65 ▶ if (defined $output) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output) { } 32 33 65
42 32 ▶ croak "output argument to diff should be a file handle or undef"
Branch: 1 branch
BranchTrueFalseTotal
if ref $output ne "GLOB" 0 32 32
43 if ref $output ne 'GLOB';
44  
45 32 $output_fileno = fileno($output);
46 32 ▶ croak "output file handle is closed or invalid" if !defined $output_fileno || $output_fileno == -1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $output_fileno or $output_fileno == -1 0 32 32
Condition33%1/3
not defined $output_fileno or $output_fileno == -1
l!l&&r!l&&!r
0032
MC/DC0%0/2
not defined $output_fileno or $output_fileno == -1
not defined $output_fileno $output_fileno == -1
Truth table33%1/3
not(A) or B
A= not defined $output_filenoB= $output_fileno == -1
ABresult
1X1
011
000
47 } else {
48 33 $output_str = '';
49 }
50  
51 65 my $ret = _encode($source_fileno, $source_str, $input_fileno, $input_str, $output_fileno, $output_str);
52  
53 65 _check_ret($ret, 'diff');
54  
55 64 ▶ return $output_str if !defined $output;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $output 32 32 64
56 }
57  
58  
59 64 ▶sub patch {
Subroutine patch: called CC=14 SCAR=29.1
Pod undocumented
60 64 my ($source, $input, $output) = @_;
61  
62 64 my ($source_fileno, $source_str, $input_fileno, $input_str, $output_fileno, $output_str);
63  
64 64 $source_fileno = $input_fileno = $output_fileno = -1;
65  
66 64 ▶ if (!defined $source) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $source) { } 0 64 64
elsif (ref $source eq 'GLOB') { } 32 32 64
67 0 croak "patch needs source argument";
68 } elsif (ref $source eq 'GLOB') {
69 32 $source_fileno = fileno($source);
70 32 ▶ croak "source file handle is closed or invalid" if !defined $source_fileno || $source_fileno == -1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $source_fileno or $source_fileno == -1 0 32 32
Condition33%1/3
not defined $source_fileno or $source_fileno == -1
l!l&&r!l&&!r
0032
MC/DC0%0/2
not defined $source_fileno or $source_fileno == -1
not defined $source_fileno $source_fileno == -1
Truth table33%1/3
not(A) or B
A= not defined $source_filenoB= $source_fileno == -1
ABresult
1X1
011
000
71 } else {
72 32 $source_str = $source;
73 }
74  
75 64 ▶ if (!defined $input) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $input) { } 0 64 64
elsif (ref $input eq 'GLOB') { } 32 32 64
76 0 croak "patch needs delta argument";
77 } elsif (ref $input eq 'GLOB') {
78 32 $input_fileno = fileno($input);
79 32 ▶ croak "delta file handle is closed or invalid" if !defined $input_fileno || $input_fileno == -1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $input_fileno or $input_fileno == -1 0 32 32
Condition33%1/3
not defined $input_fileno or $input_fileno == -1
l!l&&r!l&&!r
0032
MC/DC0%0/2
not defined $input_fileno or $input_fileno == -1
not defined $input_fileno $input_fileno == -1
Truth table33%1/3
not(A) or B
A= not defined $input_filenoB= $input_fileno == -1
ABresult
1X1
011
000
80 } else {
81 32 $input_str = $input;
82 }
83  
84 64 ▶ if (defined $output) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output) { } 32 32 64
85 32 ▶ croak "output argument to patch should be a file handle or undef"
Branch: 1 branch
BranchTrueFalseTotal
if ref $output ne "GLOB" 0 32 32
86 if ref $output ne 'GLOB';
87  
88 32 $output_fileno = fileno($output);
89 32 ▶ croak "output file handle is closed or invalid" if !defined $output_fileno || $output_fileno == -1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $output_fileno or $output_fileno == -1 0 32 32
Condition33%1/3
not defined $output_fileno or $output_fileno == -1
l!l&&r!l&&!r
0032
MC/DC0%0/2
not defined $output_fileno or $output_fileno == -1
not defined $output_fileno $output_fileno == -1
Truth table33%1/3
not(A) or B
A= not defined $output_filenoB= $output_fileno == -1
ABresult
1X1
011
000
90 } else {
91 32 $output_str = '';
92 }
93  
94 64 my $ret = _decode($source_fileno, $source_str, $input_fileno, $input_str, $output_fileno, $output_str);
95  
96 64 _check_ret($ret, 'patch');
97  
98 64 ▶ return $output_str if !defined $output;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $output 32 32 64
99 }
100  
101  
102  
103 2 my $exception_map = {
104 1 => 'xd3_config_stream',
105 2 => 'unable to allocate memory for source.blksize',
106 3 => 'source is not lseek()able (must be a regular file, not a pipe/socket)',
107 4 => 'error reading from source',
108 5 => 'unable to allocate memory for ibuf',
109 6 => 'error reading from target/delta',
110 7 => 'error writing to output',
111 8 => 'xd3_close_stream',
112 };
113  
114 129 ▶sub _check_ret {
Subroutine _check_ret: called CC=3 SCAR=11.3
115 129 my ($ret, $func) = @_;
116  
117 129 ▶ return unless $ret;
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 128 1 129
118  
119 1 my $exception = $exception_map->{$ret};
120  
121 1 ▶ croak "error in Vcdiff::Xdelta3::$func: $exception" if $exception;
Branch: 1 branch
BranchTrueFalseTotal
if $exception 1 0 1
122  
123 0 croak "unknown error in Vcdiff::Xdelta3::$func ($ret)";
124 }
125  
126  
127 2 1;
128  
129  
130  
131  
132 =head1 NAME
133  
134 Vcdiff::Xdelta3 - Xdelta3 backend for Vcdiff
135  
136 =head1 SYNOPSIS
137  
138 use Vcdiff::Xdelta3;
139  
140 my $delta = Vcdiff::Xdelta3::diff($source, $target);
141  
142 my $target2 = Vcdiff::Xdelta3::patch($source, $delta);
143  
144 ## $target2 eq $target
145  
146 This module is a backend to the L<Vcdiff> module and isn't usually used directly.
147  
148  
149 =head1 DESCRIPTION
150  
151 Xdelta3 is a delta encoding library by Joshua MacDonald. The Xdelta3 source code is embedded into this module and built as a shared object. The C<xdelta3> command-line binary is not built.
152  
153  
154 =head1 PROS
155  
156 =over
157  
158 =item *
159  
160 Doesn't have arbitrary size limitations on source, target, or delta files.
161  
162 =item *
163  
164 Has a really neat feature that lets you merge VCDIFF deltas into a single delta. Unfortunately this module doesn't expose that yet.
165  
166 =back
167  
168  
169 =head1 CONS
170  
171 =over
172  
173 =item *
174  
175 GPL licensed
176  
177 =item *
178  
179 Build system is really weird. I didn't bother figuring out how to run Xdelta3's test-suite when installing the CPAN module which is unfortunate. Note that installing this module does still run the shared test-suite in L<Vcdiff>.
180  
181 =back
182  
183  
184 =head1 SEE ALSO
185  
186 L<Vcdiff-Xdelta3 github repo|https://github.com/hoytech/Vcdiff-Xdelta3>
187  
188 L<Vcdiff>
189  
190 L<Official Xdelta3 website|http://xdelta.org/>
191  
192  
193 =head1 AUTHOR
194  
195 Doug Hoyte, C<< <doug@hcsw.org> >>
196  
197  
198 =head1 COPYRIGHT & LICENSE
199  
200 Copyright 2013 Doug Hoyte.
201  
202 This module includes xdelta3 which is copyright Joshua P. MacDonald. xdelta3 is licensed under the GNU GPL 2 which can be found in the inc/COPYING file of this distribution.
203  
204 Because of xdelta3's license, this module is licensed under the GNU GPL 2.
↑ Summary Interface.xs »