Promise/Stream.pm

filter: Statementstmt 54.3% 486 / 895 Branchbran 34.3% 196 / 570 Conditioncond 35.3% 75 / 212 MC/DCmcdc 11.4% 13 / 114 Subroutinesub 68.9% 60 / 87 Podpod 84.2% 16 / 19 totaltotal 44.6% 846 / 1897 CC 371 SCAR 61.6
CC
371
Cov
45%
write
2407.8
read
419.8
as_string
240.0
CRAP 474.3
« Promise/Request.pm ↑ Summary Promise/Headers.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Stream.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/03/28
7 ## Modified 2026/03/09
8 ## All rights reserved.
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTTP::Promise::Stream;
15 BEGIN
16 12 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 warnings::register_categories( 'HTTP::Promise' );
20 12 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 $FILTER_MAP $CLASSES $ENCODING_SUFFIX $SUFFIX_ENCODING $ENCODING_ALIAS
23 $MIME_ENCODING
24 12 );
25 12 ▶ use HTTP::Promise::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 12 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 12 ▶ use constant HAS_BROWSER_SUPPORT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 12 our $VERSION = 'v0.3.0';
29 };
30  
31 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 12 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 {
36 12 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 12 $CLASSES =
38 {
39 base64 => [qw( HTTP::Promise::Stream::Base64 HTTP::Promise::Stream::Base64 )],
40 brotli => [qw( HTTP::Promise::Stream::Brotli HTTP::Promise::Stream::Brotli ), HAS_BROWSER_SUPPORT],
41 bzip2 => [qw( IO::Compress::Bzip2 IO::Uncompress::Bunzip2 ), HAS_BROWSER_SUPPORT],
42 deflate => [qw( IO::Compress::Deflate IO::Uncompress::Inflate ), HAS_BROWSER_SUPPORT],
43 gzip => [qw( IO::Compress::Gzip IO::Uncompress::Gunzip ), HAS_BROWSER_SUPPORT],
44 lzf => [qw( IO::Compress::Lzf IO::Uncompress::UnLzf )],
45 lzip => [qw( IO::Compress::Lzip IO::Uncompress::UnLzip )],
46 lzma => [qw( IO::Compress::Lzma IO::Uncompress::UnLzma )],
47 lzop => [qw( IO::Compress::Lzop IO::Uncompress::UnLzop )],
48 lzw => [qw( HTTP::Promise::Stream::LZW HTTP::Promise::Stream::LZW )],
49 qp => [qw( HTTP::Promise::Stream::QuotedPrint HTTP::Promise::Stream::QuotedPrint )],
50 rawdeflate => [qw( IO::Compress::RawDeflate IO::Uncompress::RawInflate ), HAS_BROWSER_SUPPORT],
51 uu => [qw( HTTP::Promise::Stream::UU HTTP::Promise::Stream::UU )],
52 xz => [qw( IO::Compress::Xz IO::Uncompress::UnXz )],
53 zip => [qw( IO::Compress::Zip IO::Uncompress::Unzip )],
54 zstd => [qw( IO::Compress::Zstd IO::Uncompress::UnZstd )],
55 };
56 12 $CLASSES->{br} = $CLASSES->{brotli};
57 12 $CLASSES->{inflate} = $CLASSES->{deflate};
58 12 $CLASSES->{rawinflate} = $CLASSES->{rawdeflate};
59 12 $CLASSES->{compress} = $CLASSES->{lzw};
60 12 $CLASSES->{'quoted-printable'} = $CLASSES->{qp};
61 12 $CLASSES->{'x-compress'} = $CLASSES->{lzw};
62 12 $CLASSES->{uuencode} = $CLASSES->{uu};
63 # Permit non-standard call with prefix x-
64 12 for( qw( bzip2 deflate gzip zip ) )
65 {
66 48 $CLASSES->{'x-' . $_} = $CLASSES->{ $_ };
67 }
68
69 $FILTER_MAP =
70 {
71 encode =>
72 {
73 # NOTE: encode -> base64
74 base64 => sub
75 5 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
76 # try-catch
77 5 local $@;
78 my $rv = eval
79 5 {
80 5 require HTTP::Promise::Stream::Base64;
81 5 HTTP::Promise::Stream::Base64::encode_b64( $_[0] => $_[1], @_[2..$#_] );
82 };
83 5 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
84 {
85 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
86 }
87 # defined( $rv ) or return( undef, $HTTP::Promise::Stream::Base64::Base64Error );
88 5 ▶ defined( $rv ) or return( undef, HTTP::Promise::Stream::Base64->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Stream::Base64"->error 5 0 5
89 5 return( $rv );
90 },
91 # NOTE: encode -> brotli
92 brotli => sub
93 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
94 # try-catch
95 0 local $@;
96 my $rv = eval
97 0 {
98 0 require HTTP::Promise::Stream::Brotli;
99 0 HTTP::Promise::Stream::Brotli::encode_bro( $_[0] => $_[1], @_[2..$#_] );
100 };
101 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
102 {
103 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
104 }
105 # $rv or return( undef, $HTTP::Promise::Stream::Brotli::BrotliError );
106 0 ▶ defined( $rv ) or return( undef, HTTP::Promise::Stream::Brotli->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Stream::Brotli"->error 0 0 0
107 0 return( $rv );
108 },
109 # NOTE: encode -> bzip2
110 bzip2 => sub
111 8 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
112 # try-catch
113 8 local $@;
114 my $rv = eval
115 8 {
116 8 require IO::Compress::Bzip2;
117 8 IO::Compress::Bzip2::bzip2( $_[0] => $_[1], @_[2..$#_] );
118 };
119 8 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
120 {
121 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
122 }
123 8 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Bzip2::Bzip2Error }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Bzip2::Bzip2Error}) 8 0 8
124 8 return( $rv );
125 },
126 # NOTE: encode -> deflate
127 deflate => sub
128 8 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
129 # try-catch
130 8 local $@;
131 my $rv = eval
132 8 {
133 8 require IO::Compress::Deflate;
134 8 IO::Compress::Deflate::deflate( $_[0] => $_[1], @_[2..$#_] );
135 };
136 8 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
137 {
138 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
139 }
140 # $rv or return( undef, $IO::Compress::Deflate::DeflateError );
141 8 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Deflate::DeflateError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Deflate::DeflateError}) 8 0 8
142 8 return( $rv );
143 },
144 # NOTE: encode -> gzip
145 gzip => sub
146 9 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
147 # try-catch
148 9 local $@;
149 my $rv = eval
150 9 {
151 9 require IO::Compress::Gzip;
152 9 IO::Compress::Gzip::gzip( $_[0] => $_[1], @_[2..$#_] );
153 };
154 9 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 9 9
155 {
156 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
157 }
158 # $rv or return( undef, $IO::Compress::Gzip::GzipError );
159 9 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Gzip::GzipError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Gzip::GzipError}) 9 0 9
160 9 return( $rv );
161 },
162 # NOTE: encode -> lzf
163 lzf => sub
164 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
165 # try-catch
166 0 local $@;
167 my $rv = eval
168 0 {
169 0 require IO::Compress::Lzf;
170 0 IO::Compress::Lzf::lzf( $_[0] => $_[1], @_[2..$#_] );
171 };
172 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
173 {
174 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
175 }
176 # $rv or return( undef, $IO::Compress::Lzf::LzfError );
177 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Lzf::LzfError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Lzf::LzfError}) 0 0 0
178 0 return( $rv );
179 },
180 # NOTE: encode -> lzip
181 lzip => sub
182 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
183 # try-catch
184 0 local $@;
185 my $rv = eval
186 0 {
187 0 require IO::Compress::Lzip;
188 0 IO::Compress::Lzip::lzip( $_[0] => $_[1], @_[2..$#_] );
189 };
190 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
191 {
192 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
193 }
194 # $rv or return( undef, $IO::Compress::Lzip::LzipError );
195 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Lzip::LzipError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Lzip::LzipError}) 0 0 0
196 0 return( $rv );
197 },
198 # NOTE: encode -> lzma
199 lzma => sub
200 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
201 # try-catch
202 0 local $@;
203 my $rv = eval
204 0 {
205 0 require IO::Compress::Lzma;
206 0 IO::Compress::Lzma::lzma( $_[0] => $_[1], @_[2..$#_] );
207 };
208 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
209 {
210 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
211 }
212 # $rv or return( undef, $IO::Compress::Lzma::LzmaError );
213 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Lzma::LzmaError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Lzma::LzmaError}) 0 0 0
214 0 return( $rv );
215 },
216 # NOTE: encode -> lzop
217 lzop => sub
218 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
219 # try-catch
220 0 local $@;
221 my $rv = eval
222 0 {
223 0 require IO::Compress::Lzop;
224 0 IO::Compress::Lzop::lzop( $_[0] => $_[1], @_[2..$#_] );
225 };
226 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
227 {
228 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
229 }
230 # $rv or return( undef, $IO::Compress::Lzop::LzopError );
231 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Lzop::LzopError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Lzop::LzopError}) 0 0 0
232 0 return( $rv );
233 },
234 # NOTE: encode -> lzw
235 lzw => sub
236 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
237 # try-catch
238 0 local $@;
239 my $rv = eval
240 0 {
241 0 require HTTP::Promise::Streem::LZW;
242 0 HTTP::Promise::Streem::LZW::encode_lzw( $_[0] => $_[1], @_[2..$#_] );
243 };
244 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
245 {
246 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
247 }
248 # $rv or return( undef, $HTTP::Promise::Streem::LZW::LZWError );
249 0 ▶ defined( $rv ) or return( undef, HTTP::Promise::Streem::LZW->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Streem::LZW"->error 0 0 0
250 0 return( $rv );
251 },
252 # NOTE: encode -> qp
253 qp => sub
254 1 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
255 # try-catch
256 1 local $@;
257 my $rv = eval
258 1 {
259 1 require HTTP::Promise::Stream::QuotedPrint;
260 1 HTTP::Promise::Stream::QuotedPrint::encode_qp( $_[0] => $_[1], @_[2..$#_] );
261 };
262 1 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
263 {
264 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
265 }
266 # $rv or return( undef, $HTTP::Promise::Stream::QuotedPrint::QuotedPrintError );
267 1 ▶ defined( $rv ) or return( undef, HTTP::Promise::Stream::QuotedPrint->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Stream::QuotedPrint"->error 1 0 1
268 1 return( $rv );
269 },
270 # NOTE: encode -> rawdeflate
271 rawdeflate => sub
272 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
273 # try-catch
274 0 local $@;
275 my $rv = eval
276 0 {
277 0 require IO::Compress::RawDeflate;
278 0 IO::Compress::RawDeflate::rawdeflate( $_[0] => $_[1], @_[2..$#_] );
279 };
280 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
281 {
282 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
283 }
284 # $rv or return( undef, $IO::Compress::RawDeflate::RawDeflateError );
285 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::RawDeflate::RawDeflateError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::RawDeflate::RawDeflateError}) 0 0 0
286 0 return( $rv );
287 },
288 # NOTE: encode -> uu
289 uu => sub
290 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
291 # try-catch
292 0 local $@;
293 my $rv = eval
294 0 {
295 0 require HTTP::Promise::Stream::UU;
296 0 HTTP::Promise::Stream::UU::encode_uu( $_[0] => $_[1], @_[2..$#_] );
297 };
298 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
299 {
300 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
301 }
302 # $rv or return( undef, $HTTP::Promise::Stream::UU::UUError );
303 0 ▶ defined( $rv ) or return( undef, HTTP::Promise::Stream::UU->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Stream::UU"->error 0 0 0
304 0 return( $rv );
305 },
306 # NOTE: encode -> xz
307 xz => sub
308 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
309 # try-catch
310 0 local $@;
311 my $rv = eval
312 0 {
313 0 require IO::Compress::Xz;
314 0 IO::Compress::Xz::xz( $_[0] => $_[1], @_[2..$#_] );
315 };
316 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
317 {
318 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
319 }
320 # $rv or return( undef, $IO::Compress::Xz::XzError );
321 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Xz::XzError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Xz::XzError}) 0 0 0
322 0 return( $rv );
323 },
324 # NOTE: encode -> zip
325 zip => sub
326 8 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
327 # try-catch
328 8 local $@;
329 my $rv = eval
330 8 {
331 8 require IO::Compress::Zip;
332 8 IO::Compress::Zip::zip( $_[0] => $_[1], @_[2..$#_] );
333 };
334 8 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
335 {
336 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
337 }
338 # $rv or return( undef, $IO::Compress::Zip::ZipError );
339 8 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Zip::ZipError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Zip::ZipError}) 8 0 8
340 8 return( $rv );
341 },
342 # NOTE: encode -> zstd
343 zstd => sub
344 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
345 # try-catch
346 0 local $@;
347 my $rv = eval
348 0 {
349 0 require IO::Compress::Zstd;
350 0 IO::Compress::Zstd::zstd( $_[0] => $_[1], @_[2..$#_] );
351 };
352 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
353 {
354 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
355 }
356 # $rv or return( undef, $IO::Compress::Zstd::ZstdError );
357 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Compress::Zstd::ZstdError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Compress::Zstd::ZstdError}) 0 0 0
358 0 return( $rv );
359 },
360 },
361 decode =>
362 {
363 # NOTE: decode -> base64
364 base64 => sub
365 4 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
366 # try-catch
367 4 local $@;
368 my $rv = eval
369 4 {
370 4 require HTTP::Promise::Stream::Base64;
371 4 HTTP::Promise::Stream::Base64::decode_b64( $_[0] => $_[1], @_[2..$#_] );
372 };
373 4 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
374 {
375 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
376 }
377 # $rv or return( undef, $HTTP::Promise::Stream::Base64::Base64Error );
378 4 ▶ defined( $rv ) or return( undef, HTTP::Promise::Stream::Base64->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Stream::Base64"->error 4 0 4
379 4 return( $rv );
380 },
381 # NOTE: decode -> brotli
382 brotli => sub
383 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
384 # try-catch
385 0 local $@;
386 my $rv = eval
387 0 {
388 0 require HTTP::Promise::Stream::Brotli;
389 0 HTTP::Promise::Stream::Brotli::decode_bro( $_[0] => $_[1], @_[2..$#_] );
390 };
391 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
392 {
393 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
394 }
395 # defined( $rv ) or return( undef, $HTTP::Promise::Stream::Brotli::BrotliError );
396 0 ▶ defined( $rv ) or return( undef, HTTP::Promise::Stream::Brotli->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Stream::Brotli"->error 0 0 0
397 0 return( $rv );
398 },
399 # NOTE: decode -> bzip2
400 bzip2 => sub
401 13 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
402 # try-catch
403 13 local $@;
404 my $rv = eval
405 13 {
406 13 require IO::Uncompress::Bunzip2;
407 13 IO::Uncompress::Bunzip2::bunzip2( $_[0] => $_[1], @_[2..$#_] );
408 };
409 13 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 13 13
410 {
411 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
412 }
413 # $rv or return( undef, $IO::Uncompress::Bunzip2::Bunzip2Error );
414 13 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::Bunzip2::Bunzip2Error }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::Bunzip2::Bunzip2Error}) 13 0 13
415 13 return( $rv );
416 },
417 # NOTE: decode -> gzip
418 gzip => sub
419 13 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
420 # try-catch
421 13 local $@;
422 my $rv = eval
423 13 {
424 13 require IO::Uncompress::Gunzip;
425 13 IO::Uncompress::Gunzip::gunzip( $_[0] => $_[1], @_[2..$#_] );
426 };
427 13 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 13 13
428 {
429 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
430 }
431 # $rv or return( undef, $IO::Uncompress::Gunzip::GunzipError );
432 13 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::Gunzip::GunzipError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::Gunzip::GunzipError}) 13 0 13
433 13 return( $rv );
434 },
435 # NOTE: decode -> inflate
436 inflate => sub
437 13 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
438 # try-catch
439 13 local $@;
440 my $rv = eval
441 13 {
442 13 require IO::Uncompress::Inflate;
443 13 IO::Uncompress::Inflate::inflate( $_[0] => $_[1], @_[2..$#_] );
444 };
445 13 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 13 13
446 {
447 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
448 }
449 # $rv or return( undef, $IO::Uncompress::Inflate::InflateError );
450 13 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::Inflate::InflateError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::Inflate::InflateError}) 13 0 13
451 13 return( $rv );
452 },
453 # NOTE: decode -> lzf
454 lzf => sub
455 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
456 # try-catch
457 0 local $@;
458 my $rv = eval
459 0 {
460 0 require IO::Uncompress::UnLzf;
461 0 IO::Uncompress::UnLzf::unlzf( $_[0] => $_[1], @_[2..$#_] );
462 };
463 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
464 {
465 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
466 }
467 # $rv or return( undef, $IO::Uncompress::UnLzf::UnLzfError );
468 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::UnLzf::UnLzfError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::UnLzf::UnLzfError}) 0 0 0
469 0 return( $rv );
470 },
471 # NOTE: decode -> lzip
472 lzip => sub
473 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
474 # try-catch
475 0 local $@;
476 my $rv = eval
477 0 {
478 0 require IO::Uncompress::UnLzip;
479 0 IO::Uncompress::UnLzip::unlzip( $_[0] => $_[1], @_[2..$#_] );
480 };
481 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
482 {
483 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
484 }
485 # $rv or return( undef, $IO::Uncompress::UnLzip::UnLzipError );
486 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::UnLzip::UnLzipError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::UnLzip::UnLzipError}) 0 0 0
487 0 return( $rv );
488 },
489 # NOTE: decode -> lzma
490 lzma => sub
491 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
492 # try-catch
493 0 local $@;
494 my $rv = eval
495 0 {
496 0 require IO::Uncompress::UnLzma;
497 0 IO::Uncompress::UnLzma::unlzma( $_[0] => $_[1], @_[2..$#_] );
498 };
499 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
500 {
501 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
502 }
503 # $rv or return( undef, $IO::Uncompress::UnLzma::UnLzmaError );
504 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::UnLzma::UnLzmaError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::UnLzma::UnLzmaError}) 0 0 0
505 0 return( $rv );
506 },
507 # NOTE: decode -> lzop
508 lzop => sub
509 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
510 # try-catch
511 0 local $@;
512 my $rv = eval
513 0 {
514 0 require IO::Uncompress::UnLzop;
515 0 IO::Uncompress::UnLzop::unlzop( $_[0] => $_[1], @_[2..$#_] );
516 };
517 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
518 {
519 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
520 }
521 # $rv or return( undef, $IO::Uncompress::UnLzop::UnLzopError );
522 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::UnLzop::UnLzopError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::UnLzop::UnLzopError}) 0 0 0
523 0 return( $rv );
524 },
525 # NOTE: decode -> lzw
526 lzw => sub
527 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
528 # try-catch
529 0 local $@;
530 my $rv = eval
531 0 {
532 0 require HTTP::Promise::Streem::LZW;
533 0 HTTP::Promise::Streem::LZW::decode_lzw( $_[0] => $_[1], @_[2..$#_] );
534 };
535 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
536 {
537 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
538 }
539 # $rv or return( undef, $HTTP::Promise::Streem::LZW::LZWError );
540 0 ▶ defined( $rv ) or return( undef, HTTP::Promise::Streem::LZW->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Streem::LZW"->error 0 0 0
541 0 return( $rv );
542 },
543 # NOTE: decode -> qp
544 qp => sub
545 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
546 # try-catch
547 0 local $@;
548 my $rv = eval
549 0 {
550 0 require HTTP::Promise::Stream::QuotedPrint;
551 0 HTTP::Promise::Stream::QuotedPrint::decode_qp( $_[0] => $_[1], @_[2..$#_] );
552 };
553 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
554 {
555 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
556 }
557 # $rv or return( undef, $HTTP::Promise::Stream::QuotedPrint::QuotedPrintError );
558 0 ▶ defined( $rv ) or return( undef, HTTP::Promise::Stream::QuotedPrint->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Stream::QuotedPrint"->error 0 0 0
559 0 return( $rv );
560 },
561 # NOTE: decode -> rawinflate
562 rawinflate => sub
563 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
564 # try-catch
565 0 local $@;
566 my $rv = eval
567 0 {
568 0 require IO::Uncompress::RawInflate;
569 0 IO::Uncompress::RawInflate::rawinflate( $_[0] => $_[1], @_[2..$#_] );
570 };
571 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
572 {
573 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
574 }
575 # $rv or return( undef, $IO::Uncompress::RawInflate::RawInflateError );
576 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::RawInflate::RawInflateError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::RawInflate::RawInflateError}) 0 0 0
577 0 return( $rv );
578 },
579 # NOTE: decode -> uu
580 uu => sub
581 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
582 # try-catch
583 0 local $@;
584 my $rv = eval
585 0 {
586 0 require HTTP::Promise::Stream::UU;
587 0 HTTP::Promise::Stream::UU::decode_uu( $_[0] => $_[1], @_[2..$#_] );
588 };
589 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
590 {
591 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
592 }
593 # $rv or return( undef, $HTTP::Promise::Stream::UU::UUError );
594 0 ▶ defined( $rv ) or return( undef, HTTP::Promise::Stream::UU->error );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv or return undef, "HTTP::Promise::Stream::UU"->error 0 0 0
595 0 return( $rv );
596 },
597 # NOTE: decode -> xz
598 xz => sub
599 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
600 # try-catch
601 0 local $@;
602 my $rv = eval
603 0 {
604 0 require IO::Uncompress::UnXz;
605 0 IO::Uncompress::UnXz::unxz( $_[0] => $_[1], @_[2..$#_] );
606 };
607 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
608 {
609 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
610 }
611 # $rv or return( undef, $IO::Uncompress::UnXz::UnXzError );
612 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::UnXz::UnXzError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::UnXz::UnXzError}) 0 0 0
613 0 return( $rv );
614 },
615 # NOTE: decode -> zip
616 zip => sub
617 13 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
618 # try-catch
619 13 local $@;
620 my $rv = eval
621 13 {
622 13 require IO::Uncompress::Unzip;
623 13 IO::Uncompress::Unzip::unzip( $_[0] => $_[1], @_[2..$#_] );
624 };
625 13 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 13 13
626 {
627 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
628 }
629 # $rv or return( undef, $IO::Uncompress::Unzip::UnzipError );
630 13 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::Unzip::UnzipError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::Unzip::UnzipError}) 13 0 13
631 13 return( $rv );
632 },
633 # NOTE: decode -> zstd
634 zstd => sub
635 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
636 # try-catch
637 0 local $@;
638 my $rv = eval
639 0 {
640 0 require IO::Uncompress::UnZstd;
641 0 IO::Uncompress::UnZstd::unzstd( $_[0] => $_[1], @_[2..$#_] );
642 };
643 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
644 {
645 0 return( undef, HTTP::Promise::Exception->new({ message => $@ }) );
646 }
647 # $rv or return( undef, $IO::Uncompress::UnZstd::UnZstdError );
648 0 ▶ $rv or return( undef, HTTP::Promise::Exception->new({ message => $IO::Uncompress::UnZstd::UnZstdError }) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return undef, "HTTP::Promise::Exception"->new({"message", $IO::Uncompress::UnZstd::UnZstdError}) 0 0 0
649 0 return( $rv );
650 },
651 }
652 12 };
653 # rfc1945, section 3.5
654 # Ref: <https://tools.ietf.org/html/rfc1945#section-3.5>
655 12 $FILTER_MAP->{encode}->{ 'x-gzip' } = $FILTER_MAP->{encode}->{gzip};
656 12 $FILTER_MAP->{decode}->{ 'x-gzip' } = $FILTER_MAP->{decode}->{gzip};
657 12 $FILTER_MAP->{encode}->{ 'x-bzip2' } = $FILTER_MAP->{encode}->{bzip2};
658 12 $FILTER_MAP->{decode}->{ 'x-bzip2' } = $FILTER_MAP->{decode}->{bzip2};
659 12 $FILTER_MAP->{encode}->{ 'x-compress' } = $FILTER_MAP->{encode}->{lzw};
660 12 $FILTER_MAP->{decode}->{ 'x-compress' } = $FILTER_MAP->{decode}->{lzw};
661 12 $FILTER_MAP->{encode}->{br} = $FILTER_MAP->{encode}->{brotli};
662 12 $FILTER_MAP->{decode}->{br} = $FILTER_MAP->{decode}->{brotli};
663 12 $FILTER_MAP->{encode}->{compress} = $FILTER_MAP->{encode}->{lzw};
664 12 $FILTER_MAP->{decode}->{compress} = $FILTER_MAP->{decode}->{lzw};
665 12 $FILTER_MAP->{encode}->{uuencode} = $FILTER_MAP->{encode}->{uu};
666 12 $FILTER_MAP->{decode}->{uuencode} = $FILTER_MAP->{decode}->{uu};
667 # deflate <-> inflate, make the choice of word irrelevant
668 12 $FILTER_MAP->{decode}->{deflate} = $FILTER_MAP->{decode}->{inflate};
669 12 $FILTER_MAP->{encode}->{inflate} = $FILTER_MAP->{encode}->{deflate};
670 12 $FILTER_MAP->{decode}->{rawdeflate} = $FILTER_MAP->{decode}->{rawinflate};
671 12 $FILTER_MAP->{encode}->{rawinflate} = $FILTER_MAP->{encode}->{rawdeflate};
672 12 $FILTER_MAP->{encode}->{ 'x-zip' } = $FILTER_MAP->{encode}->{zip};
673 12 $FILTER_MAP->{decode}->{ 'x-zip' } = $FILTER_MAP->{decode}->{zip};
674 # x-compress was used for LZW compression (the algorithm used in GIF),
675 # but is not actually used. There is a module Compress::LZW, but what is the point?
676 12 $FILTER_MAP->{encode}->{ 'quoted-printable' } = $FILTER_MAP->{encode}->{qp};
677 12 $FILTER_MAP->{decode}->{ 'quoted-printable' } = $FILTER_MAP->{decode}->{qp};
678  
679 12 $ENCODING_SUFFIX =
680 {
681 base64 => 'b64',
682 brotli => 'br',
683 bzip2 => 'bz2',
684 # See rfc1950
685 # <https://fileinfo.com/extension/zz#pigz_zlib_compressed_file>
686 deflate => 'zz',
687 gzip => 'gz',
688 lzf => 'lzf',
689 # <https://fileinfo.com/extension/lz>
690 lzip => 'lz',
691 # <https://fileinfo.com/extension/lzma>
692 lzma => 'lzma',
693 lzop => 'lzop',
694 lzw => 'lzw',
695 qp => 'qp',
696 rawdeflate => 'rzz',
697 uu => 'uu',
698 xz => 'xz',
699 zip => 'zip',
700 zstd => 'zst',
701 };
702  
703 12 $ENCODING_ALIAS =
704 {
705 br => 'brotli',
706 'x-gzip' => 'gzip',
707 'x-bzip2' => 'bzip2',
708 'x-compress' => 'lzw',
709 'x-uuencode' => 'uu',
710 'x-zip' => 'zip',
711 'compress' => 'lzw',
712 'inflate' => 'deflate',
713 'quoted-printable' => 'qp',
714 'rawinflate' => 'rawdeflate',
715 'uuencode' => 'uu',
716 };
717  
718 12 $MIME_ENCODING =
719 {
720 'application/gzip' => 'gzip',
721 'application/x-gzip' => 'gzip',
722 'application/x-bzip2' => 'bzip2',
723 'application/x-xz' => 'xz',
724 'application/zstd' => 'zstd',
725 'application/x-compress' => 'lzw',
726 'application/x-lzma' => 'lzma',
727 'application/x-lzip' => 'lzip',
728 'application/x-lzop' => 'lzop',
729 'application/x-lzf' => 'lzf',
730 };
731 }
732  
733 sub init
734 95 ▶{
Subroutine init: called CC=17 SCAR=30.4
Pod documented
735 95 my $self = shift( @_ );
736 95 my $src = shift( @_ );
737 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
738 95 ▶ return( $self->error( "No stream was provided." ) ) if( !defined( $src ) || !length( $src ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $src and length $src 0 95 95
Condition33%1/3
defined $src and length $src
!ll&&!rl&&r
0095
MC/DC0%0/2
defined $src and length $src
defined $src length $src
Truth table33%1/3
A and B
A= defined $srcB= length $src
ABresult
0X0
100
111
739 95 ▶ my $type = ref( $src ) ? lc( Scalar::Util::reftype( $src ) ) : '';
Branch: 1 branch
BranchTrueFalseTotal
ref $src ? : 93 2 95
740 95 ▶ if( ref( $src ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $src) { } 93 2 95
741 {
742 93 ▶ if( $self->_is_a( $src => 'Module::Generic::File' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($src, 'Module::Generic::File')) { } 47 46 93
elsif ($type ne 'scalar' and $type ne 'glob' and $type ne 'code') { } 0 92 92
743 {
744 47 $src = "$src";
745 }
746 ▶ elsif( $type ne 'scalar' && $type ne 'glob' && $type ne 'code' )
Condition50%3/6
$type ne "scalar" and $type ne "glob" and $type ne "code"
!ll&&!rl&&r
4600
$type ne "scalar" and $type ne "glob"
!ll&&!rl&&r
4150
MC/DC0%0/3
$type ne "scalar" and $type ne "glob" and $type ne "code"
$type ne "scalar" $type ne "glob" $type ne "code"
Truth table50%2/4
A and B and C
A= $type ne "scalar"B= $type ne "glob"C= $type ne "code"
ABCresult
0XX0
10X0
1100
1111
747 {
748 0 return( $self->error( "You can only provide a scalar reference, array reference, code reference or a glob as a reference element for the filter." ) );
749 }
750 }
751 else
752 {
753 2 ▶ if( $src =~ /\n/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($src =~ /\n/) 0 2 2
754 {
755 0 return( $self->error( "You cannot provide a text to set the filter. It can only be a scalar reference, array reference, a glob or a file path." ) );
756 }
757 }
758 95 $self->{compress_params} = {};
759 95 $self->{encoding} = undef;
760 95 $self->{decoding} = undef;
761 95 $self->{_init_strict_use_sub} = 1;
762 95 $self->{_exception_class} = 'HTTP::Promise::Exception';
763 95 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 95 0 95
764 95 $self->source( $src );
765 95 $self->{read_tmp_file} = undef;
766 95 $self->{src_file_handle} = undef;
767 95 ▶ if( defined( $self->{encoding} ) && length( $self->{encoding} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'encoding'} and length $self->{'encoding'}) { } 27 68 95
elsif (defined $self->{'decoding'} and length $self->{'decoding'}) { } 44 48 92
Condition66%2/3
defined $self->{"encoding"} and length $self->{"encoding"}
!ll&&!rl&&r
68027
MC/DC50%1/2
defined $self->{"encoding"} and length $self->{"encoding"}
defined $self->{"encoding"} length $self->{"encoding"}
Truth table66%2/3
A and B
A= defined $self->{"encoding"}B= length $self->{"encoding"}
ABresult
0X0
100
111
768 {
769 27 ▶ return( $self->error( "Encoding provided \"$self->{encoding}\" is unsupported." ) ) if( !exists( $FILTER_MAP->{encode}->{ $self->{encoding} } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HTTP::Promise::Stream::FILTER_MAP->{"encode"}{$self->{"encoding"}} 0 27 27
770 }
771 ▶ elsif( defined( $self->{decoding} ) && length( $self->{decoding} ) )
Condition66%2/3
defined $self->{"decoding"} and length $self->{"decoding"}
!ll&&!rl&&r
24044
MC/DC50%1/2
defined $self->{"decoding"} and length $self->{"decoding"}
defined $self->{"decoding"} length $self->{"decoding"}
Truth table66%2/3
A and B
A= defined $self->{"decoding"}B= length $self->{"decoding"}
ABresult
0X0
100
111
772 {
773 44 ▶ return( $self->error( "Decoding provided \"$self->{decoding}\" is unsupported." ) ) if( !exists( $FILTER_MAP->{decode}->{ $self->{decoding} } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HTTP::Promise::Stream::FILTER_MAP->{"decode"}{$self->{"decoding"}} 0 44 44
774 }
775 95 return( $self );
776 }
777  
778 sub as_string
779 0 ▶{
Subroutine as_string: not called CC=15 SCAR=54.8
Pod documented
780 0 my $self = shift( @_ );
781 0 my $src = $self->source;
782 0 ▶ if( ref( $src ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $src) { } 0 0 0
783 {
784 0 my $type = lc( Scalar::Util::reftype( $src ) );
785 0 ▶ if( $type eq 'scalar' )
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'scalar') { } 0 0 0
elsif ($type eq 'glob') { } 0 0 0
elsif ($self->_is_a($src, 'Module::Generic::File')) { } 0 0 0
786 {
787 0 return( ${$src} );
788 }
789 elsif( $type eq 'glob' )
790 {
791 0 ▶ if( $self->_is_a( $src => 'Module::Generic::Scalar::IO' ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_a($src, 'Module::Generic::Scalar::IO')) { } 0 0 0
elsif ($self->_is_object($src) and $self->_can($src, 'seek') and $self->_can($src, 'read')) { } 0 0 0
elsif (fileno $src) { } 0 0 0
792 {
793 0 return( join( '', $src->getlines ) );
794 }
795 ▶ elsif( $self->_is_object( $src ) && $self->_can( $src => 'seek' ) && $self->_can( $src => 'read' ) )
Condition0%0/6
$self->_is_object($src) and $self->_can($src, "seek") and $self->_can($src, "read")
!ll&&!rl&&r
000
$self->_is_object($src) and $self->_can($src, "seek")
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_is_object($src) and $self->_can($src, "seek") and $self->_can($src, "read")
$self->_is_object($src) $self->_can($src, "seek") $self->_can($src, "read")
Truth table0%0/4
A and B and C
A= $self->_is_object($src)B= $self->_can($src, "seek")C= $self->_can($src, "read")
ABCresult
0XX0
10X0
1100
1111
796 {
797 0 my $data = '';
798 0 ▶ $src->seek(0,0) || return( $self->error( "Unable to seek source stream glob: $!" ) );
Branch: 1 branch
BranchTrueFalseTotal
$src->seek(0, 0) or return $self->error("Unable to seek source stream glob: $!") 0 0 0
799 0 ▶ while( $src->read( my $buff, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($src->read(my $buff, 10240)) 0 0 0
800 {
801 0 $data .= $buff;
802 }
803 0 return( $data );
804 }
805 elsif( fileno( $src ) )
806 {
807 0 my $data = '';
808 0 ▶ CORE::seek( $src, 0, 0 ) || return( $self->error( "Unable to seek source stream glob: $!" ) );
Branch: 1 branch
BranchTrueFalseTotal
seek $src, 0, 0 or return $self->error("Unable to seek source stream glob: $!") 0 0 0
809 0 ▶ while( CORE::read( $src, my $buff, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::read $src, my $buff, 10240) 0 0 0
810 {
811 0 $data .= $buff;
812 }
813 0 return( $data );
814 }
815 }
816 elsif( $self->_is_a( $src => 'Module::Generic::File' ) )
817 {
818 0 return( $src->content );
819 }
820 0 return;
821 }
822 else
823 {
824 0 ▶ my $f = $self->new_file( $src ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($src) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($src) || (return $self->pass_error)
$self->new_file($src)
Truth table0%0/2
A
A= $self->new_file($src)
Aresult
11
00
825 0 return( $f->content );
826 }
827 }
828  
829 95 ▶sub compress_params { return( shift->_set_get_hash_as_mix_object( 'compress_params', @_ ) ); }
Subroutine compress_params: called CC=1 SCAR=0.0
Pod documented
830  
831 1 ▶sub decodable { return( shift->_decodable_encodable( 0, @_ ) ); }
Subroutine decodable: called CC=1 SCAR=0.0
Pod documented
832  
833 # Decoding $data and writing to stream:
834 # $stream->decode( $data );
835 # Decoding stream and returning decoded data:
836 # my $decoded = $stream->decode;
837 sub decode
838 12 ▶{
Subroutine decode: called CC=16 SCAR=37.0
Pod documented
839 12 my( $self ) = @_;
840 12 my $opts = {};
841 12 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 12 0 12
842 12 ▶ $opts->{encoding} //= '';
Condition50%1/2
$opts->{"encoding"} //= ""
l!l
120
MC/DC0%0/1
$opts->{"encoding"} //= ""
$opts->{"encoding"}
Truth table50%1/2
A
A= $opts->{"encoding"}
Aresult
11
00
843 12 ▶ $opts->{decoding} //= '';
Condition50%1/2
$opts->{"decoding"} //= ""
l!l
012
MC/DC0%0/1
$opts->{"decoding"} //= ""
$opts->{"decoding"}
Truth table50%1/2
A
A= $opts->{"decoding"}
Aresult
11
00
844 12 ▶ my $dec = $opts->{decoding} || $opts->{encoding} || $self->decoding->lower;
Condition33%2/6
$opts->{'decoding'} || $opts->{'encoding'} || $self->decoding->lower
l!l&&r!l&&!r
1200
$opts->{"decoding"} or $opts->{"encoding"}
l!l&&r!l&&!r
0120
MC/DC0%0/3
$opts->{'decoding'} || $opts->{'encoding'} || $self->decoding->lower
$opts->{"decoding"} $opts->{"encoding"} $self->decoding->lower
Truth table25%1/4
A or B || C
A= $opts->{"decoding"}B= $opts->{"encoding"}C= $self->decoding->lower
ABCresult
1XX1
01X1
0011
0000
845 12 my $src = $self->source;
846 # Scalar reference or glob
847 12 ▶ my $this = @_ >= 2 ? $_[1] : $src;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 0 12 12
848 12 my $size = $self->_get_size( $this );
849
850 # No need to bother going further
851 12 ▶ if( !defined( $dec ) || !length( $dec ) || !$size )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dec and length $dec and $size) 0 12 12
Condition33%2/6
defined $dec and length $dec and $size
!ll&&!rl&&r
0012
defined $dec and length $dec
!ll&&!rl&&r
0012
MC/DC0%0/3
defined $dec and length $dec and $size
defined $dec length $dec $size
Truth table25%1/4
A and B and C
A= defined $decB= length $decC= $size
ABCresult
0XX0
10X0
1100
1111
852 {
853 # $stream->decode( $data );
854 0 ▶ return( $self ) if( @_ >= 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 2 0 0 0
855 # my $decoded = $stream->decode;
856 0 return( '' );
857 }
858 12 my $filters = $FILTER_MAP->{decode};
859 12 ▶ return( $self->error( "Unknown decoding \"$dec\"." ) ) if( !exists( $filters->{ $dec } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $filters->{$dec} 0 12 12
860 12 my $params = $self->_io_compress_params( $opts );
861 12 my $rv;
862 # Decode some data provided and into the stream
863 12 ▶ if( @_ >= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2) { } 0 12 12
864 {
865 0 ( $rv, my $err ) = $filters->{ $dec }->( $_[0] => $src, %$params );
866 0 ▶ return( $self->error( "Unable to decode $size bytes of data into the stream with $dec: $err" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
867 0 return( $rv );
868 }
869 # Decode the stream and return the decoded data
870 else
871 {
872 12 my $buf;
873 12 ( $rv, my $err ) = $filters->{ $dec }->( $src => \$buf, %$params );
874 12 ▶ return( $self->error( "Unable to decode $size bytes of data from the stream with $dec: $err" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 12 12
875 12 ▶ return( $buf ) if( defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $rv 12 0 12
876 0 return( $rv );
877 }
878 }
879  
880 115 ▶sub decoding { return( shift->_set_get_scalar_as_object( 'decoding', @_ ) ); }
Subroutine decoding: called CC=1 SCAR=0.0
Pod documented
881  
882 0 ▶sub encodable { return( shift->_decodable_encodable( 1, @_ ) ); }
Subroutine encodable: not called CC=1 SCAR=6.9
Pod documented
883  
884 # Encoding $data and writing to stream:
885 # $stream->encode( $data );
886 # Encoding stream and returning decoded data:
887 # my $encoded = $stream->encode;
888 sub encode
889 12 ▶{
Subroutine encode: called CC=14 SCAR=34.4
Pod documented
890 12 my( $self ) = @_;
891 12 my $opts = {};
892 12 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 12 0 12
893 12 ▶ $opts->{encoding} //= '';
Condition50%1/2
$opts->{"encoding"} //= ""
l!l
120
MC/DC0%0/1
$opts->{"encoding"} //= ""
$opts->{"encoding"}
Truth table50%1/2
A
A= $opts->{"encoding"}
Aresult
11
00
894 12 ▶ my $enc = $opts->{encoding} || $self->encoding->lower;
Condition33%1/3
$opts->{'encoding'} || $self->encoding->lower
l!l&&r!l&&!r
1200
MC/DC0%0/2
$opts->{'encoding'} || $self->encoding->lower
$opts->{'encoding'} $self->encoding->lower
Truth table33%1/3
A || B
A= $opts->{'encoding'}B= $self->encoding->lower
ABresult
1X1
011
000
895 12 my $src = $self->source;
896 # Scalar reference or glob
897 12 ▶ my $this = @_ >= 2 ? $_[1] : $src;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 ? : 0 12 12
898 12 my $size = $self->_get_size( $this );
899
900 # No need to bother going further
901 12 ▶ if( !defined( $enc ) || !length( $enc ) || !$size )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $enc and length $enc and $size) 0 12 12
Condition33%2/6
defined $enc and length $enc and $size
!ll&&!rl&&r
0012
defined $enc and length $enc
!ll&&!rl&&r
0012
MC/DC0%0/3
defined $enc and length $enc and $size
defined $enc length $enc $size
Truth table25%1/4
A and B and C
A= defined $encB= length $encC= $size
ABCresult
0XX0
10X0
1100
1111
902 {
903 # $stream->encode( $data );
904 0 ▶ return( $self ) if( @_ >= 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 2 0 0 0
905 # my $encoded = $stream->encode;
906 0 return( '' );
907 }
908 12 my $filters = $FILTER_MAP->{encode};
909 12 ▶ return( $self->error( "Unknown encoding \"$enc\". Supported encodings are: ", join( ', ', sort( keys( %$filters ) ) ) ) ) if( !exists( $filters->{ $enc } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $filters->{$enc} 0 12 12
910 12 my $params = $self->_io_compress_params( $opts );
911 12 my $rv;
912 # Encode some data provided and into the stream
913 12 ▶ if( @_ >= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2) { } 0 12 12
914 {
915 0 ( $rv, my $err ) = $filters->{ $enc }->( $_[0] => $src, %$params );
916 0 ▶ return( $self->error( "Unable to encode $size bytes of data into the stream with $enc: $err" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
917 0 return( $rv );
918 }
919 # Encode the stream and return the decoded data
920 else
921 {
922 12 my $buf;
923 12 my $ref = \$buf;
924 12 ( $rv, my $err ) = $filters->{ $enc }->( $src => \$buf, %$params );
925 12 ▶ return( $self->error( "Unable to encode $size bytes of data from the stream with $enc: $err" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 12 12
926 12 ▶ return( $buf ) if( defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $rv 12 0 12
927 0 return( $rv );
928 }
929 }
930  
931 98 ▶sub encoding { return( shift->_set_get_scalar_as_object( 'encoding', @_ ) ); }
Subroutine encoding: called CC=1 SCAR=0.0
Pod documented
932  
933 sub encoding2suffix
934 16 ▶{
Subroutine encoding2suffix: called CC=9 SCAR=25.4
Pod documented
935 16 my $self = shift( @_ );
936 16 my $this = shift( @_ );
937 16 ▶ return( $self->error( "Bad argument provided. encoding2suffix() takes either an array of encodings or a string or something that stringifies." ) ) if( !defined( $this ) || ( !$self->_is_array( $this ) && ( ref( $this ) && !overload::Method( $this => '""' ) ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $this or not $self->_is_array($this) and (ref $this and not overload::Method($this, "\"\"")) 0 16 16
Condition22%2/9
not defined $this or not $self->_is_array($this) and (ref $this and not overload::Method($this, "\"\""))
l!l&&r!l&&!r
0016
not $self->_is_array($this) and (ref $this and not overload::Method($this, "\"\""))
!ll&&!rl&&r
1600
ref $this and not overload::Method($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $this or not $self->_is_array($this) and (ref $this and not overload::Method($this, "\"\""))
not defined $this not $self->_is_array($this) ref $this not overload::Method($this, "\"\"")
Truth table20%1/5
not(A) or not(B) and C and not(D)
A= not defined $thisB= not $self->_is_array($this)C= ref $thisD= not overload::Method($this, "\"\"")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
938 16 ▶ my $encodings = $self->new_array( $self->_is_array( $this ) ? $this : [split( /[[:blank:]\h]*,[[:blank:]\h]*/, lc( "${this}" ) )] );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($this) ? : 16 0 16
939 16 my $ext = $self->new_array;
940 16 foreach( @$encodings )
941 {
942 17 my $enc;
943 17 ▶ $enc = exists( $ENCODING_ALIAS->{ $_ } ) ? $ENCODING_ALIAS->{ $_ } : $_;
Branch: 1 branch
BranchTrueFalseTotal
exists $HTTP::Promise::Stream::ENCODING_ALIAS->{$_} ? : 0 17 17
944 17 ▶ return( $self->error( "Unknown encoding provided \"${enc}\"." ) ) if( !exists( $ENCODING_SUFFIX->{ $enc } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HTTP::Promise::Stream::ENCODING_SUFFIX->{$enc} 1 16 17
945 16 $ext->push( $ENCODING_SUFFIX->{ $enc } );
946 }
947 15 return( $ext );
948 }
949  
950 sub load
951 0 ▶{
Subroutine load: not called CC=10 SCAR=47.0
Pod documented
952 0 my $self = shift( @_ );
953 0 ▶ my $enc = shift( @_ ) || return( $self->error( "No encoding was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No encoding was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No encoding was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
954 0 $enc = lc( $enc );
955 0 ▶ return(0) if( !exists( $CLASSES->{ $enc } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HTTP::Promise::Stream::CLASSES->{$enc} 0 0 0
956 0 my $opts = $self->_get_args_as_hash( @_ );
957 0 my $p = {};
958 0 ▶ $p->{version} = $opts->{version} if( exists( $opts->{version} ) && length( $opts->{version} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"version"} and length $opts->{"version"} 0 0 0
Condition0%0/3
exists $opts->{"version"} and length $opts->{"version"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"version"} and length $opts->{"version"}
exists $opts->{"version"} length $opts->{"version"}
Truth table0%0/3
A and B
A= exists $opts->{"version"}B= length $opts->{"version"}
ABresult
0X0
100
111
959 0 my( $encoder, $decoder ) = @{$CLASSES->{ $enc }};
960 0 my $ok = 0;
961 0 for( $encoder, $decoder )
962 {
963 0 ▶ $ok++, next if( $_ eq $decoder && $decoder eq $encoder );
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $decoder and $decoder eq $encoder 0 0 0
Condition0%0/3
$_ eq $decoder and $decoder eq $encoder
!ll&&!rl&&r
000
MC/DC0%0/2
$_ eq $decoder and $decoder eq $encoder
$_ eq $decoder $decoder eq $encoder
Truth table0%0/3
A and B
A= $_ eq $decoderB= $decoder eq $encoder
ABresult
0X0
100
111
964 0 ▶ $self->_load_class( $_, $p ) || next;
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($_, $p) or next 0 0 0
965 0 $ok++;
966 }
967 0 ▶ return(1) if( $ok == 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $ok == 2 0 0 0
968 0 return(0);
969 }
970  
971 sub mime2encoding
972 11 ▶{
Subroutine mime2encoding: called CC=3 SCAR=11.0
Pod undocumented
973 11 my $self = shift( @_ );
974 11 ▶ my $mime = shift( @_ ) || return( $self->error( "No MIME type was provided." ) );
Condition100%2/2
shift @_ || (return $self->error('No MIME type was provided.'))
l!l
101
MC/DC100%1/1
shift @_ || (return $self->error('No MIME type was provided.'))
shift @_
Truth table100%2/2
A
A= shift @_
Aresult
11
00
975 10 $mime = lc( "${mime}" );
976 # Strip parameters like '; charset=binary'
977 10 ▶ $mime =~ s/[[:blank:]]*;.*$// if( index( $mime, ';' ) != -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($mime, ";") != -1) 1 9 10
978 10 return( $MIME_ENCODING->{ $mime } );
979 }
980  
981 # $stream->read( $buffer, $len, $offset );
982 # $stream->read( $buffer, $len );
983 # $stream->read( $buffer );
984 # $stream->read( *buffer );
985 # $stream->read( sub{} );
986 # $stream->read( \$buffer );
987 # $stream->read( '/some/where/file.txt' );
988 sub read
989 51 ▶{
Subroutine read: called CC=63 SCAR=60.4
Pod documented
990 51 my( $self ) = @_;
991 51 my $opts = {};
992 51 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 4 47 51
993 51 ▶ $opts->{binmode} = 'raw' if( !exists( $opts->{binmode} ) || !length( $opts->{binmode} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"binmode"} and length $opts->{"binmode"} 51 0 51
Condition33%1/3
exists $opts->{"binmode"} and length $opts->{"binmode"}
!ll&&!rl&&r
5100
MC/DC0%0/2
exists $opts->{"binmode"} and length $opts->{"binmode"}
exists $opts->{"binmode"} length $opts->{"binmode"}
Truth table33%1/3
A and B
A= exists $opts->{"binmode"}B= length $opts->{"binmode"}
ABresult
0X0
100
111
994 51 my $src = $self->source;
995 51 ▶ my $enc = $self->encoding->lower || lc( $opts->{encoding} );
Condition66%2/3
$self->encoding->lower || lc $opts->{'encoding'}
l!l&&r!l&&!r
7044
MC/DC50%1/2
$self->encoding->lower || lc $opts->{'encoding'}
$self->encoding->lower lc $opts->{'encoding'}
Truth table66%2/3
A || B
A= $self->encoding->lowerB= lc $opts->{'encoding'}
ABresult
1X1
011
000
996 51 ▶ my $dec = $self->decoding->lower || lc( $opts->{decoding} );
Condition66%2/3
$self->decoding->lower || lc $opts->{'decoding'}
l!l&&r!l&&!r
4407
MC/DC50%1/2
$self->decoding->lower || lc $opts->{'decoding'}
$self->decoding->lower lc $opts->{'decoding'}
Truth table66%2/3
A || B
A= $self->decoding->lowerB= lc $opts->{'decoding'}
ABresult
1X1
011
000
997 51 my $io = $self->{src_file_handle};
998 51 my $tempfile = $self->{read_tmp_file};
999 51 ▶ unless( $io )
Branch: 1 branch
BranchTrueFalseTotal
unless ($io) 51 0 51
1000 {
1001 51 ▶ $tempfile = $self->{read_tmp_file} = $self->new_tempfile ||
Condition50%1/2
$self->new_tempfile || (return $self->error('Unable to get a new tempfile: ', $self->error))
l!l
510
MC/DC0%0/1
$self->new_tempfile || (return $self->error('Unable to get a new tempfile: ', $self->error))
$self->new_tempfile
Truth table50%1/2
A
A= $self->new_tempfile
Aresult
11
00
1002 return( $self->error( "Unable to get a new tempfile: ", $self->error ) );
1003 51 ▶ if( $enc )
Branch: 2 branches
BranchTrueFalseTotal
if ($enc) { } 7 44 51
elsif ($dec) { } 44 0 44
1004 {
1005 7 my $params = $self->_io_compress_params( $opts );
1006 7 my $filters = $FILTER_MAP->{encode};
1007 7 ▶ return( $self->error( "Unknown encoding \"$enc\"." ) ) if( !exists( $filters->{ $enc } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $filters->{$enc} 0 7 7
1008 7 my( $rv, $err ) = $filters->{ $enc }->( $self->_normalise( $src ) => "$tempfile", %$params );
1009 7 my $size = $self->_get_size( $src );
1010 7 ▶ return( $self->error( "Unable to encode $size bytes of data into the stream with $enc: $err" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 7 7
1011 7 ▶ $io = $self->{src_file_handle} = $tempfile->open( '<', { binmode => $opts->{binmode} }) ||
Condition50%1/2
$tempfile->open('<', {'binmode', $opts->{'binmode'}}) || (return $self->pass_error($tempfile))
l!l
70
MC/DC0%0/1
$tempfile->open('<', {'binmode', $opts->{'binmode'}}) || (return $self->pass_error($tempfile))
$tempfile->open('<', {'binmode', $opts->{'binmode'}})
Truth table50%1/2
A
A= $tempfile->open('<', {'binmode', $opts->{'binmode'}})
Aresult
11
00
1012 return( $self->pass_error( $tempfile ) );
1013 }
1014 elsif( $dec )
1015 {
1016 44 my $params = $self->_io_compress_params( $opts );
1017 44 my $filters = $FILTER_MAP->{decode};
1018 44 ▶ return( $self->error( "Unknown decoding \"$dec\"." ) ) if( !exists( $filters->{ $dec } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $filters->{$dec} 0 44 44
1019 # $err, if defined, would be a HTTP::Promise::Exception object
1020 44 my( $rv, $err ) = $filters->{ $dec }->( $self->_normalise( $src ) => "$tempfile", %$params );
1021 44 my $size = $self->_get_size( $src );
1022 44 ▶ return( $self->error( "Unable to decode $size bytes of data into the stream with $dec and input '", $self->_normalise( $src ), "' and output '", $tempfile, "': $err" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 44 44
1023 44 ▶ $io = $self->{src_file_handle} = $tempfile->open( '<', { binmode => $opts->{binmode} }) ||
Condition50%1/2
$tempfile->open('<', {'binmode', $opts->{'binmode'}}) || (return $self->pass_error($tempfile))
l!l
440
MC/DC0%0/1
$tempfile->open('<', {'binmode', $opts->{'binmode'}}) || (return $self->pass_error($tempfile))
$tempfile->open('<', {'binmode', $opts->{'binmode'}})
Truth table50%1/2
A
A= $tempfile->open('<', {'binmode', $opts->{'binmode'}})
Aresult
11
00
1024 return( $self->pass_error( $tempfile ) );
1025 }
1026 else
1027 {
1028 0 my $type = lc( Scalar::Util::reftype( $src ) );
1029 0 ▶ if( $type eq 'scalar' )
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'scalar') { } 0 0 0
elsif ($type eq 'glob') { } 0 0 0
elsif (not ref $src) { } 0 0 0
1030 {
1031 0 my $s = $self->new_scalar( $src );
1032 0 ▶ $io = $self->{src_file_handle} = $s->open( '<' ) ||
Condition0%0/2
$s->open('<') || (return $self->pass_error($s->error))
l!l
00
MC/DC0%0/1
$s->open('<') || (return $self->pass_error($s->error))
$s->open('<')
Truth table0%0/2
A
A= $s->open('<')
Aresult
11
00
1033 return( $self->pass_error( $s->error ) );
1034 }
1035 elsif( $type eq 'glob' )
1036 {
1037 0 $io = $self->{src_file_handle} = $src;
1038 }
1039 elsif( !ref( $src ) )
1040 {
1041 0 my $f = $self->new_file( $src );
1042 0 ▶ $io = $self->{src_file_handle} = $f->open( '<', { $opts->{binmode} ? ( binmode => $opts->{binmode} ) : () }) ||
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'binmode'} ? : 0 0 0
Condition0%0/2
$f->open('<', {$opts->{'binmode'} ? ('binmode', $opts->{'binmode'}) : ()}) || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$f->open('<', {$opts->{'binmode'} ? ('binmode', $opts->{'binmode'}) : ()}) || (return $self->pass_error($f->error))
$f->open('<', {$opts->{'binmode'} ? ('binmode', $opts->{'binmode'}) : ()})
Truth table0%0/2
A
A= $f->open('<', {$opts->{'binmode'} ? ('binmode', $opts->{'binmode'}) : ()})
Aresult
11
00
1043 return( $self->pass_error( $f->error ) );
1044 }
1045 else
1046 {
1047 0 return( $self->error( "I do not know how to handle source '$src'." ) );
1048 }
1049 }
1050 }
1051
1052 51 my $len;
1053 51 ▶ if( ref( $_[1] ) eq 'CODE' )
Branch: 4 branches
BranchTrueFalseTotal
if (ref $_[1] eq 'CODE') { } 4 47 51
elsif (builtin::reftype($_[1]) eq 'SCALAR') { } 33 14 47
elsif (builtin::reftype($_[1]) eq 'GLOB') { } 4 10 14
elsif ($self->_is_a($_[1], 'Module::Generic::File') or not ref $_[1] and length $_[1] and index($_[1], "\n") == -1) { } 6 4 10
1054 {
1055 4 my $buf;
1056 # Because there is no buffer provided and we send the data chunk to a callback, the
1057 # offset option of the read() function is useless
1058 4 ▶ if( @_ >= 3 )
Branch: 2 branches
BranchTrueFalseTotal
if (@_ >= 3) { } 0 4 4
elsif (@_ >= 2) { } 4 0 4
1059 {
1060 0 $len = $io->read( $buf, $_[2] );
1061 0 ▶ return( $self->error( "Unable to read ", $_[2], " bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 0 0
1062 }
1063 elsif( @_ >= 2 )
1064 {
1065 4 $len = $io->read( $buf, $tempfile->length );
1066 4 ▶ return( $self->error( "Unable to read bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 4 4
1067 }
1068
1069 # try-catch
1070 4 local $@;
1071 eval
1072 4 {
1073 4 $_[1]->( $buf );
1074 };
1075 4 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
1076 {
1077 0 return( $self->error( "Callback raised an exception when sending it the ", length( $buf ), " bytes of data read from source: $@" ) );
1078 }
1079 }
1080 elsif( Scalar::Util::reftype( $_[1] ) eq 'SCALAR' )
1081 {
1082 33 ▶ if( @_ >= 4 )
Branch: 3 branches
BranchTrueFalseTotal
if (@_ >= 4) { } 0 33 33
elsif (@_ >= 3) { } 0 33 33
elsif (@_ >= 2) { } 33 0 33
1083 {
1084 0 $len = $io->read( ${$_[1]}, $_[2], $_[3] );
1085 0 ▶ return( $self->error( "Unable to read ", $_[2], " bytes at offset ", $_[3], " from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 0 0
1086 }
1087 elsif( @_ >= 3 )
1088 {
1089 0 $len = $io->read( ${$_[1]}, $_[2] );
1090 0 ▶ return( $self->error( "Unable to read ", $_[2], " bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 0 0
1091 }
1092 elsif( @_ >= 2 )
1093 {
1094 33 $len = $io->read( ${$_[1]}, $tempfile->length );
1095 33 ▶ return( $self->error( "Unable to read bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 33 33
1096 }
1097 }
1098 elsif( Scalar::Util::reftype( $_[1] ) eq 'GLOB' )
1099 {
1100 4 my $buf;
1101 # Because there is no buffer provided and we send the data chunk to a glob, the
1102 # offset option of the read() function is useless
1103 4 ▶ if( @_ >= 3 )
Branch: 2 branches
BranchTrueFalseTotal
if (@_ >= 3) { } 0 4 4
elsif (@_ >= 2) { } 4 0 4
1104 {
1105 0 $len = $io->read( $buf, $_[2] );
1106 0 ▶ return( $self->error( "Unable to read ", $_[2], " bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 0 0
1107 0 my $rv = CORE::print( $_[1], $buf );
1108 0 ▶ return( $self->error( "Unable to print ", CORE::length( $buf ), " bytes of data to provided file handle '", $_[1], "': $!" ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
1109 }
1110 elsif( @_ >= 2 )
1111 {
1112 4 my $chunklen;
1113 4 ▶ while( $chunklen = $io->read( $buf, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($chunklen = $io->read($buf, 10240)) 4 4 8
1114 {
1115 4 $len += $chunklen;
1116 #my $rv = CORE::print( $_[1], $buf );
1117 4 my $rv = $_[1]->print( $buf );
1118 4 ▶ return( $self->error( "Unable to print ", CORE::length( $buf ), " bytes of data to provided file handle '", $_[1], "': $!" ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 4 4
1119 }
1120 4 ▶ return( $self->error( "Unable to read bytes from source: $!" ) ) if( !defined( $chunklen ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunklen 0 4 4
1121 }
1122 }
1123 # A file
1124 ▶ elsif( $self->_is_a( $_[1] => 'Module::Generic::File' ) ||
Condition44%4/9
$self->_is_a($_[1], "Module::Generic::File") or not ref $_[1] and length $_[1] and index($_[1], "\n") == -1
l!l&&r!l&&!r
604
not ref $_[1] and length $_[1] and index($_[1], "\n") == -1
!ll&&!rl&&r
400
not ref $_[1] and length $_[1]
!ll&&!rl&&r
040
MC/DC25%1/4
$self->_is_a($_[1], "Module::Generic::File") or not ref $_[1] and length $_[1] and index($_[1], "\n") == -1
$self->_is_a($_[1], "Module::Generic::File") not ref $_[1] length $_[1] index($_[1], "\n") == -1
Truth table40%2/5
A or not(B) and C and D
A= $self->_is_a($_[1], "Module::Generic::File")B= not ref $_[1]C= length $_[1]D= index($_[1], "\n") == -1
ABCDresult
1XXX1
01111
00XX0
010X0
01100
1125 ( !ref( $_[1] ) &&
1126 CORE::length( $_[1] ) &&
1127 CORE::index( $_[1], "\n" ) == -1
1128 ) )
1129 {
1130 6 ▶ my $f = $self->new_file( $_[1] ) || return( $self->pass_error );
Condition50%1/2
$self->new_file($_[1]) || (return $self->pass_error)
l!l
60
MC/DC0%0/1
$self->new_file($_[1]) || (return $self->pass_error)
$self->new_file($_[1])
Truth table50%1/2
A
A= $self->new_file($_[1])
Aresult
11
00
1131 6 my $buf;
1132 # Because there is no buffer provided and we send the data chunk to a file, the
1133 # offset option of the read() function is useless
1134 6 ▶ if( @_ >= 3 )
Branch: 2 branches
BranchTrueFalseTotal
if (@_ >= 3) { } 0 6 6
elsif (@_ >= 2) { } 6 0 6
1135 {
1136 0 $len = $io->read( $buf, $_[2] );
1137 0 ▶ return( $self->error( "Unable to read ", $_[2], " bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 0 0
1138 }
1139 elsif( @_ >= 2 )
1140 {
1141 6 $len = $io->read( $buf, $tempfile->length );
1142 6 ▶ return( $self->error( "Unable to read bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 6 6
1143 }
1144 6 ▶ my $mode = $opts->{mode} ? $opts->{mode} : '>';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'mode'} ? : 0 6 6
1145 6 my $params = {};
1146 6 ▶ $params->{binmode} = $opts->{binmode} if( $opts->{binmode} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"binmode"} 6 0 6
1147 6 ▶ $params->{autoflush} = $opts->{autoflush} if( $opts->{autoflush} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"autoflush"} 0 6 6
1148 6 ▶ $f->open( $mode, $params ) ||
Branch: 1 branch
BranchTrueFalseTotal
$f->open($mode, $params) or return $self->pass_error($f->error) 6 0 6
1149 return( $self->pass_error( $f->error ) );
1150 6 ▶ $f->print( $buf ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->print($buf) or return $self->pass_error($f->error) 6 0 6
1151 6 $f->close;
1152 }
1153 # A regular string
1154 else
1155 {
1156 4 ▶ if( @_ >= 4 )
Branch: 3 branches
BranchTrueFalseTotal
if (@_ >= 4) { } 0 4 4
elsif (@_ >= 3) { } 0 4 4
elsif (@_ >= 2) { } 4 0 4
1157 {
1158 0 $len = $io->read( $_[1], $_[2], $_[3] );
1159 0 ▶ return( $self->error( "Unable to read ", $_[2], " bytes at offset ", $_[3], " from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 0 0
1160 }
1161 elsif( @_ >= 3 )
1162 {
1163 0 $len = $io->read( $_[1], $_[2] );
1164 0 ▶ return( $self->error( "Unable to read ", $_[2], " bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 0 0
1165 }
1166 elsif( @_ >= 2 )
1167 {
1168 4 $len = $io->read( $_[1], $tempfile->length );
1169 4 ▶ return( $self->error( "Unable to read bytes from source: $!" ) ) if( !defined( $len ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 4 4
1170 }
1171 }
1172 51 return( $len );
1173 }
1174  
1175 190 ▶sub source { return( shift->_set_get_scalar( 'source', @_ ) ); }
Subroutine source: called CC=1 SCAR=0.0
Pod documented
1176  
1177 sub suffix2encoding
1178 27 ▶{
Subroutine suffix2encoding: called CC=7 SCAR=19.6
Pod documented
1179 27 my $self = shift( @_ );
1180 27 ▶ my $file = shift( @_ ) || return( $self->pass_error( "No file was provided to guess encoding." ) );
Condition50%1/2
shift @_ || (return $self->pass_error('No file was provided to guess encoding.'))
l!l
270
MC/DC0%0/1
shift @_ || (return $self->pass_error('No file was provided to guess encoding.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1181 27 my @parts = reverse( split( /\./, $file ) );
1182 27 ▶ unless( defined( $SUFFIX_ENCODING ) && %$SUFFIX_ENCODING )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $HTTP::Promise::Stream::SUFFIX_ENCODING and %$HTTP::Promise::Stream::SUFFIX_ENCODING) 2 25 27
Condition66%2/3
defined $HTTP::Promise::Stream::SUFFIX_ENCODING and %$HTTP::Promise::Stream::SUFFIX_ENCODING
!ll&&!rl&&r
2025
MC/DC50%1/2
defined $HTTP::Promise::Stream::SUFFIX_ENCODING and %$HTTP::Promise::Stream::SUFFIX_ENCODING
defined $HTTP::Promise::Stream::SUFFIX_ENCODING %$HTTP::Promise::Stream::SUFFIX_ENCODING
Truth table66%2/3
A and B
A= defined $HTTP::Promise::Stream::SUFFIX_ENCODINGB= %$HTTP::Promise::Stream::SUFFIX_ENCODING
ABresult
0X0
100
111
1183 {
1184 2 my @keys = keys( %$ENCODING_SUFFIX );
1185 2 my @vals = @$ENCODING_SUFFIX{ @keys };
1186 2 $SUFFIX_ENCODING = {};
1187 2 @$SUFFIX_ENCODING{ @vals } = @keys;
1188 2 ▶ $SUFFIX_ENCODING->{Z} = 'lzw' unless( CORE::exists( $SUFFIX_ENCODING->{Z} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HTTP::Promise::Stream::SUFFIX_ENCODING->{"Z"} 2 0 2
1189 }
1190 27 my $encs = $self->new_array;
1191 27 foreach( @parts )
1192 {
1193 54 ▶ if( exists( $SUFFIX_ENCODING->{ $_ } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $HTTP::Promise::Stream::SUFFIX_ENCODING->{$_}) { } 27 27 54
1194 {
1195 27 $encs->push( $SUFFIX_ENCODING->{ $_ } );
1196 }
1197 else
1198 {
1199 27 last;
1200 }
1201 }
1202 27 return( $encs->reverse );
1203 }
1204  
1205 sub supported
1206 0 ▶{
Subroutine supported: not called CC=6 SCAR=37.4
Pod documented
1207 0 my $self = shift( @_ );
1208 0 ▶ return( $self->error( "No encoding was provided to check if it exists." ) ) if( !@_ || !defined( $_[0] ) || !length( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and defined $_[0] and length $_[0] 0 0 0
Condition0%0/6
@_ and defined $_[0] and length $_[0]
!ll&&!rl&&r
000
@_ and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/3
@_ and defined $_[0] and length $_[0]
@_ defined $_[0] length $_[0]
Truth table0%0/4
A and B and C
A= @_B= defined $_[0]C= length $_[0]
ABCresult
0XX0
10X0
1100
1111
1209 0 my $this = lc( shift( @_ ) );
1210 0 ▶ return(1) if( exists( $FILTER_MAP->{encode}->{ $this } ) || exists( $FILTER_MAP->{decode}->{ $this } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $HTTP::Promise::Stream::FILTER_MAP->{"encode"}{$this} or exists $HTTP::Promise::Stream::FILTER_MAP->{"decode"}{$this} 0 0 0
Condition0%0/3
exists $HTTP::Promise::Stream::FILTER_MAP->{"encode"}{$this} or exists $HTTP::Promise::Stream::FILTER_MAP->{"decode"}{$this}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $HTTP::Promise::Stream::FILTER_MAP->{"encode"}{$this} or exists $HTTP::Promise::Stream::FILTER_MAP->{"decode"}{$this}
exists $HTTP::Promise::Stream::FILTER_MAP->{"encode"}{$this} exists $HTTP::Promise::Stream::FILTER_MAP->{"decode"}{$this}
Truth table0%0/3
A or B
A= exists $HTTP::Promise::Stream::FILTER_MAP->{"encode"}{$this}B= exists $HTTP::Promise::Stream::FILTER_MAP->{"decode"}{$this}
ABresult
1X1
011
000
1211 0 return(0);
1212 }
1213  
1214 # $stream->write( $data );
1215 # $stream->write( \$data );
1216 # $stream->write( *$data );
1217 # $stream->write( '/some/where/file.txt' );
1218 # $stream->write( sub{} );
1219 sub write
1220 20 ▶{
Subroutine write: called CC=74 SCAR=77.9
Pod documented
1221 20 my( $self ) = @_;
1222 # No data was provided
1223 20 ▶ return(0) if( !defined( $_[1] ) || !length( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] and length $_[1] 0 20 20
Condition33%1/3
defined $_[1] and length $_[1]
!ll&&!rl&&r
0020
MC/DC0%0/2
defined $_[1] and length $_[1]
defined $_[1] length $_[1]
Truth table33%1/3
A and B
A= defined $_[1]B= length $_[1]
ABresult
0X0
100
111
1224 20 my $src = $self->source;
1225 20 my $enc = $self->encoding->lower;
1226 20 my $dec = $self->decoding->lower;
1227 20 my $type = lc( Scalar::Util::reftype( $_[1] ) );
1228 20 my $data;
1229 my $size;
1230 20 my $len;
1231 20 ▶ if( $type eq 'code' )
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'code') { } 4 16 20
1232 {
1233 # try-catch
1234 4 local $@;
1235 my $buf = eval
1236 4 {
1237 4 $_[1]->()
1238 };
1239 4 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
1240 {
1241 0 return( $self->error( "Error getting data from callback: $@" ) );
1242 }
1243 4 $data = \$buf;
1244 4 $size = length( $$data );
1245 }
1246 else
1247 {
1248 16 $size = $self->_get_size( $_[1] );
1249 # If the data provided is not a reference i.e. a string and it does not have any
1250 # CRLF sequence and it is not a file that exists, OR it has multiple CRLF
1251 # sequences, then we treat it as a string, and to remove ambiguity, we make it a
1252 # scalar reference
1253 16 ▶ if( !ref( $_[1] ) &&
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $_[1] and index($_[1], "\n") == -1 && !(-e $_[1]) || (index($_[1], "\n") != -1)) { } 4 12 16
elsif ($type eq 'scalar') { } 4 8 12
elsif ($self->_is_a($_[1], 'Module::Generic::File') or $self->_can($_[1], 'filename')) { } 4 4 8
Condition44%4/9
not ref $_[1] and index($_[1], "\n") == -1 && !(-e $_[1]) || (index($_[1], "\n") != -1)
!ll&&!rl&&r
1204
index($_[1], "\n") == -1 and not -e $_[1] or (index($_[1], "\n") != -1)
l!l&&r!l&&!r
400
index($_[1], "\n") == -1 and not -e $_[1]
!ll&&!rl&&r
004
MC/DC25%1/4
not ref $_[1] and index($_[1], "\n") == -1 && !(-e $_[1]) || (index($_[1], "\n") != -1)
not ref $_[1] index($_[1], "\n") == -1 not -e $_[1] (index($_[1], "\n") != -1)
Truth table33%2/6
not(A) and B and not(C) or D
A= not ref $_[1]B= index($_[1], "\n") == -1C= not -e $_[1]D= (index($_[1], "\n") != -1)
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
1254 (
1255 ( index( $_[1], "\n" ) == -1 && !-e( $_[1] ) ) ||
1256 ( index( $_[1], "\n" ) != -1 )
1257 ) )
1258 {
1259 4 $data = \$_[1];
1260 }
1261 elsif( $type eq 'scalar' )
1262 {
1263 4 $data = $_[1];
1264 }
1265 ▶ elsif( $self->_is_a( $_[1] => 'Module::Generic::File' ) ||
Condition66%2/3
$self->_is_a($_[1], "Module::Generic::File") or $self->_can($_[1], "filename")
l!l&&r!l&&!r
404
MC/DC50%1/2
$self->_is_a($_[1], "Module::Generic::File") or $self->_can($_[1], "filename")
$self->_is_a($_[1], "Module::Generic::File") $self->_can($_[1], "filename")
Truth table66%2/3
A or B
A= $self->_is_a($_[1], "Module::Generic::File")B= $self->_can($_[1], "filename")
ABresult
1X1
011
000
1266 $self->_can( $_[1] => 'filename' ) )
1267 {
1268 4 $data = $_[1]->filename;
1269 }
1270 # otherwise, it is either a scalar reference, a glob or a file, and if it is none
1271 # of those, we return an error
1272 else
1273 {
1274 4 $data = $_[1];
1275 4 ▶ return( $self->error( "Unsupported data type '", overload::StrVal( $data ), "'. You can only provide a string, a scalar reference, a code reference, a glob or a file path." ) ) if( ref( $data ) && $type ne 'scalar' && $type ne 'glob' && $type ne 'code' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $data and $type ne "scalar" and $type ne "glob" and $type ne "code" 0 4 4
Condition33%3/9
ref $data and $type ne "scalar" and $type ne "glob" and $type ne "code"
!ll&&!rl&&r
400
ref $data and $type ne "scalar" and $type ne "glob"
!ll&&!rl&&r
040
ref $data and $type ne "scalar"
!ll&&!rl&&r
004
MC/DC0%0/4
ref $data and $type ne "scalar" and $type ne "glob" and $type ne "code"
ref $data $type ne "scalar" $type ne "glob" $type ne "code"
Truth table20%1/5
A and B and C and D
A= ref $dataB= $type ne "scalar"C= $type ne "glob"D= $type ne "code"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1276 }
1277
1278 # If we are dealing with a file, open it and use its file glob instead,
1279 # because some encoder like IO::Compress::Zip actually creates and archive of the file with the file path included, rather than just the file content as advertised.
1280 # See Bug #38
1281 # <https://github.com/pmqs/IO-Compress/issues/38>
1282 16 ▶ if( !ref( $data ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data) 4 12 16
1283 {
1284 4 my $f = $self->new_file( $data );
1285 4 ▶ $data = $f->open( '<', { binmode => 'raw' } ) ||
Condition50%1/2
$f->open('<', {'binmode', 'raw'}) || (return $self->pass_error($f->error))
l!l
40
MC/DC0%0/1
$f->open('<', {'binmode', 'raw'}) || (return $self->pass_error($f->error))
$f->open('<', {'binmode', 'raw'})
Truth table50%1/2
A
A= $f->open('<', {'binmode', 'raw'})
Aresult
11
00
1286 return( $self->pass_error( $f->error ) );
1287 }
1288 }
1289  
1290 20 my $stype = lc( Scalar::Util::reftype( $src ) );
1291 20 ▶ if( $stype eq 'code' )
Branch: 1 branch
BranchTrueFalseTotal
if ($stype eq 'code') { } 0 20 20
1292 {
1293 0 ▶ if( $enc )
Branch: 2 branches
BranchTrueFalseTotal
if ($enc) { } 0 0 0
elsif ($dec) { } 0 0 0
1294 {
1295 0 my $params = $self->_io_compress_params;
1296 # try-catch
1297 0 local $@;
1298 eval
1299 0 {
1300 0 $src->( $self->encode( $data, $params ) );
1301 };
1302 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1303 {
1304 0 return( $self->error( "Error executing calback to write $size bytes of data: $@" ) );
1305 }
1306 0 $len = $size;
1307 }
1308 elsif( $dec )
1309 {
1310 0 my $params = $self->_io_compress_params;
1311 # try-catch
1312 0 local $@;
1313 eval
1314 0 {
1315 0 $src->( $self->decode( $data, $params ) );
1316 };
1317 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1318 {
1319 0 return( $self->error( "Error executing calback to write $size bytes of data: $@" ) );
1320 }
1321 0 $len = $size;
1322 }
1323 else
1324 {
1325 0 ▶ if( $type eq 'scalar' )
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'scalar') { } 0 0 0
elsif ($type eq 'glob') { } 0 0 0
1326 {
1327 0 $len = length( $$data );
1328 # try-catch
1329 0 local $@;
1330 eval
1331 0 {
1332 0 $src->( $$data );
1333 };
1334 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1335 {
1336 0 return( $self->error( "Error executing calback to write $size bytes of data: $@" ) );
1337 }
1338 }
1339 elsif( $type eq 'glob' )
1340 {
1341 0 my( $rv, $buf );
1342 0 ▶ while( $rv = CORE::read( $data, $buf, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($rv = CORE::read($data, $buf, 10240)) 0 0 0
1343 {
1344 # try-catch
1345 0 local $@;
1346 eval
1347 0 {
1348 0 $src->( $buf );
1349 };
1350 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1351 {
1352 0 return( $self->error( "Error executing calback to write $size bytes of data: $@" ) );
1353 }
1354 0 $len += length( $buf );
1355 }
1356 0 ▶ return( $self->error( "Unable to read data from glob provided: $!" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
1357 }
1358 else
1359 {
1360 0 ▶ my $f = $self->new_file( $data ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($data) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($data) || (return $self->pass_error)
$self->new_file($data)
Truth table0%0/2
A
A= $self->new_file($data)
Aresult
11
00
1361 0 ▶ my $fh = $f->open( '<' ) || return( $self->pass_error( $f->error ) );
Condition0%0/2
$f->open('<') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$f->open('<') || (return $self->pass_error($f->error))
$f->open('<')
Truth table0%0/2
A
A= $f->open('<')
Aresult
11
00
1362 0 my $buf;
1363 0 my $rv = $fh->read( $buf );
1364 0 ▶ return( $self->error( "Unable to read data from file \"$f\" provided: $!" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
1365 # try-catch
1366 0 local $@;
1367 eval
1368 0 {
1369 0 $src->( $buf );
1370 };
1371 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1372 {
1373 0 return( $self->error( "Error executing calback to write $size bytes of data: $@" ) );
1374 }
1375 0 $fh->close;
1376 0 $len = length( $buf );
1377 }
1378 }
1379 }
1380 else
1381 {
1382 20 my $filters;
1383 20 ▶ if( $dec )
Branch: 2 branches
BranchTrueFalseTotal
if ($dec) { } 0 20 20
elsif ($enc) { } 20 0 20
1384 {
1385 0 $filters = $FILTER_MAP->{decode};
1386 }
1387 elsif( $enc )
1388 {
1389 20 $filters = $FILTER_MAP->{encode};
1390 }
1391
1392 20 my $rv;
1393 20 ▶ if( $dec )
Branch: 4 branches
BranchTrueFalseTotal
if ($dec) { } 0 20 20
elsif ($enc) { } 20 0 20
elsif ($stype eq 'scalar') { } 0 0 0
elsif ($stype eq 'glob') { } 0 0 0
1394 {
1395 0 my $params = $self->_io_compress_params;
1396 0 ▶ return( $self->error( "No encoding found for \"$dec\"." ) ) if( !exists( $filters->{ $dec } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $filters->{$dec} 0 0 0
1397 # try-catch
1398 0 local $@;
1399 ( $rv, my $err ) = eval
1400 0 {
1401 0 $filters->{ $dec }->( $data => $src, %$params );
1402 };
1403 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1404 {
1405 0 ▶ return( $self->error( "Error ", ( $self->encode ? 'encoding' : 'decoding' ), " $size bytes of data: $@" ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->encode ? : 0 0 0
1406 }
1407 0 ▶ return( $self->error( "Unable to decode data to write to source: $err" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
1408 0 $len = $size;
1409 }
1410 elsif( $enc )
1411 {
1412 20 my $params = $self->_io_compress_params;
1413 20 ▶ return( $self->error( "No encoding found for \"$enc\"." ) ) if( !exists( $filters->{ $enc } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $filters->{$enc} 0 20 20
1414 # try-catch
1415 20 local $@;
1416 ( $rv, my $err ) = eval
1417 20 {
1418 20 $filters->{ $enc }->( $data => $src, %$params );
1419 };
1420 20 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 20 20
1421 {
1422 0 ▶ return( $self->error( "Error ", ( $self->encode ? 'encoding' : 'decoding' ), " $size bytes of data: $@" ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->encode ? : 0 0 0
1423 }
1424 20 ▶ return( $self->error( "Unable to encode data to write to source: $err" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 20 20
1425 20 $len = $size;
1426 }
1427 elsif( $stype eq 'scalar' )
1428 {
1429 0 ▶ if( $type eq 'scalar' )
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'scalar') { } 0 0 0
elsif ($type eq 'glob') { } 0 0 0
1430 {
1431 0 $$src .= $$data;
1432 0 $len = length( $$data );
1433 }
1434 elsif( $type eq 'glob' )
1435 {
1436 0 my( $rv, $buf );
1437 0 ▶ while( $rv = CORE::read( $data, $buf, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($rv = CORE::read($data, $buf, 10240)) 0 0 0
1438 {
1439 0 $$src .= $buf;
1440 0 $len += length( $buf );
1441 }
1442 0 ▶ return( $self->error( "Unable to read data from glob provided: $!" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
1443 }
1444 else
1445 {
1446 0 ▶ my $f = $self->new_file( $data ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($data) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($data) || (return $self->pass_error)
$self->new_file($data)
Truth table0%0/2
A
A= $self->new_file($data)
Aresult
11
00
1447 0 ▶ my $fh = $f->open( '<' ) ||
Condition0%0/2
$f->open('<') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$f->open('<') || (return $self->pass_error($f->error))
$f->open('<')
Truth table0%0/2
A
A= $f->open('<')
Aresult
11
00
1448 return( $self->pass_error( $f->error ) );
1449 0 my $buf;
1450 0 my $rv = $fh->read( $buf );
1451 0 ▶ return( $self->error( "Unable to read data from file \"$f\" provided: $!" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
1452 0 $$src .= $buf;
1453 0 $len = length( $buf );
1454 }
1455 }
1456 elsif( $stype eq 'glob' )
1457 {
1458 0 ▶ if( $type eq 'scalar' )
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'scalar') { } 0 0 0
elsif ($type eq 'glob') { } 0 0 0
1459 {
1460 0 ▶ print( $src, $$data ) ||
Branch: 1 branch
BranchTrueFalseTotal
print $src, $$data or return $self->error("Unable to write ", length $$data, " bytes of data to source glob: $!") 0 0 0
1461 return( $self->error( "Unable to write ", length( $$data ), " bytes of data to source glob: $!" ) );
1462 0 $len = length( $$data );
1463 }
1464 elsif( $type eq 'glob' )
1465 {
1466 0 my $buf;
1467 0 ▶ while( CORE::read( $data, $buf, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::read $data, $buf, 10240) 0 0 0
1468 {
1469 0 ▶ print( $src, $buf ) ||
Branch: 1 branch
BranchTrueFalseTotal
print $src, $buf or return $self->error("Unable to write ", length $buf, " bytes of data to source glob: $!") 0 0 0
1470 return( $self->error( "Unable to write ", length( $buf ), " bytes of data to source glob: $!" ) );
1471 0 $len += length( $buf );
1472 }
1473 }
1474 else
1475 {
1476 0 ▶ my $f = $self->new_file( $data ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($data) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($data) || (return $self->pass_error)
$self->new_file($data)
Truth table0%0/2
A
A= $self->new_file($data)
Aresult
11
00
1477 0 ▶ my $fh = $f->open( '<' ) ||
Condition0%0/2
$f->open('<') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$f->open('<') || (return $self->pass_error($f->error))
$f->open('<')
Truth table0%0/2
A
A= $f->open('<')
Aresult
11
00
1478 return( $self->pass_error( $f->error ) );
1479 0 my $buf;
1480 0 ▶ while( $fh->read( $buf, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->read($buf, 10240)) 0 0 0
1481 {
1482 0 ▶ print( $src, $buf ) ||
Branch: 1 branch
BranchTrueFalseTotal
print $src, $buf or return $self->error("Unable to write ", length $buf, " bytes of data to source glob: $!") 0 0 0
1483 return( $self->error( "Unable to write ", length( $buf ), " bytes of data to source glob: $!" ) );
1484 0 $len += length( $buf );
1485 }
1486 }
1487 }
1488 else
1489 {
1490 0 ▶ my $f = $self->new_file( $src ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($src) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($src) || (return $self->pass_error)
$self->new_file($src)
Truth table0%0/2
A
A= $self->new_file($src)
Aresult
11
00
1491 0 ▶ my $fh = $f->open( '>', { autoflush => 1 } ) || return( $self->pass_error( $f->error ) );
Condition0%0/2
$f->open('>', {'autoflush', 1}) || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$f->open('>', {'autoflush', 1}) || (return $self->pass_error($f->error))
$f->open('>', {'autoflush', 1})
Truth table0%0/2
A
A= $f->open('>', {'autoflush', 1})
Aresult
11
00
1492 0 ▶ if( $type eq 'scalar' )
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'scalar') { } 0 0 0
elsif ($type eq 'glob') { } 0 0 0
1493 {
1494 0 ▶ $fh->print( $$data ) ||
Branch: 1 branch
BranchTrueFalseTotal
$fh->print($$data) or return $self->error("Unable to write ", length $$data, qq[ bytes of data to file "$f": $!]) 0 0 0
1495 return( $self->error( "Unable to write ", length( $$data ), " bytes of data to file \"$f\": $!" ) );
1496 0 $len = length( $$data );
1497 }
1498 elsif( $type eq 'glob' )
1499 {
1500 0 my $buf;
1501 0 ▶ while( CORE::read( $data, $buf, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::read $data, $buf, 10240) 0 0 0
1502 {
1503 0 ▶ $fh->print( $buf ) ||
Branch: 1 branch
BranchTrueFalseTotal
$fh->print($buf) or return $self->error("Unable to write ", length $buf, qq[ bytes of data to file "$f": $!]) 0 0 0
1504 return( $self->error( "Unable to write ", length( $buf ), " bytes of data to file \"$f\": $!" ) );
1505 0 $len += length( $buf );
1506 }
1507 }
1508 else
1509 {
1510 0 ▶ my $f2 = $self->new_file( $data ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($data) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($data) || (return $self->pass_error)
$self->new_file($data)
Truth table0%0/2
A
A= $self->new_file($data)
Aresult
11
00
1511 0 ▶ my $fh2 = $f2->open( '<' ) ||
Condition0%0/2
$f2->open('<') || (return $self->pass_error($f2->error))
l!l
00
MC/DC0%0/1
$f2->open('<') || (return $self->pass_error($f2->error))
$f2->open('<')
Truth table0%0/2
A
A= $f2->open('<')
Aresult
11
00
1512 return( $self->pass_error( $f2->error ) );
1513 0 my $buf;
1514 0 ▶ while( $fh2->read( $buf, 10240 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($fh2->read($buf, 10240)) 0 0 0
1515 {
1516 0 ▶ $fh->print( $buf ) ||
Branch: 1 branch
BranchTrueFalseTotal
$fh->print($buf) or return $self->error("Unable to write ", length $buf, qq[ bytes of data to source file "$f": $!]) 0 0 0
1517 return( $self->error( "Unable to write ", length( $buf ), " bytes of data to source file \"$f\": $!" ) );
1518 0 $len += length( $buf );
1519 }
1520 0 $fh2->close;
1521 }
1522 0 $fh->close;
1523 }
1524 }
1525 20 return( $len );
1526 }
1527  
1528 sub _decodable_encodable
1529 1 ▶{
Subroutine _decodable_encodable: called CC=21 SCAR=34.7
1530 1 my $self = shift( @_ );
1531 # 1 for encodable, 0 for decodable
1532 1 my $enc_or_dec = shift( @_ );
1533 1 ▶ my $what = shift( @_ ) || 'all';
Condition50%1/2
shift @_ || 'all'
l!l
10
MC/DC0%0/1
shift @_ || 'all'
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1534 1 my $list = $self->new_array;
1535 1 ▶ my $offset = $enc_or_dec ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$enc_or_dec ? : 0 1 1
1536 1 ▶ if( $self->_is_array( $what ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_array($what)) { } 0 1 1
elsif ($what eq 'all' or $what eq 'auto') { } 0 1 1
elsif ($what eq 'browser') { } 1 0 1
1537 {
1538 0 $list = $what;
1539 }
1540 ▶ elsif( $what eq 'all' || $what eq 'auto' )
Condition33%1/3
$what eq "all" or $what eq "auto"
l!l&&r!l&&!r
001
MC/DC0%0/2
$what eq "all" or $what eq "auto"
$what eq "all" $what eq "auto"
Truth table33%1/3
A or B
A= $what eq "all"B= $what eq "auto"
ABresult
1X1
011
000
1541 {
1542 0 $list = [sort( keys( %$CLASSES ) )];
1543 }
1544 elsif( $what eq 'browser' )
1545 {
1546 1 foreach( keys( %$CLASSES ) )
1547 {
1548 27 ▶ $list->push( $_ ) if( $CLASSES->{ $_ }->[2] );
Branch: 1 branch
BranchTrueFalseTotal
if $HTTP::Promise::Stream::CLASSES->{$_}[2] 11 16 27
1549 }
1550 }
1551 else
1552 {
1553 0 return( $self->error( "Unsupported keyword '$what' used." ) );
1554 }
1555
1556 1 my $res = $self->new_array;
1557 1 foreach my $enc ( @$list )
1558 {
1559 # inflate is just an alias for deflate
1560 11 ▶ next if( $enc eq 'inflate' || $enc eq 'rawinflate' || substr( $enc, 0, 2 ) eq 'x-' );
Branch: 1 branch
BranchTrueFalseTotal
if $enc eq "inflate" or $enc eq "rawinflate" or substr($enc, 0, 2) eq "x-" 5 6 11
Condition100%6/6
$enc eq "inflate" or $enc eq "rawinflate" or substr($enc, 0, 2) eq "x-"
l!l&&r!l&&!r
236
$enc eq "inflate" or $enc eq "rawinflate"
l!l&&r!l&&!r
119
MC/DC100%3/3
$enc eq "inflate" or $enc eq "rawinflate" or substr($enc, 0, 2) eq "x-"
$enc eq "inflate" $enc eq "rawinflate" substr($enc, 0, 2) eq "x-"
Truth table100%4/4
A or B or C
A= $enc eq "inflate"B= $enc eq "rawinflate"C= substr($enc, 0, 2) eq "x-"
ABCresult
1XX1
01X1
0011
0000
1561 6 ▶ if( !exists( $CLASSES->{ $enc } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $HTTP::Promise::Stream::CLASSES->{$enc}) 0 6 6
1562 {
1563 0 ▶ warn( "Unsupported content encoding \"$enc\"." ) if( $self->_is_warnings_enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTTP::Promise") 0 0 0
1564 0 next;
1565 }
1566 6 my $encoder_class = $CLASSES->{ $enc }->[$offset];
1567 6 ▶ my $is_installed_method = ( $enc_or_dec ? 'is_encoder_installed' : 'is_decoder_installed' );
Branch: 1 branch
BranchTrueFalseTotal
$enc_or_dec ? : 0 6 6
1568 # Load the module if it is one of ours, so we can then use the method 'is_encoder_installed' or 'is_decoder_installed'
1569 6 ▶ if( substr( $encoder_class, 0, length( 'HTTP::Promise::Stream' ) ) eq 'HTTP::Promise::Stream' )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($encoder_class, 0, 21) eq "HTTP::Promise::Stream") 2 4 6
1570 {
1571 2 ▶ $self->_load_class( $encoder_class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($encoder_class) or return $self->pass_error 2 0 2
1572 }
1573  
1574 6 ▶ if( my $coderef = $encoder_class->can( $is_installed_method ) )
Branch: 2 branches
BranchTrueFalseTotal
if (my $coderef = $encoder_class->can($is_installed_method)) { } 2 4 6
elsif ($self->_is_class_loadable($encoder_class)) { } 4 0 4
1575 {
1576 2 my $rv = $coderef->();
1577 2 ▶ $res->push( $enc ) if( $coderef->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$coderef() 2 0 2
1578 }
1579 elsif( $self->_is_class_loadable( $encoder_class ) )
1580 {
1581 4 $res->push( $enc );
1582 }
1583 }
1584 1 return( $res );
1585 }
1586  
1587 sub _encoding2suffix_map
1588 5 ▶{
Subroutine _encoding2suffix_map: called CC=3 SCAR=12.3
1589 5 my $self = shift( @_ );
1590 5 ▶ unless( defined( $ENCODING_SUFFIX ) && %$ENCODING_SUFFIX )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $HTTP::Promise::Stream::ENCODING_SUFFIX and %$HTTP::Promise::Stream::ENCODING_SUFFIX) 0 5 5
Condition33%1/3
defined $HTTP::Promise::Stream::ENCODING_SUFFIX and %$HTTP::Promise::Stream::ENCODING_SUFFIX
!ll&&!rl&&r
005
MC/DC0%0/2
defined $HTTP::Promise::Stream::ENCODING_SUFFIX and %$HTTP::Promise::Stream::ENCODING_SUFFIX
defined $HTTP::Promise::Stream::ENCODING_SUFFIX %$HTTP::Promise::Stream::ENCODING_SUFFIX
Truth table33%1/3
A and B
A= defined $HTTP::Promise::Stream::ENCODING_SUFFIXB= %$HTTP::Promise::Stream::ENCODING_SUFFIX
ABresult
0X0
100
111
1591 {
1592 # Initialisation défensive - normalement déjà fait dans le bloc BEGIN
1593 0 $ENCODING_SUFFIX = {};
1594 }
1595 5 my $copy = { %{$ENCODING_SUFFIX} };
1596 5 return( $copy );
1597 }
1598  
1599 sub _get_size
1600 91 ▶{
Subroutine _get_size: called CC=13 SCAR=27.3
1601 91 my $self = shift( @_ );
1602 91 ▶ if( ref( $_[0] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0]) { } 57 34 91
elsif (not ref $_[0] and index($_[0], "\n") == -1 && !(-e $_[0]) || (index($_[0], "\n") != -1)) { } 4 30 34
1603 {
1604 57 my $type = lc( Scalar::Util::reftype( $_[0] ) );
1605 57 ▶ if( $type eq 'scalar' )
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'scalar') { } 41 16 57
elsif ($type eq 'glob') { } 12 4 16
elsif ($self->_is_a($_[0], 'Module::Generic::File')) { } 4 0 4
1606 {
1607 41 return( length( ${$_[0]} ) );
1608 }
1609 elsif( $type eq 'glob' )
1610 {
1611 12 ▶ if( $self->_is_a( $_[0] => 'Module::Generic::Scalar::IO' ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_a($_[0], 'Module::Generic::Scalar::IO')) { } 8 4 12
elsif ($self->_is_object($_[0]) and $self->_can($_[0], 'size')) { } 0 4 4
elsif (fileno $_[0]) { } 4 0 4
1612 {
1613 8 return( $_[0]->size );
1614 }
1615 ▶ elsif( $self->_is_object( $_[0] ) && $self->_can( $_[0] => 'size' ) )
Condition33%1/3
$self->_is_object($_[0]) and $self->_can($_[0], "size")
!ll&&!rl&&r
040
MC/DC0%0/2
$self->_is_object($_[0]) and $self->_can($_[0], "size")
$self->_is_object($_[0]) $self->_can($_[0], "size")
Truth table33%1/3
A and B
A= $self->_is_object($_[0])B= $self->_can($_[0], "size")
ABresult
0X0
100
111
1616 {
1617 0 return( $_[0]->size );
1618 }
1619 elsif( fileno( $_[0] ) )
1620 {
1621 4 return( -s( $_[0] ) );
1622 }
1623 }
1624 elsif( $self->_is_a( $_[0] => 'Module::Generic::File' ) )
1625 {
1626 4 return( $_[0]->size );
1627 }
1628 0 return;
1629 }
1630 # If the data provided is not a reference i.e. a string and it does not have any
1631 # CRLF sequence and it is not a file that exists, OR it has multiple CRLF
1632 # sequences, then we treat it as a string, and to remove ambiguity, we make it a
1633 # scalar reference
1634 ▶ elsif( !ref( $_[0] ) &&
Condition66%6/9
not ref $_[0] and index($_[0], "\n") == -1 && !(-e $_[0]) || (index($_[0], "\n") != -1)
!ll&&!rl&&r
0304
index($_[0], "\n") == -1 and not -e $_[0] or (index($_[0], "\n") != -1)
l!l&&r!l&&!r
4030
index($_[0], "\n") == -1 and not -e $_[0]
!ll&&!rl&&r
0304
MC/DC25%1/4
not ref $_[0] and index($_[0], "\n") == -1 && !(-e $_[0]) || (index($_[0], "\n") != -1)
not ref $_[0] index($_[0], "\n") == -1 not -e $_[0] (index($_[0], "\n") != -1)
Truth table33%2/6
not(A) and B and not(C) or D
A= not ref $_[0]B= index($_[0], "\n") == -1C= not -e $_[0]D= (index($_[0], "\n") != -1)
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
1635 (
1636 ( index( $_[0], "\n" ) == -1 && !-e( $_[0] ) ) ||
1637 ( index( $_[0], "\n" ) != -1 )
1638 ) )
1639 {
1640 4 return( length( $_[0] ) );
1641 }
1642 else
1643 {
1644 30 return( -s( $_[0] ) );
1645 }
1646 }
1647  
1648 sub _io_compress_params
1649 95 ▶{
Subroutine _io_compress_params: called CC=3 SCAR=11.0
1650 95 my $self = shift( @_ );
1651 95 my $opts = {};
1652 95 my $ref = $self->compress_params;
1653 95 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 75 20 95
1654 {
1655 75 $opts = shift( @_ );
1656 75 my @keys = grep( /^[A-Z]\w+$/, keys( %$opts ) );
1657 75 ▶ @$ref{ @keys } = @$opts{ @keys } if( scalar( @keys ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @keys 0 75 75
1658 }
1659 95 return( $ref );
1660 }
1661  
1662 # Because the IO::Compress and IO::Uncompress family does not recognise a scalar object
1663 # as a valid scalar reference, we have to normalise it, before we can pass it to the filters
1664 # Remove this once IO::Compress has accepted my pull request to change
1665 # IO::Compress::Base::Common->whatIs made on 2022-04-11
1666 # <https://github.com/pmqs/IO-Compress/pull/40>
1667 sub _normalise
1668 51 ▶{
Subroutine _normalise: called CC=7 SCAR=23.7
1669 51 my $self = shift( @_ );
1670 51 ▶ if( ref( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 29 22 51
1671 {
1672 29 my $type = lc( Scalar::Util::reftype( $_[0] ) );
1673 29 ▶ if( $type eq 'scalar' )
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'scalar') { } 29 0 29
elsif ($type eq 'glob') { } 0 0 0
elsif ($self->_is_a($_[0], 'Module::Generic::File') or $self->_can($_[0], 'filename')) { } 0 0 0
1674 {
1675 # if it is a regular scalar reference, we return it
1676 # return( $self->_is_object( $_[0] ) ? \${$_[0]} : $_[0] );
1677 29 ▶ if( $self->_is_object( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($_[0])) { } 9 20 29
1678 {
1679 9 my $tmp = ${$_[0]};
1680 9 return( \$tmp );
1681 }
1682 else
1683 {
1684 20 return( $_[0] );
1685 }
1686 }
1687 elsif( $type eq 'glob' )
1688 {
1689 0 return( $_[0] );
1690 }
1691 ▶ elsif( $self->_is_a( $_[0] => 'Module::Generic::File' ) || $self->_can( $_[0] => 'filename' ) )
Condition0%0/3
$self->_is_a($_[0], "Module::Generic::File") or $self->_can($_[0], "filename")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_is_a($_[0], "Module::Generic::File") or $self->_can($_[0], "filename")
$self->_is_a($_[0], "Module::Generic::File") $self->_can($_[0], "filename")
Truth table0%0/3
A or B
A= $self->_is_a($_[0], "Module::Generic::File")B= $self->_can($_[0], "filename")
ABresult
1X1
011
000
1692 {
1693 0 return( $_[0]->filename );
1694 }
1695 else
1696 {
1697 0 return( $_[0] );
1698 }
1699 }
1700 else
1701 {
1702 22 return( $_[0] );
1703 }
1704 }
1705  
1706 # NOTE: sub FREEZE is inherited
1707  
1708 1 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
1709  
1710 1 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
1711  
1712 # NOTE: sub THAW is inherited
1713  
1714 # NOTE: HTTP::Promise::Stream::Generic class
1715 {
1716 package
1717 HTTP::Promise::Stream::Generic;
1718 BEGIN
1719 12 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
1720 12 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1721 12 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1722 12 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
1723 12 ▶ use vars qw( $VERSION $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
1724 12 ▶ use Module::Generic::File::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
1725 12 ▶ use Module::Generic::Scalar::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
1726 # use Nice::Try;
1727 12 our $EXCEPTION_CLASS = 'HTTP::Promise::Exception';
1728 12 our $VERSION = $HTTP::Promise::Stream::VERSION;
1729 };
1730  
1731 12 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1732 12 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1733  
1734 sub init
1735 21 ▶ {
Subroutine init: called CC=4 SCAR=14.3
1736 21 my $self = shift( @_ );
1737 21 ▶ my $class = ( ref( $self ) || $self );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
2100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1738 21 $self->{_init_strict_use_sub} = 1;
1739 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1740 21 ▶ $self->{_exception_class} = defined( ${"${class}\::EXCEPTION_CLASS"} ) ? ${"${class}\::EXCEPTION_CLASS"} : $EXCEPTION_CLASS;
Branch: 1 branch
BranchTrueFalseTotal
defined ${"${class}::EXCEPTION_CLASS";} ? : 21 0 21
1741 21 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 21 0 21
1742 21 return( $self );
1743 }
1744  
1745 sub _get_glob_from_arg
1746 32 ▶ {
Subroutine _get_glob_from_arg: called CC=27 SCAR=49.1
1747 32 my $self = shift( @_ );
1748 32 my $this = shift( @_ );
1749 32 ▶ return( $self->error( "No argument was provided." ) ) if( !defined( $this ) || ( !ref( $this ) && !length( $this ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and ref $this || length $this 0 32 32
Condition50%3/6
defined $this and ref $this || length $this
!ll&&!rl&&r
0032
ref $this or length $this
l!l&&r!l&&!r
21110
MC/DC0%0/3
defined $this and ref $this || length $this
defined $this ref $this length $this
Truth table50%2/4
A and B or C
A= defined $thisB= ref $thisC= length $this
ABCresult
0XX0
1000
11X1
1011
1750 32 my $opts = $self->_get_args_as_hash( @_ );
1751 32 ▶ $opts->{write} = 0 if( !exists( $opts->{write} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"write"} 16 16 32
1752 32 ▶ my $mode = $opts->{write} ? '+>' : '<';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'write'} ? : 16 16 32
1753 32 my $fh;
1754 32 my $is_native_glob = 0;
1755 32 ▶ if( $self->_is_glob( $this ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_glob($this)) { } 3 29 32
elsif ($self->_is_scalar($this)) { } 15 14 29
1756 {
1757 3 $fh = $this;
1758 # even if this is a scalar reference opened in memory, perl will return -1, which is true
1759 3 ▶ $is_native_glob++ if( fileno( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
if fileno $this 3 0 3
1760 }
1761 elsif( $self->_is_scalar( $this ) )
1762 {
1763 15 ▶ $fh = Module::Generic::Scalar::IO->new( $this, $mode ) ||
Condition50%1/2
'Module::Generic::Scalar::IO'->new($this, $mode) || (return $self->pass_error('Module::Generic::Scalar::IO'->error))
l!l
150
MC/DC0%0/1
'Module::Generic::Scalar::IO'->new($this, $mode) || (return $self->pass_error('Module::Generic::Scalar::IO'->error))
'Module::Generic::Scalar::IO'->new($this, $mode)
Truth table50%1/2
A
A= 'Module::Generic::Scalar::IO'->new($this, $mode)
Aresult
11
00
1764 return( $self->pass_error( Module::Generic::Scalar::IO->error ) );
1765 15 $is_native_glob++;
1766 }
1767 else
1768 {
1769 14 ▶ my $f = $self->new_file( "$this" ) || return( $self->pass_error );
Condition50%1/2
$self->new_file("$this") || (return $self->pass_error)
l!l
140
MC/DC0%0/1
$self->new_file("$this") || (return $self->pass_error)
$self->new_file("$this")
Truth table50%1/2
A
A= $self->new_file("$this")
Aresult
11
00
1770 14 ▶ return( $self->error( "File '$this' does not exist." ) ) if( !$f->exists && !$opts->{write} );
Branch: 1 branch
BranchTrueFalseTotal
unless $f->exists or $opts->{"write"} 0 14 14
Condition66%2/3
$f->exists or $opts->{"write"}
l!l&&r!l&&!r
4100
MC/DC0%0/2
$f->exists or $opts->{"write"}
$f->exists $opts->{"write"}
Truth table66%2/3
A or B
A= $f->existsB= $opts->{"write"}
ABresult
1X1
011
000
1771 14 ▶ $fh = $f->open( $mode, { binmode => 'raw', ( $opts->{write} ? ( autoflush => 1 ) : () ) } ) ||
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'write'} ? : 10 4 14
Condition50%1/2
$f->open($mode, {'binmode', 'raw', $opts->{'write'} ? ('autoflush', 1) : ()}) || (return $self->pass_error($f->error))
l!l
140
MC/DC0%0/1
$f->open($mode, {'binmode', 'raw', $opts->{'write'} ? ('autoflush', 1) : ()}) || (return $self->pass_error($f->error))
$f->open($mode, {'binmode', 'raw', $opts->{'write'} ? ('autoflush', 1) : ()})
Truth table50%1/2
A
A= $f->open($mode, {'binmode', 'raw', $opts->{'write'} ? ('autoflush', 1) : ()})
Aresult
11
00
1772 return( $self->pass_error( $f->error ) );
1773 14 $is_native_glob++;
1774 }
1775 32 my $flags;
1776 32 ▶ if( $self->_can( $fh => 'fcntl' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can($fh, 'fcntl')) { } 32 0 32
1777 {
1778 32 $flags = $fh->fcntl( F_GETFL, 0 );
1779 }
1780 else
1781 {
1782 0 $flags = fcntl( $fh, F_GETFL, 0 );
1783 }
1784
1785 32 ▶ if( defined( $flags ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $flags) 32 0 32
1786 {
1787 32 ▶ if( $opts->{write} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'write'}) { } 16 16 32
1788 {
1789 16 ▶ unless( $flags & ( O_RDWR | O_WRONLY | O_APPEND ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($flags & 1027) 0 16 16
1790 {
1791 0 return( $self->error( "Filehandle provided does not have write permission enabled." ) );
1792 }
1793 }
1794 # read mode then
1795 else
1796 {
1797 16 ▶ unless( ( ( $flags & O_RDONLY ) == O_RDONLY ) || ( $flags & O_RDWR ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (($flags & 0) == 0 or $flags & 2) 0 16 16
Condition33%1/3
($flags & 0) == 0 or $flags & 2
l!l&&r!l&&!r
1600
MC/DC0%0/2
($flags & 0) == 0 or $flags & 2
($flags & 0) == 0 $flags & 2
Truth table33%1/3
A or B
A= ($flags & 0) == 0B= $flags & 2
ABresult
1X1
011
000
1798 {
1799 0 return( $self->error( "Filehandle provided does not have read permission enabled. File handle flags value is '$flags'" ) );
1800 }
1801 }
1802 }
1803
1804 # We check if the file handle is an object, in which case we use its method, because
1805 # it may not be a true glob and calling perl's core read() or print() on it would not
1806 # work unless that glob object has implemented a tie. See perltie manual page.
1807 32 my $op;
1808 my $meth;
1809 32 ▶ if( $opts->{write} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'write'}) { } 16 16 32
1810 {
1811 16 ▶ if( $is_native_glob )
Branch: 2 branches
BranchTrueFalseTotal
if ($is_native_glob) { } 16 0 16
elsif ($meth = $self->_can($fh, 'print') || $self->_can($fh, 'write')) { } 0 0 0
1812 {
1813 $op = sub
1814 344 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.1
1815 344 my $rv = print( $fh @_ );
1816 344 ▶ return( $self->error( "Error writing ", CORE::length( $_[0] ), " bytes of data to output: $!" ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 344 344
1817 344 return( $rv );
1818 16 };
1819 }
1820 ▶ elsif( ( $meth = ( $self->_can( $fh => 'print' ) || $self->_can( $fh => 'write' ) ) ) )
Condition0%0/3
$self->_can($fh, 'print') || $self->_can($fh, 'write')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_can($fh, 'print') || $self->_can($fh, 'write')
$self->_can($fh, 'print') $self->_can($fh, 'write')
Truth table0%0/3
A || B
A= $self->_can($fh, 'print')B= $self->_can($fh, 'write')
ABresult
1X1
011
000
1821 {
1822 $op = sub
1823 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
1824 # try-catch
1825 0 local $@;
1826 my $rv = eval
1827 0 {
1828 0 $fh->$meth( @_ );
1829 };
1830 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1831 {
1832 0 return( $self->error( "Error writing ", CORE::length( $_[0] ), " bytes of data to output: $@" ) );
1833 }
1834 0 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rv) 0 0 0
1835 {
1836 0 my $err;
1837 0 ▶ if( defined( $! ) )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $!) { } 0 0 0
elsif ($self->_can($fh, 'error')) { } 0 0 0
elsif ($self->_can($fh, 'errstr')) { } 0 0 0
1838 {
1839 0 $err = $!;
1840 }
1841 elsif( $self->_can( $fh => 'error' ) )
1842 {
1843 0 $err = $fh->error;
1844 }
1845 elsif( $self->_can( $fh => 'errstr' ) )
1846 {
1847 0 $err = $fh->errstr;
1848 }
1849 0 return( $self->error( "Error writing ", CORE::length( $_[0] ), " bytes of data to output: $err" ) );
1850 }
1851 0 return( $rv );
1852 0 };
1853 }
1854 else
1855 {
1856 0 return( $self->error( "The file handle provided is not a native opened one and does not support the print() or write() methods." ) );
1857 }
1858 }
1859 else
1860 {
1861 16 ▶ if( $is_native_glob )
Branch: 2 branches
BranchTrueFalseTotal
if ($is_native_glob) { } 16 0 16
elsif ($self->_can($fh, 'read')) { } 0 0 0
1862 {
1863 $op = sub
1864 329 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.1
1865 329 my $n = read( $fh, $_[0], $_[1] );
1866 329 ▶ return( $self->error( "Error reading ", $_[1], " bytes of data from input: $!" ) ) if( !defined( $n ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 329 329
1867 329 return( $n );
1868 16 };
1869 }
1870 elsif( $self->_can( $fh => 'read' ) )
1871 {
1872 $op = sub
1873 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
1874 # try-catch
1875 0 local $@;
1876 my $n = eval
1877 0 {
1878 0 $fh->read( @_ );
1879 };
1880 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1881 {
1882 0 return( $self->error( "Error reading ", $_[1], " bytes of data from input: $@" ) );
1883 }
1884 0 ▶ if( !defined( $n ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n) 0 0 0
1885 {
1886 0 my $err;
1887 0 ▶ if( defined( $! ) )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $!) { } 0 0 0
elsif ($self->_can($fh, 'error')) { } 0 0 0
elsif ($self->_can($fh, 'errstr')) { } 0 0 0
1888 {
1889 0 $err = $!;
1890 }
1891 elsif( $self->_can( $fh => 'error' ) )
1892 {
1893 0 $err = $fh->error;
1894 }
1895 elsif( $self->_can( $fh => 'errstr' ) )
1896 {
1897 0 $err = $fh->errstr;
1898 }
1899 0 return( $self->error( "Error reading ", $_[1], " bytes of data from intput: $err" ) );
1900 }
1901 0 return( $n );
1902 0 };
1903 }
1904 else
1905 {
1906 0 return( $self->error( "The file handle provided is not a native opened one and does not support the read() method." ) );
1907 }
1908 }
1909 32 return( $fh, $op );
1910 }
1911  
1912 # NOTE: sub FREEZE is inherited
1913  
1914 4 ▶ sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
1915  
1916 4 ▶ sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
1917  
1918 # NOTE: sub THAW is inherited
1919 }
1920  
1921 12 1;
1922 # NOTE: POD
1923 __END__
« Promise/Request.pm ↑ Summary Promise/Headers.pm »