blib/lib/IO/Compress/Base/Common.pm

filter: Statementstmt 94.5% 449 / 475 Branchbran 83.1% 163 / 196 Conditioncond 77.3% 106 / 137 MC/DCmcdc 58.2% 46 / 79 Subroutinesub 95.8% 93 / 97 Podpod 0.0% 0 / 17 totaltotal 85.6% 857 / 1001 CC 149 SCAR 23.5
CC
149
Cov
89%
new
27.3
_checkType
26.3
Init
20.0
CRAP 10.5
« blib/lib/File/GlobMapper.pm ↑ Summary blib/lib/Compress/Zlib.pm »
1 package IO::Compress::Base::Common;
2  
3 130 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 130 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 130 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 130 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 130 ▶use Scalar::Util qw(blessed readonly);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 130 ▶use File::GlobMapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 130 require Exporter;
12 130 our ($VERSION, @ISA, @EXPORT, %EXPORT_TAGS, $HAS_ENCODE);
13 130 @ISA = qw(Exporter);
14 130 $VERSION = '2.223';
15  
16 130 @EXPORT = qw( isaFilehandle isaFilename isaScalar
17 whatIsInput whatIsOutput
18 isaFileGlobString cleanFileGlobString oneTarget
19 setBinModeInput setBinModeOutput
20 ckInOutParams
21 createSelfTiedObject
22  
23 isGeMax32
24  
25 MAX32
26  
27 WANT_CODE
28 WANT_EXT
29 WANT_UNDEF
30 WANT_HASH
31  
32 STATUS_OK
33 STATUS_ENDSTREAM
34 STATUS_EOF
35 STATUS_ERROR
36 );
37  
38 130 %EXPORT_TAGS = ( Status => [qw( STATUS_OK
39 STATUS_ENDSTREAM
40 STATUS_EOF
41 STATUS_ERROR
42 )]);
43  
44  
45 130 ▶use constant STATUS_OK => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 130 ▶use constant STATUS_ENDSTREAM => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 130 ▶use constant STATUS_EOF => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 130 ▶use constant STATUS_ERROR => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 130 ▶use constant MAX16 => 0xFFFF ;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 130 ▶use constant MAX32 => 0xFFFFFFFF ;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 130 ▶use constant MAX32cmp => 0xFFFFFFFF + 1 - 1; # for 5.6.x on 32-bit need to force an non-IV value
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53  
54 sub isGeMax32
55 {
56 184 ▶ return $_[0] >= MAX32cmp ;
Subroutine isGeMax32: called CC=1 SCAR=0.0
Pod undocumented
57 }
58  
59 sub hasEncode()
60 {
61 20 ▶ if (! defined $HAS_ENCODE) {
Subroutine hasEncode: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $IO::Compress::Base::Common::HAS_ENCODE) 5 15 20
62 eval
63 5 {
64 5 require Encode;
65 5 Encode->import();
66 };
67  
68 5 ▶ $HAS_ENCODE = $@ ? 0 : 1 ;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 5 5
69 }
70  
71 20 return $HAS_ENCODE;
72 }
73  
74 sub getEncoding($$$)
75 {
76 20 ▶ my $obj = shift;
Subroutine getEncoding: called CC=3 SCAR=11.0
Pod undocumented
77 20 my $class = shift ;
78 20 my $want_encoding = shift ;
79  
80 20 ▶ $obj->croakError("$class: Encode module needed to use -Encode")
Branch: 1 branch
BranchTrueFalseTotal
unless &hasEncode() 0 20 20
81 if ! hasEncode();
82  
83 20 my $encoding = Encode::find_encoding($want_encoding);
84  
85 20 ▶ $obj->croakError("$class: Encoding '$want_encoding' is not available")
Branch: 1 branch
BranchTrueFalseTotal
unless $encoding 5 15 20
86 if ! $encoding;
87  
88 15 return $encoding;
89 }
90  
91 130 our ($needBinmode);
92 130 ▶$needBinmode = ($^O eq 'MSWin32' ||
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' || $] >= 5.006 && eval ' ${^UNICODE} || ${^UTF8LOCALE} ' ? : 0 130 130
Condition33%2/6
$^O eq "MSWin32" or $] >= "5.006" and eval " \${^UNICODE} || \${^UTF8LOCALE} "
l!l&&r!l&&!r
00130
$] >= "5.006" and eval " \${^UNICODE} || \${^UTF8LOCALE} "
!ll&&!rl&&r
01300
MC/DC0%0/3
$^O eq "MSWin32" or $] >= "5.006" and eval " \${^UNICODE} || \${^UTF8LOCALE} "
$^O eq "MSWin32" $] >= "5.006" eval " \${^UNICODE} || \${^UTF8LOCALE} "
Truth table0%0/4
A or B and C
A= $^O eq "MSWin32"B= $] >= "5.006"C= eval " \${^UNICODE} || \${^UTF8LOCALE} "
ABCresult
1XX1
0111
00X0
0100
93 ($] >= 5.006 && eval ' ${^UNICODE} || ${^UTF8LOCALE} '))
94 ? 1 : 1 ;
95  
96 sub setBinModeInput($)
97 {
98 2193 ▶ my $handle = shift ;
Subroutine setBinModeInput: called CC=2 SCAR=7.2
Pod undocumented
99  
100 2193 ▶ binmode $handle
Branch: 1 branch
BranchTrueFalseTotal
if $IO::Compress::Base::Common::needBinmode 2193 0 2193
101 if $needBinmode;
102 }
103  
104 sub setBinModeOutput($)
105 {
106 1049 ▶ my $handle = shift ;
Subroutine setBinModeOutput: called CC=2 SCAR=7.2
Pod undocumented
107  
108 1049 ▶ binmode $handle
Branch: 1 branch
BranchTrueFalseTotal
if $IO::Compress::Base::Common::needBinmode 1049 0 1049
109 if $needBinmode;
110 }
111  
112 sub isaFilehandle($)
113 {
114 130 ▶ use utf8; # Pragma needed to keep Perl 5.6.0 happy
Subroutine BEGIN: called CC=1 SCAR=0.0
115 16647 ▶ return (defined $_[0] and
Subroutine isaFilehandle: called CC=4 SCAR=13.9
Pod undocumented
Condition88%8/9
defined $_[0] && (UNIVERSAL::isa($_[0], 'GLOB') || UNIVERSAL::isa($_[0], 'IO::Handle') || UNIVERSAL::isa(\$_[0], 'GLOB'))
!ll&&!rl&&r
20145282099
UNIVERSAL::isa($_[0], "GLOB") or UNIVERSAL::isa($_[0], "IO::Handle") or UNIVERSAL::isa(\$_[0], "GLOB")
l!l&&r!l&&!r
186723214528
UNIVERSAL::isa($_[0], "GLOB") or UNIVERSAL::isa($_[0], "IO::Handle")
l!l&&r!l&&!r
1867014760
MC/DC75%3/4
defined $_[0] && (UNIVERSAL::isa($_[0], 'GLOB') || UNIVERSAL::isa($_[0], 'IO::Handle') || UNIVERSAL::isa(\$_[0], 'GLOB'))
defined $_[0] UNIVERSAL::isa($_[0], "GLOB") UNIVERSAL::isa($_[0], "IO::Handle") UNIVERSAL::isa(\$_[0], "GLOB")
Truth table80%4/5
A && B or C or D
A= defined $_[0]B= UNIVERSAL::isa($_[0], "GLOB")C= UNIVERSAL::isa($_[0], "IO::Handle")D= UNIVERSAL::isa(\$_[0], "GLOB")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
116 (UNIVERSAL::isa($_[0],'GLOB') or
117 UNIVERSAL::isa($_[0],'IO::Handle') or
118 UNIVERSAL::isa(\$_[0],'GLOB'))
119 )
120 }
121  
122 sub isaScalar
123 {
124 1048 ▶ return ( defined($_[0]) and ref($_[0]) eq 'SCALAR' and defined ${ $_[0] } ) ;
Subroutine isaScalar: called CC=3 SCAR=11.0
Pod undocumented
Condition83%5/6
defined $_[0] && ref $_[0] eq 'SCALAR' && defined ${$_[0];}
!ll&&!rl&&r
70151296
defined $_[0] and ref $_[0] eq "SCALAR"
!ll&&!rl&&r
0701347
MC/DC66%2/3
defined $_[0] && ref $_[0] eq 'SCALAR' && defined ${$_[0];}
defined $_[0] ref $_[0] eq "SCALAR" defined ${$_[0];}
Truth table75%3/4
A and B && C
A= defined $_[0]B= ref $_[0] eq "SCALAR"C= defined ${$_[0];}
ABCresult
0XX0
10X0
1100
1111
125 }
126  
127 sub isaFilename($)
128 {
129 1495 ▶ return (defined $_[0] and
Subroutine isaFilename: called CC=3 SCAR=11.0
Pod undocumented
Condition100%6/6
defined $_[0] && !ref($_[0]) && UNIVERSAL::isa(\$_[0], 'SCALAR')
!ll&&!rl&&r
48061954
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
14791015
MC/DC100%3/3
defined $_[0] && !ref($_[0]) && UNIVERSAL::isa(\$_[0], 'SCALAR')
defined $_[0] not ref $_[0] UNIVERSAL::isa(\$_[0], 'SCALAR')
Truth table100%4/4
A and not(B) && C
A= defined $_[0]B= not ref $_[0]C= UNIVERSAL::isa(\$_[0], 'SCALAR')
ABCresult
0XX0
10X0
1100
1111
130 ! ref $_[0] and
131 UNIVERSAL::isa(\$_[0], 'SCALAR'));
132 }
133  
134 sub isaFileGlobString
135 {
136 1007 ▶ return defined $_[0] && $_[0] =~ /^<.*>$/;
Subroutine isaFileGlobString: called CC=2 SCAR=6.9
Pod undocumented
Condition100%3/3
defined $_[0] && $_[0] =~ /^<.*>$/
!ll&&!rl&&r
15797195
MC/DC100%2/2
defined $_[0] && $_[0] =~ /^<.*>$/
defined $_[0] $_[0] =~ /^<.*>$/
Truth table100%3/3
A && B
A= defined $_[0]B= $_[0] =~ /^<.*>$/
ABresult
0X0
100
111
137 }
138  
139 sub cleanFileGlobString
140 {
141 110 ▶ my $string = shift ;
Subroutine cleanFileGlobString: called CC=1 SCAR=0.0
Pod undocumented
142  
143 110 $string =~ s/^\s*<\s*(.*)\s*>\s*$/$1/;
144  
145 110 return $string;
146 }
147  
148 130 ▶use constant WANT_CODE => 1 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
149 130 ▶use constant WANT_EXT => 2 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
150 130 ▶use constant WANT_UNDEF => 4 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
151 #use constant WANT_HASH => 8 ;
152 130 ▶use constant WANT_HASH => 0 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
153  
154 sub whatIsInput($;$)
155 {
156 9121 ▶ my $got = whatIs(@_);
Subroutine whatIsInput: called CC=5 SCAR=16.1
Pod undocumented
157  
158 9121 ▶ if (defined $got && $got eq 'filename' && defined $_[0] && $_[0] eq '-')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $got and $got eq "filename" and defined $_[0] and $_[0] eq "-") 100 9021 9121
Condition88%8/9
defined $got and $got eq "filename" and defined $_[0] and $_[0] eq "-"
!ll&&!rl&&r
50104011100
defined $got and $got eq "filename" and defined $_[0]
!ll&&!rl&&r
4990204111
defined $got and $got eq "filename"
!ll&&!rl&&r
049904131
MC/DC75%3/4
defined $got and $got eq "filename" and defined $_[0] and $_[0] eq "-"
defined $got $got eq "filename" defined $_[0] $_[0] eq "-"
Truth table80%4/5
A and B and C and D
A= defined $gotB= $got eq "filename"C= defined $_[0]D= $_[0] eq "-"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
159 {
160 #use IO::File;
161 100 $got = 'handle';
162 100 $_[0] = *STDIN;
163 #$_[0] = IO::File->new("<-");
164 }
165  
166 9121 return $got;
167 }
168  
169 sub whatIsOutput($;$)
170 {
171 5355 ▶ my $got = whatIs(@_);
Subroutine whatIsOutput: called CC=5 SCAR=16.2
Pod undocumented
172  
173 5355 ▶ if (defined $got && $got eq 'filename' && defined $_[0] && $_[0] eq '-')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $got and $got eq "filename" and defined $_[0] and $_[0] eq "-") 24 5331 5355
Condition77%7/9
defined $got and $got eq "filename" and defined $_[0] and $_[0] eq "-"
!ll&&!rl&&r
3238209324
defined $got and $got eq "filename" and defined $_[0]
!ll&&!rl&&r
323802117
defined $got and $got eq "filename"
!ll&&!rl&&r
032382117
MC/DC50%2/4
defined $got and $got eq "filename" and defined $_[0] and $_[0] eq "-"
defined $got $got eq "filename" defined $_[0] $_[0] eq "-"
Truth table60%3/5
A and B and C and D
A= defined $gotB= $got eq "filename"C= defined $_[0]D= $_[0] eq "-"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
174 {
175 24 $got = 'handle';
176 24 $_[0] = *STDOUT;
177 #$_[0] = IO::File->new(">-");
178 }
179  
180 5355 return $got;
181 }
182  
183 sub whatIs ($;$)
184 {
185 14476 ▶ return 'handle' if isaFilehandle($_[0]);
Subroutine whatIs: called CC=19 SCAR=29.7
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if &isaFilehandle($_[0]) 1840 12636 14476
186  
187 12636 ▶ my $wantCode = defined $_[1] && $_[1] & WANT_CODE ;
Condition100%3/3
defined $_[1] && $_[1] & 1
!ll&&!rl&&r
361226496375
MC/DC100%2/2
defined $_[1] && $_[1] & 1
defined $_[1] $_[1] & 1
Truth table100%3/3
A && B
A= defined $_[1]B= $_[1] & 1
ABresult
0X0
100
111
188 12636 ▶ my $extended = defined $_[1] && $_[1] & WANT_EXT ;
Condition100%3/3
defined $_[1] && $_[1] & 2
!ll&&!rl&&r
361263752649
MC/DC100%2/2
defined $_[1] && $_[1] & 2
defined $_[1] $_[1] & 2
Truth table100%3/3
A && B
A= defined $_[1]B= $_[1] & 2
ABresult
0X0
100
111
189 12636 ▶ my $undef = defined $_[1] && $_[1] & WANT_UNDEF ;
Condition66%2/3
defined $_[1] && $_[1] & 4
!ll&&!rl&&r
361290240
MC/DC0%0/2
defined $_[1] && $_[1] & 4
defined $_[1] $_[1] & 4
Truth table66%2/3
A && B
A= defined $_[1]B= $_[1] & 4
ABresult
0X0
100
111
190 12636 ▶ my $hash = defined $_[1] && $_[1] & WANT_HASH ;
Condition66%2/3
defined $_[1] && $_[1] & 0
!ll&&!rl&&r
361290240
MC/DC0%0/2
defined $_[1] && $_[1] & 0
defined $_[1] $_[1] & 0
Truth table66%2/3
A && B
A= defined $_[1]B= $_[1] & 0
ABresult
0X0
100
111
191  
192 12636 ▶ return 'undef' if ! defined $_[0] && $undef ;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[0] and $undef 0 12636 12636
Condition66%2/3
not defined $_[0] and $undef
!ll&&!rl&&r
12616200
MC/DC0%0/2
not defined $_[0] and $undef
not defined $_[0] $undef
Truth table66%2/3
not(A) and B
A= not defined $_[0]B= $undef
ABresult
0X0
100
111
193  
194 12636 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) 6193 6443 12636
195 6193 ▶ return '' if blessed($_[0]); # is an object
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) 60 6133 6193
196 #return '' if UNIVERSAL::isa($_[0], 'UNIVERSAL'); # is an object
197 6133 ▶ return 'buffer' if UNIVERSAL::isa($_[0], 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "SCALAR") 5799 334 6133
198 334 ▶ return 'array' if UNIVERSAL::isa($_[0], 'ARRAY') && $extended ;
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "ARRAY") and $extended 290 44 334
Condition100%3/3
UNIVERSAL::isa($_[0], "ARRAY") and $extended
!ll&&!rl&&r
935290
MC/DC100%2/2
UNIVERSAL::isa($_[0], "ARRAY") and $extended
UNIVERSAL::isa($_[0], "ARRAY") $extended
Truth table100%3/3
A and B
A= UNIVERSAL::isa($_[0], "ARRAY")B= $extended
ABresult
0X0
100
111
199 44 ▶ return 'hash' if UNIVERSAL::isa($_[0], 'HASH') && $hash ;
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "HASH") and $hash 0 44 44
Condition33%1/3
UNIVERSAL::isa($_[0], "HASH") and $hash
!ll&&!rl&&r
4400
MC/DC0%0/2
UNIVERSAL::isa($_[0], "HASH") and $hash
UNIVERSAL::isa($_[0], "HASH") $hash
Truth table33%1/3
A and B
A= UNIVERSAL::isa($_[0], "HASH")B= $hash
ABresult
0X0
100
111
200 44 ▶ return 'code' if UNIVERSAL::isa($_[0], 'CODE') && $wantCode ;
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "CODE") and $wantCode 2 42 44
Condition100%3/3
UNIVERSAL::isa($_[0], "CODE") and $wantCode
!ll&&!rl&&r
3572
MC/DC100%2/2
UNIVERSAL::isa($_[0], "CODE") and $wantCode
UNIVERSAL::isa($_[0], "CODE") $wantCode
Truth table100%3/3
A and B
A= UNIVERSAL::isa($_[0], "CODE")B= $wantCode
ABresult
0X0
100
111
201 42 return '';
202 }
203  
204 6443 ▶ return 'fileglob' if $extended && isaFileGlobString($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if $extended and isaFileGlobString($_[0]) 195 6248 6443
Condition100%3/3
$extended and isaFileGlobString($_[0])
!ll&&!rl&&r
5436812195
MC/DC100%2/2
$extended and isaFileGlobString($_[0])
$extended isaFileGlobString($_[0])
Truth table100%3/3
A and B
A= $extendedB= isaFileGlobString($_[0])
ABresult
0X0
100
111
205 6248 return 'filename';
206 }
207  
208 sub oneTarget
209 {
210 3086 ▶ return $_[0] =~ /^(code|handle|buffer|filename)$/;
Subroutine oneTarget: called CC=1 SCAR=0.0
Pod undocumented
211 }
212  
213 sub IO::Compress::Base::Validator::new
214 {
215 1543 ▶ my $class = shift ;
Subroutine new: called CC=27 SCAR=33.1
216  
217 1543 my $Class = shift ;
218 1543 my $error_ref = shift ;
219 1543 my $reportClass = shift ;
220  
221 1543 my %data = (Class => $Class,
222 Error => $error_ref,
223 reportClass => $reportClass,
224 ) ;
225  
226 1543 my $obj = bless \%data, $class ;
227  
228 1543 local $Carp::CarpLevel = 1;
229  
230 1543 my $inType = $data{inType} = whatIsInput($_[0], WANT_EXT|WANT_HASH);
231 1543 my $outType = $data{outType} = whatIsOutput($_[1], WANT_EXT|WANT_HASH);
232  
233 1543 my $oneInput = $data{oneInput} = oneTarget($inType);
234 1543 my $oneOutput = $data{oneOutput} = oneTarget($outType);
235  
236 1543 ▶ if (! $inType)
Branch: 1 branch
BranchTrueFalseTotal
unless ($inType) 30 1513 1543
237 {
238 30 $obj->croakError("$reportClass: illegal input parameter") ;
239 #return undef ;
240 }
241  
242 # if ($inType eq 'hash')
243 # {
244 # $obj->{Hash} = 1 ;
245 # $obj->{oneInput} = 1 ;
246 # return $obj->validateHash($_[0]);
247 # }
248  
249 1513 ▶ if (! $outType)
Branch: 1 branch
BranchTrueFalseTotal
unless ($outType) 30 1483 1513
250 {
251 30 $obj->croakError("$reportClass: illegal output parameter") ;
252 #return undef ;
253 }
254  
255  
256 1483 ▶ if ($inType ne 'fileglob' && $outType eq 'fileglob')
Branch: 1 branch
BranchTrueFalseTotal
if ($inType ne "fileglob" and $outType eq "fileglob") 15 1468 1483
Condition100%3/3
$inType ne "fileglob" and $outType eq "fileglob"
!ll&&!rl&&r
145132315
MC/DC100%2/2
$inType ne "fileglob" and $outType eq "fileglob"
$inType ne "fileglob" $outType eq "fileglob"
Truth table100%3/3
A and B
A= $inType ne "fileglob"B= $outType eq "fileglob"
ABresult
0X0
100
111
257 {
258 15 $obj->croakError("Need input fileglob for outout fileglob");
259 }
260  
261 # if ($inType ne 'fileglob' && $outType eq 'hash' && $inType ne 'filename' )
262 # {
263 # $obj->croakError("input must ne filename or fileglob when output is a hash");
264 # }
265  
266 1468 ▶ if ($inType eq 'fileglob' && $outType eq 'fileglob')
Branch: 1 branch
BranchTrueFalseTotal
if ($inType eq "fileglob" and $outType eq "fileglob") 35 1433 1468
Condition100%3/3
$inType eq "fileglob" and $outType eq "fileglob"
!ll&&!rl&&r
132311035
MC/DC100%2/2
$inType eq "fileglob" and $outType eq "fileglob"
$inType eq "fileglob" $outType eq "fileglob"
Truth table100%3/3
A and B
A= $inType eq "fileglob"B= $outType eq "fileglob"
ABresult
0X0
100
111
267 {
268 35 $data{GlobMap} = 1 ;
269 35 $data{inType} = $data{outType} = 'filename';
270 35 my $mapper = File::GlobMapper->new($_[0], $_[1]);
271 35 ▶ if ( ! $mapper )
Branch: 1 branch
BranchTrueFalseTotal
unless ($mapper) 15 20 35
272 {
273 15 return $obj->saveErrorString($File::GlobMapper::Error) ;
274 }
275 20 $data{Pairs} = $mapper->getFileMap();
276  
277 20 return $obj;
278 }
279  
280 1433 ▶ $obj->croakError("$reportClass: input and output $inType are identical")
Branch: 1 branch
BranchTrueFalseTotal
if $inType eq $outType and $_[0] eq $_[1] and $_[0] ne "-" 45 1388 1433
Condition83%5/6
$inType eq $outType and $_[0] eq $_[1] and $_[0] ne "-"
!ll&&!rl&&r
1388045
$inType eq $outType and $_[0] eq $_[1]
!ll&&!rl&&r
95443445
MC/DC66%2/3
$inType eq $outType and $_[0] eq $_[1] and $_[0] ne "-"
$inType eq $outType $_[0] eq $_[1] $_[0] ne "-"
Truth table75%3/4
A and B and C
A= $inType eq $outTypeB= $_[0] eq $_[1]C= $_[0] ne "-"
ABCresult
0XX0
10X0
1100
1111
281 if $inType eq $outType && $_[0] eq $_[1] && $_[0] ne '-' ;
282  
283 1388 ▶ if ($inType eq 'fileglob') # && $outType ne 'fileglob'
Branch: 3 branches
BranchTrueFalseTotal
if ($inType eq 'fileglob') { } 110 1278 1388
elsif ($inType eq 'filename') { } 341 937 1278
elsif ($inType eq 'array') { } 175 762 937
284 {
285 110 my $glob = cleanFileGlobString($_[0]);
286 110 my @inputs = glob($glob);
287  
288 110 ▶ if (@inputs == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (@inputs == 0) { } 0 110 110
elsif (@inputs == 1) { } 35 75 110
289 {
290 # TODO -- legal or die?
291 0 die "globmap matched zero file -- legal or die???" ;
292 }
293 elsif (@inputs == 1)
294 {
295 35 ▶ $obj->validateInputFilenames($inputs[0])
Branch: 1 branch
BranchTrueFalseTotal
$obj->validateInputFilenames($inputs[0]) or return undef 0 35 35
296 or return undef;
297 35 $_[0] = $inputs[0] ;
298 35 $data{inType} = 'filename' ;
299 35 $data{oneInput} = 1;
300 }
301 else
302 {
303 75 ▶ $obj->validateInputFilenames(@inputs)
Branch: 1 branch
BranchTrueFalseTotal
$obj->validateInputFilenames(@inputs) or return undef 0 75 75
304 or return undef;
305 75 $_[0] = [ @inputs ] ;
306 75 $data{inType} = 'filenames' ;
307 }
308 }
309 elsif ($inType eq 'filename')
310 {
311 341 ▶ $obj->validateInputFilenames($_[0])
Branch: 1 branch
BranchTrueFalseTotal
$obj->validateInputFilenames($_[0]) or return undef 30 281 311
312 or return undef;
313 }
314 elsif ($inType eq 'array')
315 {
316 175 $data{inType} = 'filenames' ;
317 175 ▶ $obj->validateInputArray($_[0])
Branch: 1 branch
BranchTrueFalseTotal
$obj->validateInputArray($_[0]) or return undef 5 120 125
318 or return undef ;
319 }
320  
321 return $obj->saveErrorString("$reportClass: output buffer is read-only")
322 1273 ▶ if $outType eq 'buffer' && readonly(${ $_[1] });
Branch: 1 branch
BranchTrueFalseTotal
if $outType eq "buffer" and &readonly(${$_[1];}) 15 1258 1273
Condition100%3/3
$outType eq "buffer" and &readonly(${$_[1];})
!ll&&!rl&&r
67658215
MC/DC100%2/2
$outType eq "buffer" and &readonly(${$_[1];})
$outType eq "buffer" &readonly(${$_[1];})
Truth table100%3/3
A and B
A= $outType eq "buffer"B= &readonly(${$_[1];})
ABresult
0X0
100
111
323  
324 1258 ▶ if ($outType eq 'filename' )
Branch: 1 branch
BranchTrueFalseTotal
if ($outType eq "filename") 335 923 1258
325 {
326 335 ▶ $obj->croakError("$reportClass: output filename is undef or null string")
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[1] or $_[1] eq "" 0 335 335
Condition33%1/3
not defined $_[1] or $_[1] eq ""
l!l&&r!l&&!r
00335
MC/DC0%0/2
not defined $_[1] or $_[1] eq ""
not defined $_[1] $_[1] eq ""
Truth table33%1/3
not(A) or B
A= not defined $_[1]B= $_[1] eq ""
ABresult
1X1
011
000
327 if ! defined $_[1] || $_[1] eq '' ;
328  
329 335 ▶ if (-e $_[1])
Branch: 1 branch
BranchTrueFalseTotal
if (-e $_[1]) 156 179 335
330 {
331 156 ▶ if (-d _ )
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) 15 141 156
332 {
333 15 return $obj->saveErrorString("output file '$_[1]' is a directory");
334 }
335 }
336 }
337  
338 1243 return $obj ;
339 }
340  
341 sub IO::Compress::Base::Validator::saveErrorString
342 {
343 280 ▶ my $self = shift ;
Subroutine saveErrorString: called CC=1 SCAR=0.0
344 280 ${ $self->{Error} } = shift ;
345 280 return undef;
346  
347 }
348  
349 sub IO::Compress::Base::Validator::croakError
350 {
351 200 ▶ my $self = shift ;
Subroutine croakError: called CC=1 SCAR=0.0
352 200 $self->saveErrorString($_[0]);
353 200 croak $_[0];
354 }
355  
356  
357  
358 sub IO::Compress::Base::Validator::validateInputFilenames
359 {
360 671 ▶ my $self = shift ;
Subroutine validateInputFilenames: called CC=7 SCAR=19.5
361  
362 671 foreach my $filename (@_)
363 {
364 821 ▶ $self->croakError("$self->{reportClass}: input filename is undef or null string")
Branch: 1 branch
BranchTrueFalseTotal
if not defined $filename or $filename eq "" 40 781 821
Condition100%3/3
not defined $filename or $filename eq ""
l!l&&r!l&&!r
2020781
MC/DC100%2/2
not defined $filename or $filename eq ""
not defined $filename $filename eq ""
Truth table100%3/3
not(A) or B
A= not defined $filenameB= $filename eq ""
ABresult
1X1
011
000
365 if ! defined $filename || $filename eq '' ;
366  
367 781 ▶ next if $filename eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq "-" 0 781 781
368  
369 781 ▶ if (! -e $filename )
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $filename) 15 766 781
370 {
371 15 return $self->saveErrorString("input file '$filename' does not exist");
372 }
373  
374 766 ▶ if (-d _ )
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) 15 751 766
375 {
376 15 return $self->saveErrorString("input file '$filename' is a directory");
377 }
378  
379 # if (! -r _ )
380 # {
381 # return $self->saveErrorString("cannot open file '$filename': $!");
382 # }
383 }
384  
385 601 return 1 ;
386 }
387  
388 sub IO::Compress::Base::Validator::validateInputArray
389 {
390 175 ▶ my $self = shift ;
Subroutine validateInputArray: called CC=6 SCAR=17.9
391  
392 175 ▶ if ( @{ $_[0] } == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$_[0];} == 0) 5 170 175
393 {
394 5 return $self->saveErrorString("empty array reference") ;
395 }
396  
397 170 foreach my $element ( @{ $_[0] } )
398 {
399 260 my $inType = whatIsInput($element);
400  
401 260 ▶ if (! $inType)
Branch: 2 branches
BranchTrueFalseTotal
if (not $inType) { } 20 240 260
elsif ($inType eq 'filename') { } 220 20 240
402 {
403 20 $self->croakError("unknown input parameter") ;
404 }
405 elsif($inType eq 'filename')
406 {
407 220 ▶ $self->validateInputFilenames($element)
Branch: 1 branch
BranchTrueFalseTotal
$self->validateInputFilenames($element) or return undef 0 210 210
408 or return undef ;
409 }
410 else
411 {
412 20 $self->croakError("not a filename") ;
413 }
414 }
415  
416 120 return 1 ;
417 }
418  
419 #sub IO::Compress::Base::Validator::validateHash
420 #{
421 # my $self = shift ;
422 # my $href = shift ;
423 #
424 # while (my($k, $v) = each %$href)
425 # {
426 # my $ktype = whatIsInput($k);
427 # my $vtype = whatIsOutput($v, WANT_EXT|WANT_UNDEF) ;
428 #
429 # if ($ktype ne 'filename')
430 # {
431 # return $self->saveErrorString("hash key not filename") ;
432 # }
433 #
434 # my %valid = map { $_ => 1 } qw(filename buffer array undef handle) ;
435 # if (! $valid{$vtype})
436 # {
437 # return $self->saveErrorString("hash value not ok") ;
438 # }
439 # }
440 #
441 # return $self ;
442 #}
443  
444 sub createSelfTiedObject
445 {
446 6444 ▶ my $class = shift || (caller)[0] ;
Subroutine createSelfTiedObject: called CC=4 SCAR=14.3
Pod undocumented
Condition66%2/3
shift() || (caller)[0]
l!l&&r!l&&!r
488615580
MC/DC0%0/2
shift() || (caller)[0]
shift() (caller)[0]
Truth table66%2/3
A || B
A= shift()B= (caller)[0]
ABresult
1X1
011
000
447 6444 my $error_ref = shift ;
448  
449 6444 ▶ my $obj = bless Symbol::gensym(), ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
064440
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
450 6444 ▶ tie *$obj, $obj if $] >= 5.005;
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.005" 6444 0 6444
451 6444 *$obj->{Closed} = 1 ;
452 6444 $$error_ref = '';
453 6444 *$obj->{Error} = $error_ref ;
454 6444 my $errno = 0 ;
455 6444 *$obj->{ErrorNo} = \$errno ;
456  
457 6444 return $obj;
458 }
459  
460  
461  
462 #package Parse::Parameters ;
463 #
464 #
465 #require Exporter;
466 #our ($VERSION, @ISA, @EXPORT);
467 #$VERSION = '2.000_08';
468 #@ISA = qw(Exporter);
469  
470 130 $EXPORT_TAGS{Parse} = [qw( ParseParameters
471 Parse_any Parse_unsigned Parse_signed
472 Parse_boolean Parse_string
473 Parse_code
474 Parse_writable_scalar
475 )
476 ];
477  
478 130 push @EXPORT, @{ $EXPORT_TAGS{Parse} } ;
479  
480 130 ▶use constant Parse_any => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
481 130 ▶use constant Parse_unsigned => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
482 130 ▶use constant Parse_signed => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
483 130 ▶use constant Parse_boolean => 0x08;
Subroutine BEGIN: called CC=1 SCAR=0.0
484 130 ▶use constant Parse_string => 0x10;
Subroutine BEGIN: called CC=1 SCAR=0.0
485 130 ▶use constant Parse_code => 0x20;
Subroutine BEGIN: called CC=1 SCAR=0.0
486  
487 #use constant Parse_store_ref => 0x100 ;
488 #use constant Parse_multiple => 0x100 ;
489 130 ▶use constant Parse_writable => 0x200 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
490 130 ▶use constant Parse_writable_scalar => 0x400 | Parse_writable ;
Subroutine BEGIN: called CC=1 SCAR=0.0
491  
492 130 ▶use constant OFF_PARSED => 0 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
493 130 ▶use constant OFF_TYPE => 1 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
494 130 ▶use constant OFF_DEFAULT => 2 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
495 130 ▶use constant OFF_FIXED => 3 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
496 #use constant OFF_FIRST_ONLY => 4 ;
497 #use constant OFF_STICKY => 5 ;
498  
499 130 ▶use constant IxError => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
500 130 ▶use constant IxGot => 1 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
501  
502 sub ParseParameters
503 {
504 58 ▶ my $level = shift || 0 ;
Subroutine ParseParameters: called CC=6 SCAR=17.9
Pod undocumented
Condition100%2/2
shift() || 0
l!l
2236
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
505  
506 58 my $sub = (caller($level + 1))[3] ;
507 58 local $Carp::CarpLevel = 1 ;
508  
509 58 ▶ return $_[1]
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 and defined $_[1] and UNIVERSAL::isa($_[1], "IO::Compress::Base::Parameters") 1 57 58
Condition100%6/6
@_ == 2 and defined $_[1] and UNIVERSAL::isa($_[1], "IO::Compress::Base::Parameters")
!ll&&!rl&&r
4891
@_ == 2 and defined $_[1]
!ll&&!rl&&r
47110
MC/DC100%3/3
@_ == 2 and defined $_[1] and UNIVERSAL::isa($_[1], "IO::Compress::Base::Parameters")
@_ == 2 defined $_[1] UNIVERSAL::isa($_[1], "IO::Compress::Base::Parameters")
Truth table100%4/4
A and B and C
A= @_ == 2B= defined $_[1]C= UNIVERSAL::isa($_[1], "IO::Compress::Base::Parameters")
ABCresult
0XX0
10X0
1100
1111
510 if @_ == 2 && defined $_[1] && UNIVERSAL::isa($_[1], "IO::Compress::Base::Parameters");
511  
512 57 my $p = IO::Compress::Base::Parameters->new();
513 57 ▶ $p->parse(@_)
Branch: 1 branch
BranchTrueFalseTotal
$p->parse(@_) or croak("${sub}: $p->[0]") 20 37 57
514 or croak "$sub: $p->[IxError]" ;
515  
516 37 return $p;
517 }
518  
519  
520 130 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
521  
522 130 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
523 130 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
524  
525  
526 sub Init
527 {
528 0 ▶ my $default = shift ;
Subroutine Init: not called CC=4 SCAR=30.0
Pod undocumented
529 0 my %got ;
530  
531 0 my $obj = IO::Compress::Base::Parameters::new();
532 0 ▶ while (my ($key, $v) = each %$default)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$default) 0 0 0
533 {
534 0 ▶ croak "need 2 params [@$v]"
Branch: 1 branch
BranchTrueFalseTotal
if @$v != 2 0 0 0
535 if @$v != 2 ;
536  
537 0 my ($type, $value) = @$v ;
538 # my ($first_only, $sticky, $type, $value) = @$v ;
539 0 my $sticky = 0;
540 0 my $x ;
541 0 ▶ $obj->_checkType($key, \$value, $type, 0, \$x)
Branch: 1 branch
BranchTrueFalseTotal
$obj->_checkType($key, \$value, $type, 0, \$x) or return undef 0 0 0
542 or return undef ;
543  
544 0 $key = lc $key;
545  
546 # if (! $sticky) {
547 # $x = []
548 # if $type & Parse_multiple;
549  
550 # $got{$key} = [0, $type, $value, $x, $first_only, $sticky] ;
551 0 $got{$key} = [0, $type, $value, $x] ;
552 # }
553 #
554 # $got{$key}[OFF_PARSED] = 0 ;
555 }
556  
557 0 return bless \%got, "IO::Compress::Base::Parameters::Defaults" ;
558 }
559  
560 sub IO::Compress::Base::Parameters::new
561 {
562 #my $class = shift ;
563  
564 5519 ▶ my $obj;
Subroutine new: called CC=1 SCAR=0.0
565 5519 $obj->[IxError] = '';
566 5519 $obj->[IxGot] = {} ;
567  
568 5519 return bless $obj, 'IO::Compress::Base::Parameters' ;
569 }
570  
571 sub IO::Compress::Base::Parameters::setError
572 {
573 77 ▶ my $self = shift ;
Subroutine setError: called CC=2 SCAR=7.0
574 77 my $error = shift ;
575 77 ▶ my $retval = @_ ? shift : undef ;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 77 77
576  
577  
578 77 $self->[IxError] = $error ;
579 77 return $retval;
580 }
581  
582 sub IO::Compress::Base::Parameters::getError
583 {
584 57 ▶ my $self = shift ;
Subroutine getError: called CC=1 SCAR=0.0
585 57 return $self->[IxError] ;
586 }
587  
588 sub IO::Compress::Base::Parameters::parse
589 {
590 5695 ▶ my $self = shift ;
Subroutine parse: called CC=16 SCAR=27.7
591 5695 my $default = shift ;
592  
593 5695 my $got = $self->[IxGot] ;
594 5695 my $firstTime = keys %{ $got } == 0 ;
595  
596 5695 my (@Bad) ;
597 5695 my @entered = () ;
598  
599 # Allow the options to be passed as a hash reference or
600 # as the complete hash.
601 5695 ▶ if (@_ == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 1215 4480 5695
elsif (@_ == 1) { } 20 4460 4480
602 1215 @entered = () ;
603 }
604 elsif (@_ == 1) {
605 20 my $href = $_[0] ;
606  
607 20 ▶ return $self->setError("Expected even number of parameters, got 1")
Branch: 1 branch
BranchTrueFalseTotal
if not defined $href && ref $href or ref $href ne "HASH" 15 5 20
Condition100%6/6
not defined $href && ref $href or ref $href ne "HASH"
l!l&&r!l&&!r
1415
defined $href && ref $href
!ll&&!rl&&r
1136
MC/DC100%3/3
not defined $href && ref $href or ref $href ne "HASH"
defined $href ref $href ref $href ne "HASH"
Truth table100%4/4
not(A && B) or C
A= defined $hrefB= ref $hrefC= ref $href ne "HASH"
ABCresult
0XX1
10X1
1111
1100
608 if ! defined $href or ! ref $href or ref $href ne "HASH" ;
609  
610 5 foreach my $key (keys %$href) {
611 6 push @entered, $key ;
612 6 push @entered, \$href->{$key} ;
613 }
614 }
615 else {
616  
617 4460 my $count = @_;
618 4460 ▶ return $self->setError("Expected even number of parameters, got $count")
Branch: 1 branch
BranchTrueFalseTotal
if $count % 2 != 0 0 4460 4460
619 if $count % 2 != 0 ;
620  
621 4460 for my $i (0.. $count / 2 - 1) {
622 12671 push @entered, $_[2 * $i] ;
623 12671 push @entered, \$_[2 * $i + 1] ;
624 }
625 }
626  
627 5680 foreach my $key (keys %$default)
628 {
629  
630 79475 my ($type, $value) = @{ $default->{$key} } ;
631  
632 79475 ▶ if ($firstTime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($firstTime) { } 75654 3821 79475
633 75654 $got->{$key} = [0, $type, $value, $value] ;
634 }
635 else
636 {
637 3821 $got->{$key}[OFF_PARSED] = 0 ;
638 }
639 }
640  
641  
642 5680 my %parsed = ();
643  
644  
645 5680 for my $i (0.. @entered / 2 - 1) {
646 12677 my $key = $entered[2* $i] ;
647 12677 my $value = $entered[2* $i+1] ;
648  
649 #print "Key [$key] Value [$value]" ;
650 #print defined $$value ? "[$$value]\n" : "[undef]\n";
651  
652 12677 $key =~ s/^-// ;
653 12677 my $canonkey = lc $key;
654  
655 12677 ▶ if ($got->{$canonkey})
Branch: 1 branch
BranchTrueFalseTotal
if ($got->{$canonkey}) { } 12650 27 12677
656 {
657 12650 my $type = $got->{$canonkey}[OFF_TYPE] ;
658 12650 my $parsed = $parsed{$canonkey};
659 12650 ++ $parsed{$canonkey};
660  
661 12650 ▶ return $self->setError("Muliple instances of '$key' found")
Branch: 1 branch
BranchTrueFalseTotal
if $parsed 1 12649 12650
662 if $parsed ;
663  
664 12649 my $s ;
665 12649 ▶ $self->_checkType($key, $value, $type, 1, \$s)
Branch: 1 branch
BranchTrueFalseTotal
$self->_checkType($key, $value, $type, 1, \$s) or return undef 34 12615 12649
666 or return undef ;
667  
668 12615 $value = $$value ;
669 12615 $got->{$canonkey} = [1, $type, $value, $s] ;
670  
671 }
672 else
673 27 { push (@Bad, $key) }
674 }
675  
676 5645 ▶ if (@Bad) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Bad) 27 5618 5645
677 27 my ($bad) = join(", ", @Bad) ;
678 27 return $self->setError("unknown key value(s) $bad") ;
679 }
680  
681 5618 return 1;
682 }
683  
684 sub IO::Compress::Base::Parameters::_checkType
685 {
686 12649 ▶ my $self = shift ;
Subroutine _checkType: called CC=26 SCAR=32.7
687  
688 12649 my $key = shift ;
689 12649 my $value = shift ;
690 12649 my $type = shift ;
691 12649 my $validate = shift ;
692 12649 my $output = shift;
693  
694 #local $Carp::CarpLevel = $level ;
695 #print "PARSE $type $key $value $validate $sub\n" ;
696  
697 12649 ▶ if ($type & Parse_writable_scalar)
Branch: 1 branch
BranchTrueFalseTotal
if ($type & 1536) 25 12624 12649
698 {
699 25 ▶ return $self->setError("Parameter '$key' not writable")
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($$value) 1 24 25
700 if readonly $$value ;
701  
702 24 ▶ if (ref $$value)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$value) { } 12 12 24
703 {
704 12 ▶ return $self->setError("Parameter '$key' not a scalar reference")
Branch: 1 branch
BranchTrueFalseTotal
if ref $$value ne "SCALAR" 11 1 12
705 if ref $$value ne 'SCALAR' ;
706  
707 1 $$output = $$value ;
708 }
709 else
710 {
711 12 ▶ return $self->setError("Parameter '$key' not a scalar")
Branch: 1 branch
BranchTrueFalseTotal
if ref $value ne "SCALAR" 1 11 12
712 if ref $value ne 'SCALAR' ;
713  
714 11 $$output = $value ;
715 }
716  
717 12 return 1;
718 }
719  
720  
721 12624 $value = $$value ;
722  
723 12624 ▶ if ($type & Parse_any)
Branch: 6 branches
BranchTrueFalseTotal
if ($type & 1) { } 2495 10129 12624
elsif ($type & 2) { } 475 9654 10129
elsif ($type & 4) { } 99 9555 9654
elsif ($type & 8) { } 9549 6 9555
elsif ($type & 16) { } 1 5 6
elsif ($type & 32) { } 4 1 5
724 {
725 2495 $$output = $value ;
726 2495 return 1;
727 }
728 elsif ($type & Parse_unsigned)
729 {
730  
731 475 ▶ return $self->setError("Parameter '$key' must be an unsigned int, got 'undef'")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 4 471 475
732 if ! defined $value ;
733 471 ▶ return $self->setError("Parameter '$key' must be an unsigned int, got '$value'")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\d+$/ 11 460 471
734 if $value !~ /^\d+$/;
735  
736 460 ▶ $$output = defined $value ? $value : 0 ;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 460 0 460
737 460 return 1;
738 }
739 elsif ($type & Parse_signed)
740 {
741 99 ▶ return $self->setError("Parameter '$key' must be a signed int, got 'undef'")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 98 99
742 if ! defined $value ;
743 98 ▶ return $self->setError("Parameter '$key' must be a signed int, got '$value'")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^-?\d+$/ 1 97 98
744 if $value !~ /^-?\d+$/;
745  
746 97 ▶ $$output = defined $value ? $value : 0 ;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 97 0 97
747 97 return 1 ;
748 }
749 elsif ($type & Parse_boolean)
750 {
751 9549 ▶ return $self->setError("Parameter '$key' must be an int, got '$value'")
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and not $value =~ /^\d*$/ 3 9546 9549
Condition66%2/3
defined $value and not $value =~ /^\d*$/
!ll&&!rl&&r
095463
MC/DC50%1/2
defined $value and not $value =~ /^\d*$/
defined $value not $value =~ /^\d*$/
Truth table66%2/3
A and not(B)
A= defined $valueB= not $value =~ /^\d*$/
ABresult
0X0
100
111
752 if defined $value && $value !~ /^\d*$/;
753  
754 9546 ▶ $$output = defined $value && $value != 0 ? 1 : 0 ;
Branch: 1 branch
BranchTrueFalseTotal
defined $value && $value != 0 ? : 8338 1208 9546
Condition66%2/3
defined $value and $value != 0
!ll&&!rl&&r
012088338
MC/DC50%1/2
defined $value and $value != 0
defined $value $value != 0
Truth table66%2/3
A and B
A= defined $valueB= $value != 0
ABresult
0X0
100
111
755 9546 return 1;
756 }
757  
758 elsif ($type & Parse_string)
759 {
760 1 ▶ $$output = defined $value ? $value : "" ;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 1 1
761 1 return 1;
762 }
763 elsif ($type & Parse_code)
764 {
765 4 ▶ return $self->setError("Parameter '$key' must be a code reference, got '$value'")
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value ne "CODE" 1 3 4
Condition66%2/3
not defined $value or ref $value ne "CODE"
l!l&&r!l&&!r
013
MC/DC50%1/2
not defined $value or ref $value ne "CODE"
not defined $value ref $value ne "CODE"
Truth table66%2/3
not(A) or B
A= not defined $valueB= ref $value ne "CODE"
ABresult
1X1
011
000
766 if (! defined $value || ref $value ne 'CODE') ;
767  
768 3 ▶ $$output = defined $value ? $value : "" ;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 3 0 3
769 3 return 1;
770 }
771  
772 1 $$output = $value ;
773 1 return 1;
774 }
775  
776 sub IO::Compress::Base::Parameters::parsed
777 {
778 12008 ▶ return $_[0]->[IxGot]{$_[1]}[OFF_PARSED] ;
Subroutine parsed: called CC=1 SCAR=0.0
779 }
780  
781  
782 sub IO::Compress::Base::Parameters::getValue
783 {
784 90436 ▶ return $_[0]->[IxGot]{$_[1]}[OFF_FIXED] ;
Subroutine getValue: called CC=1 SCAR=0.0
785 }
786 sub IO::Compress::Base::Parameters::setValue
787 {
788 8053 ▶ $_[0]->[IxGot]{$_[1]}[OFF_PARSED] = 1;
Subroutine setValue: called CC=1 SCAR=0.0
789 8053 $_[0]->[IxGot]{$_[1]}[OFF_DEFAULT] = $_[2] ;
790 8053 $_[0]->[IxGot]{$_[1]}[OFF_FIXED] = $_[2] ;
791 }
792  
793 sub IO::Compress::Base::Parameters::valueRef
794 {
795 0 ▶ return $_[0]->[IxGot]{$_[1]}[OFF_FIXED] ;
Subroutine valueRef: not called CC=1 SCAR=6.9
796 }
797  
798 sub IO::Compress::Base::Parameters::valueOrDefault
799 {
800 2356 ▶ my $self = shift ;
Subroutine valueOrDefault: called CC=2 SCAR=6.9
801 2356 my $name = shift ;
802 2356 my $default = shift ;
803  
804 2356 my $value = $self->[IxGot]{$name}[OFF_DEFAULT] ;
805  
806 2356 ▶ return $value if defined $value ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 1967 389 2356
807 389 return $default ;
808 }
809  
810 sub IO::Compress::Base::Parameters::wantValue
811 {
812 1149 ▶ return defined $_[0]->[IxGot]{$_[1]}[OFF_DEFAULT] ;
Subroutine wantValue: called CC=1 SCAR=0.0
813 }
814  
815 sub IO::Compress::Base::Parameters::clone
816 {
817 255 ▶ my $self = shift ;
Subroutine clone: called CC=2 SCAR=6.9
818 255 my $obj = [] ;
819 255 my %got ;
820  
821 255 my $hash = $self->[IxGot] ;
822 255 for my $k (keys %{ $hash })
823 {
824 5616 $got{$k} = [ @{ $hash->{$k} } ];
825 }
826  
827 255 $obj->[IxError] = $self->[IxError];
828 255 $obj->[IxGot] = \%got ;
829  
830 255 return bless $obj, 'IO::Compress::Base::Parameters' ;
831 }
832  
833 package U64;
834  
835 130 ▶use constant MAX32 => 0xFFFFFFFF ;
Subroutine BEGIN: called CC=1 SCAR=0.0
836 130 ▶use constant HI_1 => MAX32 + 1 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
837 130 ▶use constant LOW => 0 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
838 130 ▶use constant HIGH => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
839  
840 sub new
841 {
842 11288 ▶ return bless [ 0, 0 ], $_[0]
Subroutine new: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 11268 20 11288
843 if @_ == 1 ;
844  
845 20 ▶ return bless [ $_[1], 0 ], $_[0]
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 3 17 20
846 if @_ == 2 ;
847  
848 17 ▶ return bless [ $_[2], $_[1] ], $_[0]
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 3 17 0 17
849 if @_ == 3 ;
850 }
851  
852 sub newUnpack_V64
853 {
854 118 ▶ my ($low, $hi) = unpack "V V", $_[0] ;
Subroutine newUnpack_V64: called CC=1 SCAR=0.0
855 118 bless [ $low, $hi ], "U64";
856 }
857  
858 sub newUnpack_V32
859 {
860 3952 ▶ my $string = shift;
Subroutine newUnpack_V32: called CC=1 SCAR=0.0
861  
862 3952 my $low = unpack "V", $string ;
863 3952 bless [ $low, 0 ], "U64";
864 }
865  
866 sub reset
867 {
868 3907 ▶ $_[0]->[HIGH] = $_[0]->[LOW] = 0;
Subroutine reset: called CC=1 SCAR=0.0
869 }
870  
871 sub clone
872 {
873 558 ▶ bless [ @{$_[0]} ], ref $_[0] ;
Subroutine clone: called CC=1 SCAR=0.0
874 }
875  
876 sub getHigh
877 {
878 23 ▶ return $_[0]->[HIGH];
Subroutine getHigh: called CC=1 SCAR=0.0
879 }
880  
881 sub getLow
882 {
883 23 ▶ return $_[0]->[LOW];
Subroutine getLow: called CC=1 SCAR=0.0
884 }
885  
886 sub get32bit
887 {
888 1466 ▶ return $_[0]->[LOW];
Subroutine get32bit: called CC=1 SCAR=0.0
889 }
890  
891 sub get64bit
892 {
893 # Not using << here because the result will still be
894 # a 32-bit value on systems where int size is 32-bits
895 2697 ▶ return $_[0]->[HIGH] * HI_1 + $_[0]->[LOW];
Subroutine get64bit: called CC=1 SCAR=0.0
896 }
897  
898 sub add
899 {
900 # my $self = shift;
901 16034 ▶ my $value = $_[1];
Subroutine add: called CC=4 SCAR=14.1
902  
903 16034 ▶ if (ref $value eq 'U64') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'U64') { } 412 15622 16034
elsif ($value > 4294967295) { } 0 15622 15622
904 412 $_[0]->[HIGH] += $value->[HIGH] ;
905 412 $value = $value->[LOW];
906 }
907 elsif ($value > MAX32) {
908 0 $_[0]->[HIGH] += int($value / HI_1) ;
909 0 $value = $value % HI_1;
910 }
911  
912 16034 my $available = MAX32 - $_[0]->[LOW] ;
913  
914 16034 ▶ if ($value > $available) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > $available) { } 2 16032 16034
915 2 ++ $_[0]->[HIGH] ;
916 2 $_[0]->[LOW] = $value - $available - 1;
917 }
918 else {
919 16032 $_[0]->[LOW] += $value ;
920 }
921 }
922  
923 sub add32
924 {
925 # my $self = shift;
926 843 ▶ my $value = $_[1];
Subroutine add32: called CC=3 SCAR=13.6
927  
928 843 ▶ if ($value > MAX32) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > 4294967295) 0 843 843
929 0 $_[0]->[HIGH] += int($value / HI_1) ;
930 0 $value = $value % HI_1;
931 }
932  
933 843 my $available = MAX32 - $_[0]->[LOW] ;
934  
935 843 ▶ if ($value > $available) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > $available) { } 0 843 843
936 0 ++ $_[0]->[HIGH] ;
937 0 $_[0]->[LOW] = $value - $available - 1;
938 }
939 else {
940 843 $_[0]->[LOW] += $value ;
941 }
942 }
943  
944 sub subtract
945 {
946 4 ▶ my $self = shift;
Subroutine subtract: called CC=6 SCAR=18.3
947 4 my $value = shift;
948  
949 4 ▶ if (ref $value eq 'U64') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "U64") 2 2 4
950  
951 2 ▶ if ($value->[HIGH]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->[1]) 2 0 2
952 2 ▶ die "bad"
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1] == 0 or $value->[1] > $self->[1] 0 2 2
Condition33%1/3
$self->[1] == 0 or $value->[1] > $self->[1]
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->[1] == 0 or $value->[1] > $self->[1]
$self->[1] == 0 $value->[1] > $self->[1]
Truth table33%1/3
A or B
A= $self->[1] == 0B= $value->[1] > $self->[1]
ABresult
1X1
011
000
953 if $self->[HIGH] == 0 ||
954 $value->[HIGH] > $self->[HIGH] ;
955  
956 2 $self->[HIGH] -= $value->[HIGH] ;
957 }
958  
959 2 $value = $value->[LOW] ;
960 }
961  
962 4 ▶ if ($value > $self->[LOW]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > $self->[0]) { } 3 1 4
963 3 -- $self->[HIGH] ;
964 3 $self->[LOW] = MAX32 - $value + $self->[LOW] + 1 ;
965 }
966 else {
967 1 $self->[LOW] -= $value;
968 }
969 }
970  
971 sub equal
972 {
973 1030 ▶ my $self = shift;
Subroutine equal: called CC=2 SCAR=7.0
974 1030 my $other = shift;
975  
976 1030 ▶ return $self->[LOW] == $other->[LOW] &&
Condition66%2/3
$self->[0] == $other->[0] && $self->[1] == $other->[1]
!ll&&!rl&&r
101029
MC/DC50%1/2
$self->[0] == $other->[0] && $self->[1] == $other->[1]
$self->[0] == $other->[0] $self->[1] == $other->[1]
Truth table66%2/3
A && B
A= $self->[0] == $other->[0]B= $self->[1] == $other->[1]
ABresult
0X0
100
111
977 $self->[HIGH] == $other->[HIGH] ;
978 }
979  
980 sub isZero
981 {
982 0 ▶ my $self = shift;
Subroutine isZero: not called CC=2 SCAR=17.9
983  
984 0 ▶ return $self->[LOW] == 0 &&
Condition0%0/3
$self->[0] == 0 && $self->[1] == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->[0] == 0 && $self->[1] == 0
$self->[0] == 0 $self->[1] == 0
Truth table0%0/3
A && B
A= $self->[0] == 0B= $self->[1] == 0
ABresult
0X0
100
111
985 $self->[HIGH] == 0 ;
986 }
987  
988 sub gt
989 {
990 1 ▶ my $self = shift;
Subroutine gt: called CC=1 SCAR=0.0
991 1 my $other = shift;
992  
993 1 return $self->cmp($other) > 0 ;
994 }
995  
996 sub cmp
997 {
998 3 ▶ my $self = shift;
Subroutine cmp: called CC=2 SCAR=7.4
999 3 my $other = shift ;
1000  
1001 3 ▶ if ($self->[LOW] == $other->[LOW]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[0] == $other->[0]) { } 0 3 3
1002 0 return $self->[HIGH] - $other->[HIGH] ;
1003 }
1004 else {
1005 3 return $self->[LOW] - $other->[LOW] ;
1006 }
1007 }
1008  
1009  
1010 sub is64bit
1011 {
1012 1189 ▶ return $_[0]->[HIGH] > 0 ;
Subroutine is64bit: called CC=1 SCAR=0.0
1013 }
1014  
1015 sub isAlmost64bit
1016 {
1017 822 ▶ return $_[0]->[HIGH] > 0 || $_[0]->[LOW] == MAX32 ;
Subroutine isAlmost64bit: called CC=2 SCAR=9.2
Condition33%1/3
$_[0][1] > 0 || $_[0][0] == 4294967295
l!l&&r!l&&!r
00822
MC/DC0%0/2
$_[0][1] > 0 || $_[0][0] == 4294967295
$_[0][1] > 0 $_[0][0] == 4294967295
Truth table33%1/3
A || B
A= $_[0][1] > 0B= $_[0][0] == 4294967295
ABresult
1X1
011
000
1018 }
1019  
1020 sub getPacked_V64
1021 {
1022 916 ▶ return pack "V V", @{ $_[0] } ;
Subroutine getPacked_V64: called CC=1 SCAR=0.0
1023 }
1024  
1025 sub getPacked_V32
1026 {
1027 2003 ▶ return pack "V", $_[0]->[LOW] ;
Subroutine getPacked_V32: called CC=1 SCAR=0.0
1028 }
1029  
1030 sub pack_V64
1031 {
1032 84 ▶ return pack "V V", $_[0], 0;
Subroutine pack_V64: called CC=1 SCAR=0.0
1033 }
1034  
1035  
1036 sub full32
1037 {
1038 32 ▶ return $_[0] == MAX32 ;
Subroutine full32: called CC=1 SCAR=0.0
1039 }
1040  
1041 sub Value_VV64
1042 {
1043 0 ▶ my $buffer = shift;
Subroutine Value_VV64: not called CC=1 SCAR=1.2
1044  
1045 0 my ($lo, $hi) = unpack ("V V" , $buffer);
1046 130 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1047 0 return $hi * HI_1 + $lo;
1048 }
1049  
1050  
1051 package IO::Compress::Base::Common;
1052  
1053 130 1;
« blib/lib/File/GlobMapper.pm ↑ Summary blib/lib/Compress/Zlib.pm »