blib/lib/IO/Uncompress/Base.pm

filter: Statementstmt 94.8% 682 / 719 Branchbran 81.6% 315 / 386 Conditioncond 78.2% 90 / 115 MC/DCmcdc 63.2% 43 / 68 Subroutinesub 97.3% 72 / 74 Podpod 16.6% 8 / 48 totaltotal 85.8% 1210 / 1410 CC 236 SCAR 26.4
CC
236
Cov
89%
read
30.1
smartRead
29.3
_create
25.4
CRAP 14.0
« blib/lib/IO/Uncompress/Gunzip.pm ↑ Summary blib/lib/IO/Compress/Gzip.pm »
1  
2 package IO::Uncompress::Base ;
3  
4 100 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 100 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 100 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 100 our (@ISA, $VERSION, @EXPORT_OK, %EXPORT_TAGS);
9 100 @ISA = qw(IO::File Exporter);
10  
11  
12 100 $VERSION = '2.225';
13  
14 100 ▶use constant G_EOF => 0 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 100 ▶use constant G_ERR => -1 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 100 ▶use IO::Compress::Base::Common 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 100 ▶use IO::File ;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 100 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 100 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 100 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 100 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 100 %EXPORT_TAGS = ( );
26 0 ▶$EXPORT_TAGS{all} = [ defined $EXPORT_TAGS{all} ? @{ $EXPORT_TAGS{all} } : (), @EXPORT_OK ] ;
Branch: 1 branch
BranchTrueFalseTotal
defined $IO::Uncompress::Base::EXPORT_TAGS{'all'} ? : 0 100 100
27  
28 sub smartRead
29 33900 ▶{
Subroutine smartRead: called CC=20 SCAR=33.8
Pod undocumented
30 33900 my $self = $_[0];
31 33900 my $out = $_[1];
32 33900 my $size = $_[2];
33 33900 $$out = "" ;
34  
35 33900 my $offset = 0 ;
36 33900 my $status = 1;
37  
38  
39 33900 ▶ if (defined *$self->{InputLength}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{"InputLength"}) 441 33459 33900
40 return 0
41 441 ▶ if *$self->{InputLengthRemaining} <= 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"InputLengthRemaining"} <= 0 173 268 441
42 268 $size = List::Util::min($size, *$self->{InputLengthRemaining});
43 }
44  
45 33727 ▶ if ( length *$self->{Prime} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length *$self->{"Prime"}) 9712 24015 33727
46 9712 $$out = substr(*$self->{Prime}, 0, $size) ;
47 9712 substr(*$self->{Prime}, 0, $size) = '' ;
48 9712 ▶ if (length $$out == $size) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$out == $size) 7092 2620 9712
49 *$self->{InputLengthRemaining} -= length $$out
50 7092 ▶ if defined *$self->{InputLength};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"InputLength"} 136 6956 7092
51  
52 7092 return length $$out ;
53 }
54 2620 $offset = length $$out ;
55 }
56  
57 26635 my $get_size = $size - $offset ;
58  
59 26635 ▶ if (defined *$self->{FH}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined *$self->{'FH'}) { } 14669 11966 26635
elsif (defined *$self->{'InputEvent'}) { } 0 11966 11966
60 14669 ▶ if ($offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset) { } 2620 12049 14669
61 # Not using this
62 #
63 # *$self->{FH}->read($$out, $get_size, $offset);
64 #
65 # because the filehandle may not support the offset parameter
66 # An example is Net::FTP
67 2620 my $tmp = '';
68 2620 $status = *$self->{FH}->read($tmp, $get_size) ;
69 2620 ▶ substr($$out, $offset) = $tmp
Branch: 1 branch
BranchTrueFalseTotal
if defined $status and $status > 0 732 1888 2620
Condition66%2/3
defined $status and $status > 0
!ll&&!rl&&r
01888732
MC/DC50%1/2
defined $status and $status > 0
defined $status $status > 0
Truth table66%2/3
A and B
A= defined $statusB= $status > 0
ABresult
0X0
100
111
70 if defined $status && $status > 0 ;
71 }
72 else
73 12049 { $status = *$self->{FH}->read($$out, $get_size) }
74 }
75 elsif (defined *$self->{InputEvent}) {
76 0 my $got = 1 ;
77 0 ▶ while (length $$out < $size) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$out < $size) 0 0 0
78 last
79 0 ▶ if ($got = *$self->{InputEvent}->($$out, $get_size)) <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($got = *$self->{"InputEvent"}->($$out, $get_size)) <= 0 0 0 0
80 }
81  
82 0 ▶ if (length $$out > $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$out > $size) 0 0 0
83 0 *$self->{Prime} = substr($$out, $size, length($$out));
84 0 substr($$out, $size, length($$out)) = '';
85 }
86  
87 0 ▶ *$self->{EventEof} = 1 if $got <= 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if $got <= 0 0 0 0
88 }
89 else {
90 100 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
91 11966 my $buf = *$self->{Buffer} ;
92 11966 ▶ $$buf = '' unless defined $$buf ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$buf 0 11966 11966
93 11966 substr($$out, $offset) = substr($$buf, *$self->{BufferOffset}, $get_size);
94 11966 ▶ if (*$self->{ConsumeInput})
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'ConsumeInput'}) { } 0 11966 11966
95 0 { substr($$buf, 0, $get_size) = '' }
96 else
97 11966 { *$self->{BufferOffset} += length($$out) - $offset }
98 }
99  
100 *$self->{InputLengthRemaining} -= length($$out) #- $offset
101 26635 ▶ if defined *$self->{InputLength};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"InputLength"} 132 26503 26635
102  
103 26635 ▶ if (! defined $status) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $status) 0 26635 26635
104 0 $self->saveStatus($!) ;
105 0 return STATUS_ERROR;
106 }
107  
108 26635 ▶ $self->saveStatus(length $$out < 0 ? STATUS_ERROR : STATUS_OK) ;
Branch: 1 branch
BranchTrueFalseTotal
length $$out < 0 ? : 0 26635 26635
109  
110 26635 return length $$out;
111 }
112  
113 sub pushBack
114 12180 ▶{
Subroutine pushBack: called CC=6 SCAR=18.8
Pod undocumented
115 12180 my $self = shift ;
116  
117 12180 ▶ return if ! defined $_[0] || length $_[0] == 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[0] or length $_[0] == 0 3274 8906 12180
Condition66%2/3
not defined $_[0] or length $_[0] == 0
l!l&&r!l&&!r
032748906
MC/DC50%1/2
not defined $_[0] or length $_[0] == 0
not defined $_[0] length $_[0] == 0
Truth table66%2/3
not(A) or B
A= not defined $_[0]B= length $_[0] == 0
ABresult
1X1
011
000
118  
119 8906 ▶ if (defined *$self->{FH} || defined *$self->{InputEvent} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{'FH'} or defined *$self->{'InputEvent'}) { } 4852 4054 8906
Condition66%2/3
defined *$self->{"FH"} or defined *$self->{"InputEvent"}
l!l&&r!l&&!r
485204054
MC/DC50%1/2
defined *$self->{"FH"} or defined *$self->{"InputEvent"}
defined *$self->{"FH"} defined *$self->{"InputEvent"}
Truth table66%2/3
A or B
A= defined *$self->{"FH"}B= defined *$self->{"InputEvent"}
ABresult
1X1
011
000
120 4852 *$self->{Prime} = $_[0] . *$self->{Prime} ;
121 4852 *$self->{InputLengthRemaining} += length($_[0]);
122 }
123 else {
124 4054 my $len = length $_[0];
125  
126 4054 ▶ if($len > *$self->{BufferOffset}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > *$self->{'BufferOffset'}) { } 0 4054 4054
127 0 *$self->{Prime} = substr($_[0], 0, $len - *$self->{BufferOffset}) . *$self->{Prime} ;
128 0 *$self->{InputLengthRemaining} = *$self->{InputLength};
129 0 *$self->{BufferOffset} = 0
130 }
131 else {
132 4054 *$self->{InputLengthRemaining} += length($_[0]);
133 4054 *$self->{BufferOffset} -= length($_[0]) ;
134 }
135 }
136 }
137  
138 sub smartSeek
139 120 ▶{
Subroutine smartSeek: called CC=6 SCAR=19.7
Pod undocumented
140 120 my $self = shift ;
141 120 my $offset = shift ;
142 120 my $truncate = shift;
143 120 ▶ my $position = shift || SEEK_SET;
Condition50%1/2
shift() || 0
l!l
0120
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
144  
145 # TODO -- need to take prime into account
146 120 *$self->{Prime} = '';
147 120 ▶ if (defined *$self->{FH})
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{'FH'}) { } 72 48 120
148 72 { *$self->{FH}->seek($offset, $position) }
149 else {
150 48 ▶ if ($position == SEEK_END) {
Branch: 2 branches
BranchTrueFalseTotal
if ($position == 2) { } 0 48 48
elsif ($position == 1) { } 0 48 48
151 0 *$self->{BufferOffset} = length(${ *$self->{Buffer} }) + $offset ;
152 }
153 elsif ($position == SEEK_CUR) {
154 0 *$self->{BufferOffset} += $offset ;
155 }
156 else {
157 48 *$self->{BufferOffset} = $offset ;
158 }
159  
160 0 ▶ substr(${ *$self->{Buffer} }, *$self->{BufferOffset}) = ''
Branch: 1 branch
BranchTrueFalseTotal
if $truncate 0 48 48
161 if $truncate;
162 48 return 1;
163 }
164 }
165  
166 sub smartTell
167 0 ▶{
Subroutine smartTell: not called CC=2 SCAR=17.9
Pod undocumented
168 0 my $self = shift ;
169  
170 0 ▶ if (defined *$self->{FH})
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{'FH'}) { } 0 0 0
171 0 { return *$self->{FH}->tell() }
172 else
173 0 { return *$self->{BufferOffset} }
174 }
175  
176 sub smartWrite
177 60 ▶{
Subroutine smartWrite: called CC=3 SCAR=11.0
Pod undocumented
178 60 my $self = shift ;
179 60 my $out_data = shift ;
180  
181 60 ▶ if (defined *$self->{FH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{'FH'}) { } 36 24 60
182 # flush needed for 5.8.0
183 defined *$self->{FH}->write($out_data, length $out_data) &&
184 36 ▶ defined *$self->{FH}->flush() ;
Branch: 1 branch
BranchTrueFalseTotal
defined *$self->{"FH"}->write($out_data, length $out_data) and defined *$self->{"FH"}->flush 36 0 36
185 }
186 else {
187 24 my $buf = *$self->{Buffer} ;
188 24 substr($$buf, *$self->{BufferOffset}, length $out_data) = $out_data ;
189 24 *$self->{BufferOffset} += length($out_data) ;
190 24 return 1;
191 }
192 }
193  
194 sub smartReadExact
195 12267 ▶{
Subroutine smartReadExact: called CC=1 SCAR=0.0
Pod undocumented
196 12267 return $_[0]->smartRead($_[1], $_[2]) == $_[2];
197 }
198  
199 sub smartReadToDelim
200 573 ▶{
Subroutine smartReadToDelim: called CC=4 SCAR=13.9
Pod undocumented
201 573 my $self = shift ;
202 573 my $out = shift ;
203 573 my $delim = shift ;
204 573 ▶ my $max_size = shift || 64 * 1024 ; # 64k
Condition50%1/2
shift() || 65536
l!l
0573
MC/DC0%0/1
shift() || 65536
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
205  
206 573 $$out = '' ;
207 573 my $got = '';
208  
209 573 ▶ my $status = $self->smartRead(\$got, $max_size) >= 0
Branch: 1 branch
BranchTrueFalseTotal
my $status = $self->smartRead(\$got, $max_size) >= 0 or return -1 573 0 573
210 or return STATUS_ERROR ;
211  
212 573 ▶ if ((my $ix = index($got, $delim)) >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((my $ix = index($got, $delim)) >= 0) { } 560 13 573
213 {
214 560 $$out .= substr($got, 0, $ix + length($delim)) ;
215 560 $self->pushBack(substr($got, $ix + length($delim) )) ;
216 }
217 else
218 {
219 13 $$out = $got ;
220 }
221  
222 573 return length $$out;
223 }
224  
225 sub smartEof
226 14974 ▶{
Subroutine smartEof: called CC=6 SCAR=18.0
Pod undocumented
227 14974 my ($self) = $_[0];
228 14974 local $.;
229  
230 14974 ▶ return 0 if length *$self->{Prime} || *$self->{PushMode};
Branch: 1 branch
BranchTrueFalseTotal
if length *$self->{"Prime"} or *$self->{"PushMode"} 1482 13492 14974
Condition66%2/3
length *$self->{"Prime"} or *$self->{"PushMode"}
l!l&&r!l&&!r
1482013492
MC/DC50%1/2
length *$self->{"Prime"} or *$self->{"PushMode"}
length *$self->{"Prime"} *$self->{"PushMode"}
Truth table66%2/3
A or B
A= length *$self->{"Prime"}B= *$self->{"PushMode"}
ABresult
1X1
011
000
231  
232 13492 ▶ if (defined *$self->{FH})
Branch: 2 branches
BranchTrueFalseTotal
if (defined *$self->{'FH'}) { } 7387 6105 13492
elsif (defined *$self->{'InputEvent'}) { } 0 6105 6105
233 {
234 # Could use
235 #
236 # *$self->{FH}->eof()
237 #
238 # here, but this can cause trouble if
239 # the filehandle is itself a tied handle, but it uses sysread.
240 # Then we get into mixing buffered & non-buffered IO,
241 # which will cause trouble
242  
243 7387 my $info = $self->getErrInfo();
244  
245 7387 my $buffer = '';
246 7387 my $status = $self->smartRead(\$buffer, 1);
247 7387 ▶ $self->pushBack($buffer) if length $buffer;
Branch: 1 branch
BranchTrueFalseTotal
if length $buffer 104 7283 7387
248 7387 $self->setErrInfo($info);
249  
250 7387 return $status == 0 ;
251 }
252 elsif (defined *$self->{InputEvent})
253 0 { *$self->{EventEof} }
254 else
255 6105 { *$self->{BufferOffset} >= length(${ *$self->{Buffer} }) }
256 }
257  
258 sub clearError
259 273 ▶{
Subroutine clearError: called CC=1 SCAR=0.0
Pod undocumented
260 273 my $self = shift ;
261  
262 273 *$self->{ErrorNo} = 0 ;
263 273 ${ *$self->{Error} } = '' ;
264 }
265  
266 sub getErrInfo
267 7387 ▶{
Subroutine getErrInfo: called CC=1 SCAR=0.0
Pod undocumented
268 7387 my $self = shift ;
269  
270 7387 return [ *$self->{ErrorNo}, ${ *$self->{Error} } ] ;
271 }
272  
273 sub setErrInfo
274 7387 ▶{
Subroutine setErrInfo: called CC=1 SCAR=0.0
Pod undocumented
275 7387 my $self = shift ;
276 7387 my $ref = shift;
277  
278 7387 *$self->{ErrorNo} = $ref->[0] ;
279 7387 ${ *$self->{Error} } = $ref->[1] ;
280 }
281  
282 sub saveStatus
283 37921 ▶{
Subroutine saveStatus: called CC=1 SCAR=0.0
Pod undocumented
284 37921 my $self = shift ;
285 37921 my $errno = shift() + 0 ;
286  
287 37921 *$self->{ErrorNo} = $errno;
288 37921 ${ *$self->{Error} } = '' ;
289  
290 37921 return *$self->{ErrorNo} ;
291 }
292  
293  
294 sub saveErrorString
295 3420 ▶{
Subroutine saveErrorString: called CC=2 SCAR=6.9
Pod undocumented
296 3420 my $self = shift ;
297 3420 my $retval = shift ;
298  
299 3420 ${ *$self->{Error} } = shift ;
300 3420 ▶ *$self->{ErrorNo} = @_ ? shift() + 0 : STATUS_ERROR ;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 3325 95 3420
301  
302 3420 return $retval;
303 }
304  
305 sub croakError
306 95 ▶{
Subroutine croakError: called CC=1 SCAR=0.0
Pod undocumented
307 95 my $self = shift ;
308 95 $self->saveErrorString(0, $_[0]);
309 95 croak $_[0];
310 }
311  
312  
313 sub closeError
314 18 ▶{
Subroutine closeError: called CC=1 SCAR=0.0
Pod undocumented
315 18 my $self = shift ;
316 18 my $retval = shift ;
317  
318 18 my $errno = *$self->{ErrorNo};
319 18 my $error = ${ *$self->{Error} };
320  
321 18 $self->close();
322  
323 18 *$self->{ErrorNo} = $errno ;
324 18 ${ *$self->{Error} } = $error ;
325  
326 18 return $retval;
327 }
328  
329 sub error
330 2110 ▶{
Subroutine error: called CC=1 SCAR=0.0
Pod documented
331 2110 my $self = shift ;
332 2110 return ${ *$self->{Error} } ;
333 }
334  
335 sub errorNo
336 212 ▶{
Subroutine errorNo: called CC=1 SCAR=0.0
Pod undocumented
337 212 my $self = shift ;
338 212 return *$self->{ErrorNo};
339 }
340  
341 sub HeaderError
342 2062 ▶{
Subroutine HeaderError: called CC=1 SCAR=0.0
Pod undocumented
343 2062 my ($self) = shift;
344 2062 return $self->saveErrorString(undef, "Header Error: $_[0]", STATUS_ERROR);
345 }
346  
347 sub TrailerError
348 18 ▶{
Subroutine TrailerError: called CC=1 SCAR=0.0
Pod undocumented
349 18 my ($self) = shift;
350 18 return $self->saveErrorString(G_ERR, "Trailer Error: $_[0]", STATUS_ERROR);
351 }
352  
353 sub TruncatedHeader
354 5 ▶{
Subroutine TruncatedHeader: called CC=1 SCAR=0.0
Pod undocumented
355 5 my ($self) = shift;
356 5 return $self->HeaderError("Truncated in $_[0] Section");
357 }
358  
359 sub TruncatedTrailer
360 0 ▶{
Subroutine TruncatedTrailer: not called CC=1 SCAR=6.9
Pod undocumented
361 0 my ($self) = shift;
362 0 return $self->TrailerError("Truncated in $_[0] Section");
363 }
364  
365 sub postCheckParams
366 3531 ▶{
Subroutine postCheckParams: called CC=1 SCAR=0.0
Pod undocumented
367 3531 return 1;
368 }
369  
370 sub checkParams
371 3563 ▶{
Subroutine checkParams: called CC=5 SCAR=16.4
Pod undocumented
372 3563 my $self = shift ;
373 3563 my $class = shift ;
374  
375 3563 ▶ my $got = shift || IO::Compress::Base::Parameters::new();
Condition33%1/3
shift() || IO::Compress::Base::Parameters::new()
l!l&&r!l&&!r
035630
MC/DC0%0/2
shift() || IO::Compress::Base::Parameters::new()
shift() IO::Compress::Base::Parameters::new()
Truth table33%1/3
A || B
A= shift()B= IO::Compress::Base::Parameters::new()
ABresult
1X1
011
000
376  
377 3563 my $Valid = {
378 'blocksize' => [IO::Compress::Base::Common::Parse_unsigned, 16 * 1024],
379 'autoclose' => [IO::Compress::Base::Common::Parse_boolean, 0],
380 'strict' => [IO::Compress::Base::Common::Parse_boolean, 0],
381 'append' => [IO::Compress::Base::Common::Parse_boolean, 0],
382 'prime' => [IO::Compress::Base::Common::Parse_any, undef],
383 'multistream' => [IO::Compress::Base::Common::Parse_boolean, 0],
384 'transparent' => [IO::Compress::Base::Common::Parse_any, 1],
385 'scan' => [IO::Compress::Base::Common::Parse_boolean, 0],
386 'inputlength' => [IO::Compress::Base::Common::Parse_unsigned, undef],
387 'binmodeout' => [IO::Compress::Base::Common::Parse_boolean, 0],
388 #'decode' => [IO::Compress::Base::Common::Parse_any, undef],
389  
390 #'consumeinput' => [IO::Compress::Base::Common::Parse_boolean, 0],
391  
392 $self->getExtraParams(),
393  
394 #'Todo - Revert to ordinary file on end Z_STREAM_END'=> 0,
395 # ContinueAfterEof
396 } ;
397  
398 $Valid->{trailingdata} = [IO::Compress::Base::Common::Parse_writable_scalar, undef]
399 3563 ▶ if *$self->{OneShot} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"OneShot"} 569 2994 3563
400  
401 3563 ▶ $got->parse($Valid, @_ )
Branch: 1 branch
BranchTrueFalseTotal
$got->parse($Valid, @_) or $self->croakError("${class}: " . $got->getError) 3531 32 3563
402 or $self->croakError("${class}: " . $got->getError()) ;
403  
404 3531 ▶ $self->postCheckParams($got)
Branch: 1 branch
BranchTrueFalseTotal
$self->postCheckParams($got) or $self->croakError("${class}: " . $self->error) 3531 0 3531
405 or $self->croakError("${class}: " . $self->error()) ;
406  
407 3531 return $got;
408 }
409  
410 sub _create
411 3678 ▶{
Subroutine _create: called CC=25 SCAR=32.4
412 3678 my $obj = shift;
413 3678 my $got = shift;
414 3678 my $append_mode = shift ;
415  
416 3678 my $class = ref $obj;
417 3678 ▶ $obj->croakError("$class: Missing Input parameter")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ or $got 5 3673 3678
Condition66%2/3
@_ or $got
l!l&&r!l&&!r
367305
MC/DC50%1/2
@_ or $got
@_ $got
Truth table66%2/3
A or B
A= @_B= $got
ABresult
1X1
011
000
418 if ! @_ && ! $got ;
419  
420 3673 my $inValue = shift ;
421  
422 3673 *$obj->{OneShot} = 0 ;
423  
424 3673 ▶ if (! $got)
Branch: 1 branch
BranchTrueFalseTotal
unless ($got) 2994 679 3673
425 {
426 2994 ▶ $got = $obj->checkParams($class, undef, @_)
Branch: 1 branch
BranchTrueFalseTotal
$got = $obj->checkParams($class, undef, @_) or return undef 2982 0 2982
427 or return undef ;
428 }
429  
430 3661 my $inType = whatIsInput($inValue, 1);
431  
432 3661 ▶ $obj->ckInputParam($class, $inValue, 1)
Branch: 1 branch
BranchTrueFalseTotal
$obj->ckInputParam($class, $inValue, 1) or return undef 3656 0 3656
433 or return undef ;
434  
435 3656 *$obj->{InNew} = 1;
436  
437 $obj->ckParams($got)
438 3656 ▶ or $obj->croakError("${class}: " . *$obj->{Error});
Branch: 1 branch
BranchTrueFalseTotal
$obj->ckParams($got) or $obj->croakError("${class}: " . *$obj->{"Error"}) 3656 0 3656
439  
440 3656 ▶ if ($inType eq 'buffer' || $inType eq 'code') {
Branch: 1 branch
BranchTrueFalseTotal
if ($inType eq 'buffer' or $inType eq 'code') { } 1450 2206 3656
Condition66%2/3
$inType eq "buffer" or $inType eq "code"
l!l&&r!l&&!r
145002206
MC/DC50%1/2
$inType eq "buffer" or $inType eq "code"
$inType eq "buffer" $inType eq "code"
Truth table66%2/3
A or B
A= $inType eq "buffer"B= $inType eq "code"
ABresult
1X1
011
000
441 1450 *$obj->{Buffer} = $inValue ;
442 1450 ▶ *$obj->{InputEvent} = $inValue
Branch: 1 branch
BranchTrueFalseTotal
if $inType eq "code" 0 1450 1450
443 if $inType eq 'code' ;
444 }
445 else {
446 2206 ▶ if ($inType eq 'handle') {
Branch: 1 branch
BranchTrueFalseTotal
if ($inType eq 'handle') { } 474 1732 2206
447 474 *$obj->{FH} = $inValue ;
448 474 *$obj->{Handle} = 1 ;
449  
450 # Need to rewind for Scan
451 474 ▶ *$obj->{FH}->seek(0, SEEK_SET)
Branch: 1 branch
BranchTrueFalseTotal
if $got->getValue("scan") 18 456 474
452 if $got->getValue('scan');
453 }
454 else {
455 100 ▶ no warnings ;
Subroutine BEGIN: called CC=1 SCAR=0.0
456 1732 my $mode = '<';
457 1732 ▶ $mode = '+<' if $got->getValue('scan');
Branch: 1 branch
BranchTrueFalseTotal
if $got->getValue("scan") 30 1702 1732
458 1732 *$obj->{StdIO} = ($inValue eq '-');
459 1732 ▶ *$obj->{FH} = IO::File->new( "$mode $inValue" )
Branch: 1 branch
BranchTrueFalseTotal
*$obj->{"FH"} = "IO::File"->new("$mode $inValue") or return $obj->saveErrorString(undef, "cannot open file '${inValue}': $!", $!) 1724 8 1732
460 or return $obj->saveErrorString(undef, "cannot open file '$inValue': $!", $!) ;
461 }
462  
463 2198 *$obj->{LineNo} = $. = 0;
464 2198 setBinModeInput(*$obj->{FH}) ;
465  
466 2198 my $buff = "" ;
467 2198 *$obj->{Buffer} = \$buff ;
468 }
469  
470 # if ($got->getValue('decode')) {
471 # my $want_encoding = $got->getValue('decode');
472 # *$obj->{Encoding} = IO::Compress::Base::Common::getEncoding($obj, $class, $want_encoding);
473 # }
474 # else {
475 # *$obj->{Encoding} = undef;
476 # }
477  
478 3648 ▶ *$obj->{InputLength} = $got->parsed('inputlength')
Branch: 1 branch
BranchTrueFalseTotal
$got->parsed('inputlength') ? : 70 3578 3648
479 ? $got->getValue('inputlength')
480 : undef ;
481 3648 *$obj->{InputLengthRemaining} = $got->getValue('inputlength');
482 3648 *$obj->{BufferOffset} = 0 ;
483 3648 *$obj->{AutoClose} = $got->getValue('autoclose');
484 3648 *$obj->{Strict} = $got->getValue('strict');
485 3648 *$obj->{BlockSize} = $got->getValue('blocksize');
486 3648 *$obj->{Append} = $got->getValue('append');
487 3648 ▶ *$obj->{AppendOutput} = $append_mode || $got->getValue('append');
Condition100%3/3
$append_mode || $got->getValue('append')
l!l&&r!l&&!r
6792209760
MC/DC100%2/2
$append_mode || $got->getValue('append')
$append_mode $got->getValue('append')
Truth table100%3/3
A || B
A= $append_modeB= $got->getValue('append')
ABresult
1X1
011
000
488 3648 *$obj->{ConsumeInput} = $got->getValue('consumeinput');
489 3648 *$obj->{Transparent} = $got->getValue('transparent');
490 3648 *$obj->{MultiStream} = $got->getValue('multistream');
491  
492 # TODO - move these two into RawDeflate
493 3648 *$obj->{Scan} = $got->getValue('scan');
494 3648 ▶ *$obj->{ParseExtra} = $got->getValue('parseextra')
Condition100%3/3
$got->getValue('parseextra') || $got->getValue('strict')
l!l&&r!l&&!r
1412952339
MC/DC100%2/2
$got->getValue('parseextra') || $got->getValue('strict')
$got->getValue('parseextra') $got->getValue('strict')
Truth table100%3/3
A || B
A= $got->getValue('parseextra')B= $got->getValue('strict')
ABresult
1X1
011
000
495 || $got->getValue('strict') ;
496 3648 *$obj->{Type} = '';
497 3648 ▶ *$obj->{Prime} = $got->getValue('prime') || '' ;
Condition50%1/2
$got->getValue('prime') || ''
l!l
03648
MC/DC0%0/1
$got->getValue('prime') || ''
$got->getValue('prime')
Truth table50%1/2
A
A= $got->getValue('prime')
Aresult
11
00
498 3648 *$obj->{Pending} = '';
499 3648 *$obj->{Plain} = 0;
500 3648 *$obj->{PlainBytesRead} = 0;
501 3648 *$obj->{InflatedBytesRead} = 0;
502 3648 *$obj->{UnCompSize} = U64->new;
503 3648 *$obj->{CompSize} = U64->new;
504 3648 *$obj->{TotalInflatedBytesRead} = 0;
505 3648 *$obj->{NewStream} = 0 ;
506 3648 *$obj->{EventEof} = 0 ;
507 3648 *$obj->{ClassName} = $class ;
508 3648 *$obj->{Params} = $got ;
509  
510 3648 ▶ if (*$obj->{ConsumeInput}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$obj->{"ConsumeInput"}) 0 3648 3648
511 0 *$obj->{InNew} = 0;
512 0 *$obj->{Closed} = 0;
513 0 return $obj
514 }
515  
516 3648 my $status = $obj->mkUncomp($got);
517  
518 return undef
519 3647 ▶ unless defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 29 3618 3647
520  
521 3618 *$obj->{InNew} = 0;
522 3618 *$obj->{Closed} = 0;
523  
524 return $obj
525 3618 ▶ if *$obj->{Pause} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$obj->{"Pause"} 0 3618 3618
526  
527 3618 ▶ if ($status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) { } 3315 303 3618
528 # Need to try uncompressing to catch the case
529 # where the compressed file uncompresses to an
530 # empty string - so eof is set immediately.
531  
532 3315 my $out_buffer = '';
533  
534 3315 $status = $obj->read(\$out_buffer);
535  
536 3315 ▶ if ($status < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status < 0) 7 3308 3315
537 7 *$obj->{ReadStatus} = [ $status, $obj->error(), $obj->errorNo() ];
538 }
539  
540 3315 ▶ $obj->ungetc($out_buffer)
Branch: 1 branch
BranchTrueFalseTotal
if length $out_buffer 2844 471 3315
541 if length $out_buffer;
542 }
543 else {
544 return undef
545 303 ▶ unless *$obj->{Transparent};
Branch: 1 branch
BranchTrueFalseTotal
unless *$obj->{"Transparent"} 33 270 303
546  
547 270 $obj->clearError();
548 270 *$obj->{Type} = 'plain';
549 270 *$obj->{Plain} = 1;
550 270 $obj->pushBack(*$obj->{HeaderPending}) ;
551 }
552  
553 3585 push @{ *$obj->{InfoList} }, *$obj->{Info} ;
554  
555 3585 $obj->saveStatus(STATUS_OK) ;
556 3585 *$obj->{InNew} = 0;
557 3585 *$obj->{Closed} = 0;
558  
559 3585 return $obj;
560 }
561  
562 sub ckInputParam
563 3661 ▶{
Subroutine ckInputParam: called CC=2 SCAR=6.9
Pod undocumented
564 3661 my $self = shift ;
565 3661 my $from = shift ;
566 3661 my $inType = whatIsInput($_[0], $_[1]);
567  
568 3661 ▶ $self->croakError("$from: input parameter not a filename, filehandle, array ref or scalar ref")
Branch: 1 branch
BranchTrueFalseTotal
unless $inType 5 3656 3661
569 if ! $inType ;
570  
571 # if ($inType eq 'filename' )
572 # {
573 # return $self->saveErrorString(1, "$from: input filename is undef or null string", STATUS_ERROR)
574 # if ! defined $_[0] || $_[0] eq '' ;
575 #
576 # if ($_[0] ne '-' && ! -e $_[0] )
577 # {
578 # return $self->saveErrorString(1,
579 # "input file '$_[0]' does not exist", STATUS_ERROR);
580 # }
581 # }
582  
583 3656 return 1;
584 }
585  
586  
587 sub _inf
588 729 ▶{
Subroutine _inf: called CC=16 SCAR=28.1
589 729 my $obj = shift ;
590  
591 729 my $class = (caller)[0] ;
592 729 my $name = (caller(1))[3] ;
593  
594 729 ▶ $obj->croakError("$name: expected at least 1 parameters\n")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 1 10 719 729
595 unless @_ >= 1 ;
596  
597 719 my $input = shift ;
598 719 my $haveOut = @_ ;
599 719 my $output = shift ;
600  
601  
602 719 ▶ my $x = IO::Compress::Base::Validator->new($class, *$obj->{Error}, $name, $input, $output)
Branch: 1 branch
BranchTrueFalseTotal
my $x = "IO::Compress::Base::Validator"->new($class, *$obj->{"Error"}, $name, $input, $output) or return undef 569 50 619
603 or return undef ;
604  
605 569 ▶ push @_, $output if $haveOut && $x->{Hash};
Branch: 1 branch
BranchTrueFalseTotal
if $haveOut and $x->{"Hash"} 0 569 569
Condition33%1/3
$haveOut and $x->{"Hash"}
!ll&&!rl&&r
05690
MC/DC0%0/2
$haveOut and $x->{"Hash"}
$haveOut $x->{"Hash"}
Truth table33%1/3
A and B
A= $haveOutB= $x->{"Hash"}
ABresult
0X0
100
111
606  
607 569 *$obj->{OneShot} = 1 ;
608  
609 569 ▶ my $got = $obj->checkParams($name, undef, @_)
Branch: 1 branch
BranchTrueFalseTotal
my $got = $obj->checkParams($name, undef, @_) or return undef 549 0 549
610 or return undef ;
611  
612 549 ▶ if ($got->parsed('trailingdata'))
Branch: 1 branch
BranchTrueFalseTotal
if ($got->parsed("trailingdata")) 10 539 549
613 {
614 # my $value = $got->valueRef('TrailingData');
615 # warn "TD $value ";
616 # #$value = $$value;
617 ## warn "TD $value $$value ";
618 #
619 # return retErr($obj, "Parameter 'TrailingData' not writable")
620 # if readonly $$value ;
621 #
622 # if (ref $$value)
623 # {
624 # return retErr($obj,"Parameter 'TrailingData' not a scalar reference")
625 # if ref $$value ne 'SCALAR' ;
626 #
627 # *$obj->{TrailingData} = $$value ;
628 # }
629 # else
630 # {
631 # return retErr($obj,"Parameter 'TrailingData' not a scalar")
632 # if ref $value ne 'SCALAR' ;
633 #
634 # *$obj->{TrailingData} = $value ;
635 # }
636  
637 10 *$obj->{TrailingData} = $got->getValue('trailingdata');
638 }
639  
640 549 *$obj->{MultiStream} = $got->getValue('multistream');
641 549 $got->setValue('multistream', 0);
642  
643 549 $x->{Got} = $got ;
644  
645 # if ($x->{Hash})
646 # {
647 # while (my($k, $v) = each %$input)
648 # {
649 # $v = \$input->{$k}
650 # unless defined $v ;
651 #
652 # $obj->_singleTarget($x, $k, $v, @_)
653 # or return undef ;
654 # }
655 #
656 # return keys %$input ;
657 # }
658  
659 549 ▶ if ($x->{GlobMap})
Branch: 1 branch
BranchTrueFalseTotal
if ($x->{"GlobMap"}) 10 539 549
660 {
661 10 $x->{oneInput} = 1 ;
662 10 foreach my $pair (@{ $x->{Pairs} })
663 {
664 30 my ($from, $to) = @$pair ;
665 30 ▶ $obj->_singleTarget($x, $from, $to, @_)
Branch: 1 branch
BranchTrueFalseTotal
$obj->_singleTarget($x, $from, $to, @_) or return undef 30 0 30
666 or return undef ;
667 }
668  
669 10 return scalar @{ $x->{Pairs} } ;
670 }
671  
672 539 ▶ if (! $x->{oneOutput} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($x->{"oneOutput"}) 40 499 539
673 {
674 my $inFile = ($x->{inType} eq 'filenames'
675 40 ▶ || $x->{inType} eq 'filename');
Condition66%2/3
$x->{'inType'} eq 'filenames' || $x->{'inType'} eq 'filename'
l!l&&r!l&&!r
20020
MC/DC50%1/2
$x->{'inType'} eq 'filenames' || $x->{'inType'} eq 'filename'
$x->{'inType'} eq 'filenames' $x->{'inType'} eq 'filename'
Truth table66%2/3
A || B
A= $x->{'inType'} eq 'filenames'B= $x->{'inType'} eq 'filename'
ABresult
1X1
011
000
676  
677 40 ▶ $x->{inType} = $inFile ? 'filename' : 'buffer';
Branch: 1 branch
BranchTrueFalseTotal
$inFile ? : 20 20 40
678  
679 40 ▶ foreach my $in ($x->{oneInput} ? $input : @$input)
Branch: 1 branch
BranchTrueFalseTotal
$x->{'oneInput'} ? : 20 20 40
680 {
681 70 my $out ;
682 70 $x->{oneInput} = 1 ;
683  
684 70 ▶ $obj->_singleTarget($x, $in, $output, @_)
Branch: 1 branch
BranchTrueFalseTotal
$obj->_singleTarget($x, $in, $output, @_) or return undef 70 0 70
685 or return undef ;
686 }
687  
688 40 return 1 ;
689 }
690  
691 # finally the 1 to 1 and n to 1
692 499 return $obj->_singleTarget($x, $input, $output, @_);
693  
694 0 croak "should not be here" ;
695 }
696  
697 sub retErr
698 10 ▶{
Subroutine retErr: called CC=1 SCAR=0.0
Pod undocumented
699 10 my $x = shift ;
700 10 my $string = shift ;
701  
702 10 ${ $x->{Error} } = $string ;
703  
704 10 return undef ;
705 }
706  
707 sub _singleTarget
708 599 ▶{
Subroutine _singleTarget: called CC=19 SCAR=29.5
709 599 my $self = shift ;
710 599 my $x = shift ;
711 599 my $input = shift;
712 599 my $output = shift;
713  
714 599 my $buff = '';
715 599 $x->{buff} = \$buff ;
716  
717 599 my $fh ;
718 599 ▶ if ($x->{outType} eq 'filename') {
Branch: 3 branches
BranchTrueFalseTotal
if ($x->{'outType'} eq 'filename') { } 130 469 599
elsif ($x->{'outType'} eq 'handle') { } 85 384 469
elsif ($x->{'outType'} eq 'buffer') { } 314 70 384
719 130 my $mode = '>' ;
720 $mode = '>>'
721 130 ▶ if $x->{Got}->getValue('append') ;
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"Got"}->getValue("append") 30 100 130
722 130 ▶ $x->{fh} = IO::File->new( "$mode $output" )
Branch: 1 branch
BranchTrueFalseTotal
$x->{"fh"} = "IO::File"->new("$mode $output") or return retErr($x, "cannot open file '${output}': $!") 120 10 130
723 or return retErr($x, "cannot open file '$output': $!") ;
724 120 binmode $x->{fh} ;
725  
726 }
727  
728 elsif ($x->{outType} eq 'handle') {
729 85 $x->{fh} = $output;
730 85 binmode $x->{fh} ;
731 85 ▶ if ($x->{Got}->getValue('append')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x->{"Got"}->getValue("append")) 30 55 85
732 30 ▶ seek($x->{fh}, 0, SEEK_END)
Branch: 1 branch
BranchTrueFalseTotal
CORE::seek $x->{"fh"}, 0, 2 or return retErr($x, "Cannot seek to end of output filehandle: $!") 30 0 30
733 or return retErr($x, "Cannot seek to end of output filehandle: $!") ;
734 }
735 }
736  
737  
738 elsif ($x->{outType} eq 'buffer' )
739 {
740 $$output = ''
741 314 ▶ unless $x->{Got}->getValue('append');
Branch: 1 branch
BranchTrueFalseTotal
unless $x->{"Got"}->getValue("append") 273 41 314
742 314 $x->{buff} = $output ;
743 }
744  
745 589 ▶ if ($x->{oneInput})
Branch: 1 branch
BranchTrueFalseTotal
if ($x->{'oneInput'}) { } 529 60 589
746 {
747 529 ▶ defined $self->_rd2($x, $input, $output)
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_rd2($x, $input, $output) or return undef 497 32 529
748 or return undef;
749 }
750 else
751 {
752 60 ▶ for my $element ( ($x->{inType} eq 'hash') ? keys %$input : @$input)
Branch: 1 branch
BranchTrueFalseTotal
$x->{'inType'} eq 'hash' ? : 0 60 60
753 {
754 150 ▶ defined $self->_rd2($x, $element, $output)
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_rd2($x, $element, $output) or return undef 150 0 150
755 or return undef ;
756 }
757 }
758  
759  
760 557 ▶ if ( ($x->{outType} eq 'filename' && $output ne '-') ||
Branch: 1 branch
BranchTrueFalseTotal
if ($x->{"outType"} eq "filename" and $output ne "-" or $x->{"outType"} eq "handle" and $x->{"Got"}->getValue("autoclose")) 190 367 557
Condition88%8/9
$x->{"outType"} eq "filename" and $output ne "-" or $x->{"outType"} eq "handle" and $x->{"Got"}->getValue("autoclose")
l!l&&r!l&&!r
12070367
$x->{"outType"} eq "filename" and $output ne "-"
!ll&&!rl&&r
4370120
$x->{"outType"} eq "handle" and $x->{"Got"}->getValue("autoclose")
!ll&&!rl&&r
3521570
MC/DC75%3/4
$x->{"outType"} eq "filename" and $output ne "-" or $x->{"outType"} eq "handle" and $x->{"Got"}->getValue("autoclose")
$x->{"outType"} eq "filename" $output ne "-" $x->{"outType"} eq "handle" $x->{"Got"}->getValue("autoclose")
Truth table57%4/7
A and B or C and D
A= $x->{"outType"} eq "filename"B= $output ne "-"C= $x->{"outType"} eq "handle"D= $x->{"Got"}->getValue("autoclose")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
761 ($x->{outType} eq 'handle' && $x->{Got}->getValue('autoclose'))) {
762 $x->{fh}->close()
763 190 ▶ or return retErr($x, $!);
Branch: 1 branch
BranchTrueFalseTotal
$x->{"fh"}->close or return retErr($x, $!) 190 0 190
764 190 delete $x->{fh};
765 }
766  
767 557 return 1 ;
768 }
769  
770 sub _rd2
771 679 ▶{
Subroutine _rd2: called CC=15 SCAR=27.2
772 679 my $self = shift ;
773 679 my $x = shift ;
774 679 my $input = shift;
775 679 my $output = shift;
776  
777 679 my $z = IO::Compress::Base::Common::createSelfTiedObject($x->{Class}, *$self->{Error});
778  
779 679 ▶ $z->_create($x->{Got}, 1, $input, @_)
Branch: 1 branch
BranchTrueFalseTotal
$z->_create($x->{"Got"}, 1, $input, @_) or return undef 665 14 679
780 or return undef ;
781  
782 665 my $status ;
783 665 my $fh = $x->{fh};
784  
785 665 while (1) {
786  
787 684 ▶ while (($status = $z->read($x->{buff})) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (($status = $z->read($x->{"buff"})) > 0) 730 684 1414
788 730 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 265 465 730
789 265 local $\;
790 265 ▶ print $fh ${ $x->{buff} }
Branch: 1 branch
BranchTrueFalseTotal
print $fh ${$x->{"buff"};} or return $z->saveErrorString(undef, "Error writing to output file: $!", $!) 265 0 265
791 or return $z->saveErrorString(undef, "Error writing to output file: $!", $!);
792 265 ${ $x->{buff} } = '' ;
793 }
794 }
795  
796 684 ▶ if (! $x->{oneOutput} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($x->{"oneOutput"}) 100 584 684
797 100 my $ot = $x->{outType} ;
798  
799 100 ▶ if ($ot eq 'array')
Branch: 2 branches
BranchTrueFalseTotal
if ($ot eq 'array') { } 70 30 100
elsif ($ot eq 'hash') { } 0 30 30
800 70 { push @$output, $x->{buff} }
801 elsif ($ot eq 'hash')
802 0 { $output->{$input} = $x->{buff} }
803  
804 100 my $buff = '';
805 100 $x->{buff} = \$buff;
806 }
807  
808 684 ▶ last if $status < 0 || $z->smartEof();
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 or $z->smartEof 627 57 684
Condition100%3/3
$status < 0 or $z->smartEof
l!l&&r!l&&!r
1860957
MC/DC100%2/2
$status < 0 or $z->smartEof
$status < 0 $z->smartEof
Truth table100%3/3
A or B
A= $status < 0B= $z->smartEof
ABresult
1X1
011
000
809  
810 last
811 57 ▶ unless *$self->{MultiStream};
Branch: 1 branch
BranchTrueFalseTotal
unless *$self->{"MultiStream"} 38 19 57
812  
813 19 $status = $z->nextStream();
814  
815 last
816 19 ▶ unless $status == 1 ;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 1 0 19 19
817 }
818  
819 665 ▶ return $z->closeError(undef)
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 18 647 665
820 if $status < 0 ;
821  
822 10 ${ *$self->{TrailingData} } = $z->trailingData()
823 647 ▶ if defined *$self->{TrailingData} ;
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"TrailingData"} 10 637 647
824  
825 647 ▶ $z->close()
Branch: 1 branch
BranchTrueFalseTotal
$z->close or return undef 647 0 647
826 or return undef ;
827  
828 647 return 1 ;
829 }
830  
831 sub TIEHANDLE
832 4407 ▶{
Subroutine TIEHANDLE: called CC=2 SCAR=9.2
833 4407 ▶ return $_[0] if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 4407 0 4407
834 0 die "OOPS\n" ;
835  
836 }
837  
838 sub UNTIE
839 3606 ▶{
Subroutine UNTIE: called CC=1 SCAR=0.0
840 3606 my $self = shift ;
841 }
842  
843  
844 sub getHeaderInfo
845 239 ▶{
Subroutine getHeaderInfo: called CC=2 SCAR=6.9
Pod undocumented
846 239 my $self = shift ;
847 239 ▶ wantarray ? @{ *$self->{InfoList} } : *$self->{Info};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 90 149 239
848 }
849  
850 sub readBlock
851 4855 ▶{
Subroutine readBlock: called CC=5 SCAR=16.1
Pod undocumented
852 4855 my $self = shift ;
853 4855 my $buff = shift ;
854 4855 my $size = shift ;
855  
856 4855 ▶ if (defined *$self->{CompressedInputLength}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{"CompressedInputLength"}) 103 4752 4855
857 103 ▶ if (*$self->{CompressedInputLengthRemaining} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"CompressedInputLengthRemaining"} == 0) 22 81 103
858 22 delete *$self->{CompressedInputLength};
859 22 *$self->{CompressedInputLengthDone} = 1;
860 22 return STATUS_OK ;
861 }
862 81 $size = List::Util::min($size, *$self->{CompressedInputLengthRemaining} );
863 81 *$self->{CompressedInputLengthRemaining} -= $size ;
864 }
865  
866 4833 my $status = $self->smartRead($buff, $size) ;
867 4833 ▶ return $self->saveErrorString(STATUS_ERROR, "Error Reading Data: $!", $!)
Branch: 1 branch
BranchTrueFalseTotal
if $status == -1 0 4833 4833
868 if $status == STATUS_ERROR ;
869  
870 4833 ▶ if ($status == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 0) 12 4821 4833
871 12 *$self->{Closed} = 1 ;
872 12 *$self->{EndStream} = 1 ;
873 12 return $self->saveErrorString(STATUS_ERROR, "unexpected end of file", STATUS_ERROR);
874 }
875  
876 4821 return STATUS_OK;
877 }
878  
879 sub postBlockChk
880 4837 ▶{
Subroutine postBlockChk: called CC=1 SCAR=0.0
Pod undocumented
881 4837 return STATUS_OK;
882 }
883  
884 sub _raw_read
885 6573 ▶{
Subroutine _raw_read: called CC=23 SCAR=31.5
886 # return codes
887 # >0 - ok, number of bytes read
888 # =0 - ok, eof
889 # <0 - not ok
890  
891 6573 my $self = shift ;
892  
893 6573 ▶ return G_EOF if *$self->{Closed} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Closed"} 0 6573 6573
894 6573 ▶ return G_EOF if *$self->{EndStream} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"EndStream"} 0 6573 6573
895  
896 6573 my $buffer = shift ;
897 6573 my $scan_mode = shift ;
898  
899 6573 ▶ if (*$self->{Plain}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"Plain"}) 541 6032 6573
900 541 my $tmp_buff ;
901 541 my $len = $self->smartRead(\$tmp_buff, *$self->{BlockSize}) ;
902  
903 541 ▶ return $self->saveErrorString(G_ERR, "Error reading data: $!", $!)
Branch: 1 branch
BranchTrueFalseTotal
if $len == -1 0 541 541
904 if $len == STATUS_ERROR ;
905  
906 541 ▶ if ($len == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len == 0) { } 260 281 541
907 260 *$self->{EndStream} = 1 ;
908 }
909 else {
910 281 *$self->{PlainBytesRead} += $len ;
911 281 $$buffer .= $tmp_buff;
912 }
913  
914 541 return $len ;
915 }
916  
917 6032 ▶ if (*$self->{NewStream}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"NewStream"}) 1177 4855 6032
918  
919 1177 ▶ $self->gotoNextStream() > 0
Branch: 1 branch
BranchTrueFalseTotal
$self->gotoNextStream > 0 or return -1 1177 0 1177
920 or return G_ERR;
921  
922 # For the headers that actually uncompressed data, put the
923 # uncompressed data into the output buffer.
924 1177 $$buffer .= *$self->{Pending} ;
925 1177 my $len = length *$self->{Pending} ;
926 1177 *$self->{Pending} = '';
927 1177 return $len;
928 }
929  
930 4855 my $temp_buf = '';
931 4855 my $outSize = 0;
932 4855 my $status = $self->readBlock(\$temp_buf, *$self->{BlockSize}, $outSize) ;
933  
934 4855 ▶ return G_ERR
Branch: 1 branch
BranchTrueFalseTotal
if $status == -1 12 4843 4855
935 if $status == STATUS_ERROR ;
936  
937 4843 my $buf_len = 0;
938 4843 ▶ if ($status == STATUS_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 0) 4843 0 4843
939 4843 my $beforeC_len = length $temp_buf;
940 4843 ▶ my $before_len = defined $$buffer ? length $$buffer : 0 ;
Branch: 1 branch
BranchTrueFalseTotal
defined $$buffer ? : 4843 0 4843
941 $status = *$self->{Uncomp}->uncompr(\$temp_buf, $buffer,
942 defined *$self->{CompressedInputLengthDone} ||
943 4843 ▶ $self->smartEof(), $outSize);
Condition100%3/3
defined *$self->{'CompressedInputLengthDone'} || $self->smartEof
l!l&&r!l&&!r
234150670
MC/DC100%2/2
defined *$self->{'CompressedInputLengthDone'} || $self->smartEof
defined *$self->{'CompressedInputLengthDone'} $self->smartEof
Truth table100%3/3
A || B
A= defined *$self->{'CompressedInputLengthDone'}B= $self->smartEof
ABresult
1X1
011
000
944  
945 # Remember the input buffer if it wasn't consumed completely
946 4843 ▶ $self->pushBack($temp_buf) if *$self->{Uncomp}{ConsumesInput};
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Uncomp"}{"ConsumesInput"} 4843 0 4843
947  
948 return $self->saveErrorString(G_ERR, *$self->{Uncomp}{Error}, *$self->{Uncomp}{ErrorNo})
949 4843 ▶ if $self->saveStatus($status) == STATUS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if $self->saveStatus($status) == -1 6 4837 4843
950  
951 4837 ▶ $self->postBlockChk($buffer, $before_len) == STATUS_OK
Branch: 1 branch
BranchTrueFalseTotal
$self->postBlockChk($buffer, $before_len) == 0 or return -1 4837 0 4837
952 or return G_ERR;
953  
954 4837 ▶ $buf_len = defined $$buffer ? length($$buffer) - $before_len : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $$buffer ? : 4837 0 4837
955  
956 4837 *$self->{CompSize}->add($beforeC_len - length $temp_buf) ;
957  
958 4837 *$self->{InflatedBytesRead} += $buf_len ;
959 4837 *$self->{TotalInflatedBytesRead} += $buf_len ;
960 4837 *$self->{UnCompSize}->add($buf_len) ;
961  
962 4837 $self->filterUncompressed($buffer, $before_len);
963  
964 # if (*$self->{Encoding}) {
965 # use Encode ;
966 # *$self->{PendingDecode} .= substr($$buffer, $before_len) ;
967 # my $got = *$self->{Encoding}->decode(*$self->{PendingDecode}, Encode::FB_QUIET) ;
968 # substr($$buffer, $before_len) = $got;
969 # }
970 }
971  
972 4837 ▶ if ($status == STATUS_ENDSTREAM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 1) 3991 846 4837
973  
974 3991 *$self->{EndStream} = 1 ;
975  
976 3991 my $trailer;
977 3991 my $trailer_size = *$self->{Info}{TrailerLength} ;
978 3991 my $got = 0;
979 3991 ▶ if (*$self->{Info}{TrailerLength})
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"Info"}{"TrailerLength"}) 2841 1150 3991
980 {
981 2841 $got = $self->smartRead(\$trailer, $trailer_size) ;
982 }
983  
984 3991 ▶ if ($got == $trailer_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got == $trailer_size) { } 3947 44 3991
985 3947 ▶ $self->chkTrailer($trailer) == STATUS_OK
Branch: 1 branch
BranchTrueFalseTotal
$self->chkTrailer($trailer) == 0 or return -1 3941 6 3947
986 or return G_ERR;
987 }
988 else {
989 return $self->TrailerError("trailer truncated. Expected " .
990 "$trailer_size bytes, got $got")
991 44 ▶ if *$self->{Strict};
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Strict"} 12 32 44
992 32 $self->pushBack($trailer) ;
993 }
994  
995 # TODO - if want file pointer, do it here
996  
997 3973 ▶ if (! $self->smartEof()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->smartEof) 1380 2593 3973
998 1380 *$self->{NewStream} = 1 ;
999  
1000 1380 ▶ if (*$self->{MultiStream}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"MultiStream"}) 943 437 1380
1001 943 *$self->{EndStream} = 0 ;
1002 943 return $buf_len ;
1003 }
1004 }
1005  
1006 }
1007  
1008  
1009 # return the number of uncompressed bytes read
1010 3876 return $buf_len ;
1011 }
1012  
1013 sub reset
1014 1775 ▶{
Subroutine reset: called CC=1 SCAR=0.0
Pod undocumented
1015 1775 my $self = shift ;
1016  
1017 1775 return *$self->{Uncomp}->reset();
1018 }
1019  
1020 sub filterUncompressed
1021 3615 ▶{
Subroutine filterUncompressed: called CC=1 SCAR=0.0
Pod undocumented
1022 }
1023  
1024 #sub isEndStream
1025 #{
1026 # my $self = shift ;
1027 # return *$self->{NewStream} ||
1028 # *$self->{EndStream} ;
1029 #}
1030  
1031 sub nextStream
1032 599 ▶{
Subroutine nextStream: called CC=5 SCAR=16.1
Pod undocumented
1033 599 my $self = shift ;
1034  
1035 # An uncompressed file cannot have a next stream, so
1036 # return immediately.
1037 return 0
1038 599 ▶ if *$self->{Plain} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Plain"} 1 598 599
1039  
1040 598 my $status = $self->gotoNextStream();
1041 598 ▶ $status == 1
Branch: 1 branch
BranchTrueFalseTotal
$status == 1 or return $status 407 191 598
1042 or return $status ;
1043  
1044 *$self->{Pending} = ''
1045 407 ▶ if $self !~ /IO::Uncompress::RawInflate/ && ! *$self->{MultiStream};
Branch: 1 branch
BranchTrueFalseTotal
unless $self =~ /IO::Uncompress::RawInflate/ or *$self->{"MultiStream"} 331 76 407
Condition66%2/3
$self =~ /IO::Uncompress::RawInflate/ or *$self->{"MultiStream"}
l!l&&r!l&&!r
760331
MC/DC50%1/2
$self =~ /IO::Uncompress::RawInflate/ or *$self->{"MultiStream"}
$self =~ /IO::Uncompress::RawInflate/ *$self->{"MultiStream"}
Truth table66%2/3
A or B
A= $self =~ /IO::Uncompress::RawInflate/B= *$self->{"MultiStream"}
ABresult
1X1
011
000
1046  
1047 407 *$self->{TotalInflatedBytesRead} = 0 ;
1048 407 *$self->{LineNo} = $. = 0;
1049  
1050 407 return 1;
1051 }
1052  
1053 sub gotoNextStream
1054 1775 ▶{
Subroutine gotoNextStream: called CC=8 SCAR=20.9
Pod undocumented
1055 1775 my $self = shift ;
1056  
1057 1775 ▶ if (! *$self->{NewStream}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (*$self->{"NewStream"}) 271 1504 1775
1058 271 my $status = 1;
1059 271 my $buffer ;
1060  
1061 # TODO - make this more efficient if know the offset for the end of
1062 # the stream and seekable
1063 271 ▶ $status = $self->read($buffer)
Branch: 1 branch
BranchTrueFalseTotal
$status > 0 and do { $status = $self->read($buffer) } 280 271 551
1064 while $status > 0 ;
1065  
1066 271 ▶ return $status
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 0 271 271
1067 if $status < 0;
1068 }
1069  
1070 1775 *$self->{NewStream} = 0 ;
1071 1775 *$self->{EndStream} = 0 ;
1072 1775 *$self->{CompressedInputLengthDone} = undef ;
1073 1775 *$self->{CompressedInputLength} = undef ;
1074 1775 $self->reset();
1075 1775 *$self->{UnCompSize}->reset();
1076 1775 *$self->{CompSize}->reset();
1077  
1078 1775 my $magic = $self->ckMagic();
1079  
1080 1775 ▶ if ( ! defined $magic) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $magic) { } 194 1581 1775
1081 194 ▶ if (! *$self->{Transparent} || $self->eof())
Branch: 1 branch
BranchTrueFalseTotal
if (not *$self->{"Transparent"} or $self->eof) 191 3 194
Condition100%3/3
not *$self->{"Transparent"} or $self->eof
l!l&&r!l&&!r
901013
MC/DC100%2/2
not *$self->{"Transparent"} or $self->eof
not *$self->{"Transparent"} $self->eof
Truth table100%3/3
not(A) or B
A= not *$self->{"Transparent"}B= $self->eof
ABresult
1X1
011
000
1082 {
1083 191 *$self->{EndStream} = 1 ;
1084 191 return 0;
1085 }
1086  
1087 # Not EOF, so Transparent mode kicks in now for trailing data
1088 # Reset member name in case anyone calls getHeaderInfo()->{Name}
1089 3 *$self->{Info} = { Name => undef, Type => 'plain' };
1090  
1091 3 $self->clearError();
1092 3 *$self->{Type} = 'plain';
1093 3 *$self->{Plain} = 1;
1094 3 $self->pushBack(*$self->{HeaderPending}) ;
1095 }
1096 else
1097 {
1098 1581 *$self->{Info} = $self->readHeader($magic);
1099  
1100 1581 ▶ if ( ! defined *$self->{Info} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined *$self->{"Info"}) 0 1581 1581
1101 0 *$self->{EndStream} = 1 ;
1102 0 return -1;
1103 }
1104 }
1105  
1106 1584 push @{ *$self->{InfoList} }, *$self->{Info} ;
1107  
1108 1584 return 1;
1109 }
1110  
1111 sub streamCount
1112 1260 ▶{
Subroutine streamCount: called CC=2 SCAR=7.0
Pod undocumented
1113 1260 my $self = shift ;
1114 1260 ▶ return 1 if ! defined *$self->{InfoList};
Branch: 1 branch
BranchTrueFalseTotal
unless defined *$self->{"InfoList"} 0 1260 1260
1115 1260 return scalar @{ *$self->{InfoList} } ;
1116 }
1117  
1118 sub read
1119 332839 ▶{
Subroutine read: called CC=30 SCAR=34.0
Pod undocumented
1120 # return codes
1121 # >0 - ok, number of bytes read
1122 # =0 - ok, eof
1123 # <0 - not ok
1124  
1125 332839 my $self = shift ;
1126  
1127 332839 ▶ if (defined *$self->{ReadStatus} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{"ReadStatus"}) 6 332833 332839
1128 6 my $status = *$self->{ReadStatus}[0];
1129 6 $self->saveErrorString( @{ *$self->{ReadStatus} } );
1130 6 delete *$self->{ReadStatus} ;
1131 6 return $status ;
1132 }
1133  
1134 332833 ▶ return G_EOF if *$self->{Closed} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Closed"} 10 332823 332833
1135  
1136 332823 my $buffer ;
1137  
1138 332823 ▶ if (ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 4723 328100 332823
1139 $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only")
1140 4723 ▶ if Scalar::Util::readonly(${ $_[0] });
Branch: 1 branch
BranchTrueFalseTotal
if &Scalar::Util::readonly(${$_[0];}) 0 4723 4723
1141  
1142 4723 ▶ $self->croakError(*$self->{ClassName} . "::read: not a scalar reference $_[0]" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "SCALAR" 0 4723 4723
1143 unless ref $_[0] eq 'SCALAR' ;
1144 4723 $buffer = $_[0] ;
1145 }
1146 else {
1147 328100 ▶ $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only")
Branch: 1 branch
BranchTrueFalseTotal
if &Scalar::Util::readonly($_[0]) 5 328095 328100
1148 if Scalar::Util::readonly($_[0]);
1149  
1150 328095 $buffer = \$_[0] ;
1151 }
1152  
1153 332818 my $length = $_[1] ;
1154 332818 ▶ my $offset = $_[2] || 0;
Condition100%2/2
$_[2] || 0
l!l
35332783
MC/DC100%1/1
$_[2] || 0
$_[2]
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
1155  
1156 332818 ▶ if (! *$self->{AppendOutput}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not *$self->{'AppendOutput'}) { } 161661 171157 332818
elsif (not defined $$buffer) { } 2256 168901 171157
1157 161661 ▶ if (! $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $offset) { } 161626 35 161661
1158  
1159 161626 $$buffer = '' ;
1160 }
1161 else {
1162 35 ▶ if ($offset > length($$buffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset > length $$buffer) { } 10 25 35
1163 10 $$buffer .= "\x00" x ($offset - length($$buffer));
1164 }
1165 else {
1166 25 substr($$buffer, $offset) = '';
1167 }
1168 }
1169 }
1170 elsif (! defined $$buffer) {
1171 2256 $$buffer = '' ;
1172 }
1173  
1174 332818 ▶ return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
Branch: 1 branch
BranchTrueFalseTotal
if not length *$self->{"Pending"} and *$self->{"EndStream"} 3286 329532 332818
Condition100%3/3
not length *$self->{"Pending"} and *$self->{"EndStream"}
!ll&&!rl&&r
32551940133286
MC/DC100%2/2
not length *$self->{"Pending"} and *$self->{"EndStream"}
not length *$self->{"Pending"} *$self->{"EndStream"}
Truth table100%3/3
not(A) and B
A= not length *$self->{"Pending"}B= *$self->{"EndStream"}
ABresult
0X0
100
111
1175  
1176 # the core read will return 0 if asked for 0 bytes
1177 329532 ▶ return 0 if defined $length && $length == 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $length and $length == 0 20 329512 329532
Condition100%3/3
defined $length and $length == 0
!ll&&!rl&&r
708432242820
MC/DC100%2/2
defined $length and $length == 0
defined $length $length == 0
Truth table100%3/3
A and B
A= defined $lengthB= $length == 0
ABresult
0X0
100
111
1178  
1179 329512 ▶ $length = $length || 0;
Condition100%2/2
$length || 0
l!l
3224287084
MC/DC100%1/1
$length || 0
$length
Truth table100%2/2
A
A= $length
Aresult
11
00
1180  
1181 329512 ▶ $self->croakError(*$self->{ClassName} . "::read: length parameter is negative")
Branch: 1 branch
BranchTrueFalseTotal
if $length < 0 5 329507 329512
1182 if $length < 0 ;
1183  
1184 # Short-circuit if this is a simple read, with no length
1185 # or offset specified.
1186 329507 ▶ unless ( $length || $offset) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($length or $offset) 7084 322423 329507
Condition66%2/3
$length or $offset
l!l&&r!l&&!r
32242307084
MC/DC50%1/2
$length or $offset
$length $offset
Truth table66%2/3
A or B
A= $lengthB= $offset
ABresult
1X1
011
000
1187 7084 ▶ if (length *$self->{Pending}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length *$self->{'Pending'}) { } 3457 3627 7084
1188 3457 $$buffer .= *$self->{Pending} ;
1189 3457 my $len = length *$self->{Pending};
1190 3457 *$self->{Pending} = '' ;
1191 3457 return $len ;
1192 }
1193 else {
1194 3627 my $len = 0;
1195 $len = $self->_raw_read($buffer)
1196 3627 ▶ while ! *$self->{EndStream} && $len == 0 ;
Branch: 1 branch
BranchTrueFalseTotal
not *$self->{"EndStream"} and $len == 0 and do { $len = $self->_raw_read($buffer) } 4078 3627 7705
Condition100%3/3
not *$self->{"EndStream"} and $len == 0
!ll&&!rl&&r
27079204078
MC/DC100%2/2
not *$self->{"EndStream"} and $len == 0
not *$self->{"EndStream"} $len == 0
Truth table100%3/3
not(A) and B
A= not *$self->{"EndStream"}B= $len == 0
ABresult
0X0
100
111
1197 3627 return $len ;
1198 }
1199 }
1200  
1201 # Need to jump through more hoops - either length or offset
1202 # or both are specified.
1203 322423 my $out_buffer = *$self->{Pending} ;
1204 322423 *$self->{Pending} = '';
1205  
1206  
1207 322423 ▶ while (! *$self->{EndStream} && length($out_buffer) < $length)
Branch: 1 branch
BranchTrueFalseTotal
if (not *$self->{"EndStream"} and length $out_buffer < $length) 2494 322423 324917
Condition100%3/3
not *$self->{"EndStream"} and length $out_buffer < $length
!ll&&!rl&&r
958132266102494
MC/DC100%2/2
not *$self->{"EndStream"} and length $out_buffer < $length
not *$self->{"EndStream"} length $out_buffer < $length
Truth table100%3/3
not(A) and B
A= not *$self->{"EndStream"}B= length $out_buffer < $length
ABresult
0X0
100
111
1208 {
1209 2494 my $buf_len = $self->_raw_read(\$out_buffer);
1210 2494 ▶ return $buf_len
Branch: 1 branch
BranchTrueFalseTotal
if $buf_len < 0 0 2494 2494
1211 if $buf_len < 0 ;
1212 }
1213  
1214 322423 ▶ $length = length $out_buffer
Branch: 1 branch
BranchTrueFalseTotal
if length $out_buffer < $length 787 321636 322423
1215 if length($out_buffer) < $length ;
1216  
1217 322423 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if $length == 0 110 322313 322423
1218 if $length == 0 ;
1219  
1220 322313 ▶ $$buffer = ''
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$buffer 0 322313 322313
1221 if ! defined $$buffer;
1222  
1223 $offset = length $$buffer
1224 322313 ▶ if *$self->{AppendOutput} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"AppendOutput"} 161609 160704 322313
1225  
1226 322313 *$self->{Pending} = $out_buffer;
1227 322313 $out_buffer = \*$self->{Pending} ;
1228  
1229 322313 substr($$buffer, $offset) = substr($$out_buffer, 0, $length) ;
1230 322313 substr($$out_buffer, 0, $length) = '' ;
1231  
1232 322313 return $length ;
1233 }
1234  
1235 sub _getline
1236 1525 ▶{
Subroutine _getline: called CC=11 SCAR=24.0
1237 1525 my $self = shift ;
1238 1525 my $status = 0 ;
1239  
1240 # Slurp Mode
1241 1525 ▶ if ( ! defined $/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $/) 55 1470 1525
1242 55 my $data ;
1243 55 ▶ 1 while ($status = $self->read($data)) > 0 ;
Branch: 1 branch
BranchTrueFalseTotal
($status = $self->read($data)) > 0 and do { '???' } 54 55 109
1244 55 return ($status, \$data);
1245 }
1246  
1247 # Record Mode
1248 1470 ▶ if ( ref $/ eq 'SCALAR' && ${$/} =~ /^\d+$/ && ${$/} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $/ eq "SCALAR" and ${$/;} =~ /^\d+$/ and ${$/;} > 0) 85 1385 1470
Condition66%4/6
ref $/ eq "SCALAR" and ${$/;} =~ /^\d+$/ and ${$/;} > 0
!ll&&!rl&&r
1385085
ref $/ eq "SCALAR" and ${$/;} =~ /^\d+$/
!ll&&!rl&&r
1385085
MC/DC33%1/3
ref $/ eq "SCALAR" and ${$/;} =~ /^\d+$/ and ${$/;} > 0
ref $/ eq "SCALAR" ${$/;} =~ /^\d+$/ ${$/;} > 0
Truth table50%2/4
A and B and C
A= ref $/ eq "SCALAR"B= ${$/;} =~ /^\d+$/C= ${$/;} > 0
ABCresult
0XX0
10X0
1100
1111
1249 85 my $reclen = ${$/} ;
1250 85 my $data ;
1251 85 $status = $self->read($data, $reclen) ;
1252 85 return ($status, \$data);
1253 }
1254  
1255 # Paragraph Mode
1256 1385 ▶ if ( ! length $/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $/) 60 1325 1385
1257 60 my $paragraph ;
1258 60 ▶ while (($status = $self->read($paragraph)) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($status = $self->read($paragraph)) > 0) 50 10 60
1259 50 ▶ if ($paragraph =~ s/^(.*?\n\n+)//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($paragraph =~ s/^(.*?\n\n+)//s) 50 0 50
1260 50 *$self->{Pending} = $paragraph ;
1261 50 my $par = $1 ;
1262 50 return (1, \$par);
1263 }
1264 }
1265 10 return ($status, \$paragraph);
1266 }
1267  
1268 # $/ isn't empty, or a reference, so it's Line Mode.
1269 {
1270 1325 my $line ;
1271 1325 my $p = \*$self->{Pending} ;
1272 1325 ▶ while (($status = $self->read($line)) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($status = $self->read($line)) > 0) 1320 38 1358
1273 1320 my $offset = index($line, $/);
1274 1320 ▶ if ($offset >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= 0) 1287 33 1320
1275 1287 my $l = substr($line, 0, $offset + length $/ );
1276 1287 substr($line, 0, $offset + length $/) = '';
1277 1287 $$p = $line;
1278 1287 return (1, \$l);
1279 }
1280 }
1281  
1282 38 return ($status, \$line);
1283 }
1284 }
1285  
1286 sub getline
1287 2086 ▶{
Subroutine getline: called CC=7 SCAR=20.4
Pod documented
1288 2086 my $self = shift;
1289  
1290 2086 ▶ if (defined *$self->{ReadStatus} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{"ReadStatus"}) 0 2086 2086
1291 0 $self->saveErrorString( @{ *$self->{ReadStatus} } );
1292 0 delete *$self->{ReadStatus} ;
1293 0 return undef;
1294 }
1295  
1296 return undef
1297 2086 ▶ if *$self->{Closed} || (!length *$self->{Pending} && *$self->{EndStream}) ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Closed"} or not length *$self->{"Pending"} and *$self->{"EndStream"} 561 1525 2086
Condition83%5/6
*$self->{"Closed"} or not length *$self->{"Pending"} and *$self->{"EndStream"}
l!l&&r!l&&!r
05611525
not length *$self->{"Pending"} and *$self->{"EndStream"}
!ll&&!rl&&r
1293232561
MC/DC66%2/3
*$self->{"Closed"} or not length *$self->{"Pending"} and *$self->{"EndStream"}
*$self->{"Closed"} not length *$self->{"Pending"} *$self->{"EndStream"}
Truth table75%3/4
A or not(B) and C
A= *$self->{"Closed"}B= not length *$self->{"Pending"}C= *$self->{"EndStream"}
ABCresult
1XX1
0111
00X0
0100
1298  
1299 1525 my $current_append = *$self->{AppendOutput} ;
1300 1525 *$self->{AppendOutput} = 1;
1301  
1302 1525 my ($status, $lineref) = $self->_getline();
1303 1525 *$self->{AppendOutput} = $current_append;
1304  
1305 return undef
1306 1525 ▶ if $status < 0 || length $$lineref == 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 or length $$lineref == 0 28 1497 1525
Condition66%2/3
$status < 0 or length $$lineref == 0
l!l&&r!l&&!r
0281497
MC/DC50%1/2
$status < 0 or length $$lineref == 0
$status < 0 length $$lineref == 0
Truth table66%2/3
A or B
A= $status < 0B= length $$lineref == 0
ABresult
1X1
011
000
1307  
1308 1497 $. = ++ *$self->{LineNo} ;
1309  
1310 1497 return $$lineref ;
1311 }
1312  
1313 sub getlines
1314 110 ▶{
Subroutine getlines: called CC=3 SCAR=11.0
Pod documented
1315 110 my $self = shift;
1316 $self->croakError(*$self->{ClassName} .
1317 110 ▶ "::getlines: called in scalar context\n") unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 110 110
1318 110 my($line, @lines);
1319 110 ▶ push(@lines, $line)
Branch: 1 branch
BranchTrueFalseTotal
defined($line = $self->getline) and do { push @lines, $line } 305 110 415
1320 while defined($line = $self->getline);
1321 110 return @lines;
1322 }
1323  
1324 sub READLINE
1325 193 ▶{
Subroutine READLINE: called CC=2 SCAR=6.9
1326 193 ▶ goto &getlines if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 30 163 193
1327 163 goto &getline;
1328 }
1329  
1330 sub getc
1331 105 ▶{
Subroutine getc: called CC=2 SCAR=6.9
Pod undocumented
1332 105 my $self = shift;
1333 105 my $buf;
1334 105 ▶ return $buf if $self->read($buf, 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->read($buf, 1) 60 45 105
1335 45 return undef;
1336 }
1337  
1338 sub ungetc
1339 2944 ▶{
Subroutine ungetc: called CC=2 SCAR=7.1
Pod documented
1340 2944 my $self = shift;
1341 2944 ▶ *$self->{Pending} = "" unless defined *$self->{Pending} ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined *$self->{"Pending"} 0 2944 2944
1342 2944 *$self->{Pending} = $_[0] . *$self->{Pending} ;
1343 }
1344  
1345  
1346 sub trailingData
1347 34 ▶{
Subroutine trailingData: called CC=3 SCAR=11.0
Pod undocumented
1348 34 my $self = shift ;
1349  
1350 34 ▶ if (defined *$self->{FH} || defined *$self->{InputEvent} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{'FH'} or defined *$self->{'InputEvent'}) { } 24 10 34
Condition66%2/3
defined *$self->{"FH"} or defined *$self->{"InputEvent"}
l!l&&r!l&&!r
24010
MC/DC50%1/2
defined *$self->{"FH"} or defined *$self->{"InputEvent"}
defined *$self->{"FH"} defined *$self->{"InputEvent"}
Truth table66%2/3
A or B
A= defined *$self->{"FH"}B= defined *$self->{"InputEvent"}
ABresult
1X1
011
000
1351 24 return *$self->{Prime} ;
1352 }
1353 else {
1354 10 my $buf = *$self->{Buffer} ;
1355 10 my $offset = *$self->{BufferOffset} ;
1356 10 return substr($$buf, $offset) ;
1357 }
1358 }
1359  
1360  
1361 sub eof
1362 2724 ▶{
Subroutine eof: called CC=4 SCAR=13.9
Pod undocumented
1363 2724 my $self = shift ;
1364  
1365 return (*$self->{Closed} ||
1366 (!length *$self->{Pending}
1367 2724 ▶ && ( $self->smartEof() || *$self->{EndStream}))) ;
Condition100%9/9
*$self->{'Closed'} || !length(*$self->{'Pending'}) && ($self->smartEof || *$self->{'EndStream'})
l!l&&r!l&&!r
692269386
not length *$self->{"Pending"} and $self->smartEof || *$self->{"EndStream"}
!ll&&!rl&&r
326602269
$self->smartEof or *$self->{"EndStream"}
l!l&&r!l&&!r
182444560
MC/DC100%4/4
*$self->{'Closed'} || !length(*$self->{'Pending'}) && ($self->smartEof || *$self->{'EndStream'})
*$self->{'Closed'} not length *$self->{"Pending"} $self->smartEof *$self->{"EndStream"}
Truth table100%5/5
A || not(B) and C or D
A= *$self->{'Closed'}B= not length *$self->{"Pending"}C= $self->smartEofD= *$self->{"EndStream"}
ABCDresult
1XXX1
011X1
01011
00XX0
01000
1368 }
1369  
1370 sub tell
1371 1133 ▶{
Subroutine tell: called CC=3 SCAR=11.0
Pod documented
1372 1133 my $self = shift ;
1373  
1374 1133 my $in ;
1375 1133 ▶ if (*$self->{Plain}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'Plain'}) { } 250 883 1133
1376 250 $in = *$self->{PlainBytesRead} ;
1377 }
1378 else {
1379 883 $in = *$self->{TotalInflatedBytesRead} ;
1380 }
1381  
1382 1133 my $pending = length *$self->{Pending} ;
1383  
1384 1133 ▶ return 0 if $pending > $in ;
Branch: 1 branch
BranchTrueFalseTotal
if $pending > $in 36 1097 1133
1385 1097 return $in - $pending ;
1386 }
1387  
1388 sub close
1389 6357 ▶{
Subroutine close: called CC=9 SCAR=22.3
Pod undocumented
1390 # todo - what to do if close is called before the end of the gzip file
1391 # do we remember any trailing data?
1392 6357 my $self = shift ;
1393  
1394 6357 ▶ return 1 if *$self->{Closed} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Closed"} 2751 3606 6357
1395  
1396 3606 ▶ untie *$self
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008" 3606 0 3606
1397 if $] >= 5.008 ;
1398  
1399 3606 my $status = 1 ;
1400  
1401 3606 ▶ if (defined *$self->{FH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{"FH"}) 2155 1451 3606
1402 2155 ▶ if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) {
Branch: 1 branch
BranchTrueFalseTotal
if (!*$self->{"Handle"} || *$self->{"AutoClose"} and not *$self->{"StdIO"}) 1962 193 2155
Condition83%5/6
!*$self->{"Handle"} || *$self->{"AutoClose"} and not *$self->{"StdIO"}
!ll&&!rl&&r
19301962
not *$self->{"Handle"} or *$self->{"AutoClose"}
l!l&&r!l&&!r
1693269193
MC/DC66%2/3
!*$self->{"Handle"} || *$self->{"AutoClose"} and not *$self->{"StdIO"}
not *$self->{"Handle"} *$self->{"AutoClose"} not *$self->{"StdIO"}
Truth table60%3/5
not(A) or B and not(C)
A= not *$self->{"Handle"}B= *$self->{"AutoClose"}C= not *$self->{"StdIO"}
ABCresult
00X0
1X00
0100
1X11
0111
1403 1962 local $.;
1404 1962 $! = 0 ;
1405 1962 $status = *$self->{FH}->close();
1406 return $self->saveErrorString(0, $!, $!)
1407 1962 ▶ if !*$self->{InNew} && $self->saveStatus($!) != 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if not *$self->{"InNew"} and $self->saveStatus($!) != 0 0 1962 1962
Condition33%1/3
not *$self->{"InNew"} and $self->saveStatus($!) != 0
!ll&&!rl&&r
019620
MC/DC0%0/2
not *$self->{"InNew"} and $self->saveStatus($!) != 0
not *$self->{"InNew"} $self->saveStatus($!) != 0
Truth table33%1/3
not(A) and B
A= not *$self->{"InNew"}B= $self->saveStatus($!) != 0
ABresult
0X0
100
111
1408 }
1409 2155 delete *$self->{FH} ;
1410 2155 $! = 0 ;
1411 }
1412 3606 *$self->{Closed} = 1 ;
1413  
1414 3606 return 1;
1415 }
1416  
1417 sub DESTROY
1418 4407 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
1419 4407 my $self = shift ;
1420 4407 local ($., $@, $!, $^E, $?);
1421  
1422 4407 $self->close() ;
1423 }
1424  
1425 sub seek
1426 106 ▶{
Subroutine seek: called CC=11 SCAR=24.0
Pod documented
1427 106 my $self = shift ;
1428 106 my $position = shift;
1429 106 my $whence = shift ;
1430  
1431 106 my $here = $self->tell() ;
1432 106 my $target = 0 ;
1433  
1434  
1435 106 ▶ if ($whence == SEEK_SET) {
Branch: 3 branches
BranchTrueFalseTotal
if ($whence == 0) { } 21 85 106
elsif ($whence == 1) { } 63 22 85
elsif ($whence == 2) { } 11 11 22
1436 21 $target = $position ;
1437 }
1438 elsif ($whence == SEEK_CUR) {
1439 63 $target = $here + $position ;
1440 }
1441 elsif ($whence == SEEK_END) {
1442 11 $target = $position ;
1443 11 $self->croakError(*$self->{ClassName} . "::seek: SEEK_END not allowed") ;
1444 }
1445 else {
1446 11 $self->croakError(*$self->{ClassName} ."::seek: unknown value, $whence, for whence parameter");
1447 }
1448  
1449 # short circuit if seeking to current offset
1450 84 ▶ if ($target == $here) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target == $here) 26 58 84
1451 # On ordinary filehandles, seeking to the current
1452 # position also clears the EOF condition, so we
1453 # emulate this behavior locally while simultaneously
1454 # cascading it to the underlying filehandle
1455 26 ▶ if (*$self->{Plain}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"Plain"}) 10 16 26
1456 10 *$self->{EndStream} = 0;
1457 10 ▶ seek(*$self->{FH},0,1) if *$self->{FH};
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"FH"} 5 5 10
1458 }
1459 26 return 1;
1460 }
1461  
1462 # Outlaw any attempt to seek backwards
1463 58 ▶ $self->croakError( *$self->{ClassName} ."::seek: cannot seek backwards")
Branch: 1 branch
BranchTrueFalseTotal
if $target < $here 11 47 58
1464 if $target < $here ;
1465  
1466 # Walk the file to the new offset
1467 47 my $offset = $target - $here ;
1468  
1469 47 my $got;
1470 47 ▶ while (($got = $self->read(my $buffer, List::Util::min($offset, *$self->{BlockSize})) ) > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (($got = $self->read(my $buffer, &List::Util::min($offset, *$self->{"BlockSize"}))) > 0) 47 0 47
1471 {
1472 47 $offset -= $got;
1473 47 ▶ last if $offset == 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if $offset == 0 47 0 47
1474 }
1475  
1476 47 $here = $self->tell() ;
1477 47 ▶ return $offset == 0 ? 1 : 0 ;
Branch: 1 branch
BranchTrueFalseTotal
$offset == 0 ? : 47 0 47
1478 }
1479  
1480 sub fileno
1481 35 ▶{
Subroutine fileno: called CC=2 SCAR=6.9
Pod undocumented
1482 35 my $self = shift ;
1483 return defined *$self->{FH}
1484 ? fileno *$self->{FH}
1485 35 ▶ : undef ;
Branch: 1 branch
BranchTrueFalseTotal
defined *$self->{'FH'} ? : 30 5 35
1486 }
1487  
1488 sub binmode
1489 5 ▶{
Subroutine binmode: called CC=1 SCAR=0.0
Pod documented
1490 5 1;
1491 # my $self = shift ;
1492 # return defined *$self->{FH}
1493 # ? binmode *$self->{FH}
1494 # : 1 ;
1495 }
1496  
1497 sub opened
1498 10 ▶{
Subroutine opened: called CC=1 SCAR=0.0
Pod documented
1499 10 my $self = shift ;
1500 10 return ! *$self->{Closed} ;
1501 }
1502  
1503 sub autoflush
1504 10 ▶{
Subroutine autoflush: called CC=2 SCAR=7.2
Pod undocumented
1505 10 my $self = shift ;
1506 return defined *$self->{FH}
1507 10 ▶ ? *$self->{FH}->autoflush(@_)
Branch: 1 branch
BranchTrueFalseTotal
defined *$self->{'FH'} ? : 0 10 10
1508 : undef ;
1509 }
1510  
1511 sub input_line_number
1512 80 ▶{
Subroutine input_line_number: called CC=2 SCAR=7.0
Pod undocumented
1513 80 my $self = shift ;
1514 80 my $last = *$self->{LineNo};
1515 80 ▶ $. = *$self->{LineNo} = $_[1] if @_ ;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 80 80
1516 80 return $last;
1517 }
1518  
1519 sub _notAvailable
1520 600 ▶{
Subroutine _notAvailable: called CC=1 SCAR=0.0
1521 600 my $name = shift ;
1522 600 ▶ return sub { croak "$name Not Available: File opened only for intput" ; } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
1523 }
1524  
1525 {
1526 100 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1527  
1528 100 *BINMODE = \&binmode;
1529 100 *SEEK = \&seek;
1530 100 *READ = \&read;
1531 100 *sysread = \&read;
1532 100 *TELL = \&tell;
1533 100 *EOF = \&eof;
1534  
1535 100 *FILENO = \&fileno;
1536 100 *CLOSE = \&close;
1537  
1538 100 *print = _notAvailable('print');
1539 100 *PRINT = _notAvailable('print');
1540 100 *printf = _notAvailable('printf');
1541 100 *PRINTF = _notAvailable('printf');
1542 100 *write = _notAvailable('write');
1543 100 *WRITE = _notAvailable('write');
1544  
1545 #*sysread = \&read;
1546 #*syswrite = \&_notAvailable;
1547 }
1548  
1549  
1550  
1551 package IO::Uncompress::Base ;
1552  
1553  
1554 100 1 ;
1555 __END__
« blib/lib/IO/Uncompress/Gunzip.pm ↑ Summary blib/lib/IO/Compress/Gzip.pm »