Branch Coverage

lib/HTTP/Promise/Entity.pm
Criterion Covered Total %
branch 281 698 40.2


line true false branch
57 0 155 unless $self->SUPER::init(@_)
66 0 5 unless $self->_is_a($part, "HTTP::Promise::Entity")
68 5 0 unless defined $index
69 5 0 if $index < 0
78 0 1 unless lc $type eq "multipart/form-data"
79 0 1 unless $self->_load_class("HTTP::Promise::Body::Form::Data")
84 0 1 if $parts->is_empty
91 0 4 unless $dispo
93 0 4 unless defined $cd
95 0 4 unless defined $name and length "$name"
97 0 4 if ($part->is_encoded and $encodings)
108 0 4 unless defined $field
110 0 4 if (exists $form->{$name}) { }
128 28 2 if defined $eol
134 0 0 if (exists $opts->{'binmode'} and length $opts->{'binmode'} and lc substr($opts->{'binmode'}, 0, 3) eq "utf")
143 28 2 scalar keys %$opts ? :
0 30 unless $self->print($fh, scalar keys %$opts ? $opts : ())
145 0 30 if (defined $binmode)
147 0 0 unless $self->_load_class("Encode")
154 0 0 if ($@)
166 0 3 unless $self->make_multipart
177 0 0 @_ ? :
178 0 0 if scalar @_
182 0 0 unless $self->print_body($fh)
201 0 0 if (exists $opts->{'binmode'} and length $opts->{'binmode'} and lc substr($opts->{'binmode'}, 0, 3) eq "utf")
210 0 1 scalar keys %$opts ? :
0 1 unless $self->print_body($fh, scalar keys %$opts ? $opts : ())
212 0 1 if (defined $binmode)
214 0 0 unless $self->_load_class("Encode")
221 0 0 if ($@)
236 2 15 $type =~ m[^multipart/]i ? :
239 3 14 exists $opts->{'top'} ? :
260 2 15 exists $opts->{'filename'} ? :
261 0 17 if defined $filename and $filename eq ""
263 3 8 if (defined $filename and length $filename and $filename =~ /[^\w\.]+/)
267 3 14 if (defined $encoding and $type =~ m[^(multipart/|message/(rfc822|partial|external-body|delivery-status|disposition-notification|feedback-report|http)$)]i)
274 2 15 if ($is_multipart) { }
277 0 2 if (defined($boundary = delete $opts->{'boundary'}))
279 0 0 if (not length $boundary) { }
0 0 elsif ($boundary =~ m[[^0-9a-zA-Z_\'\(\)\+\,\.\/\:\=\?\- ]]) { }
281 0 0 if $self->_warnings_is_enabled
286 0 0 if $self->_warnings_is_enabled
291 2 0 unless defined $boundary
297 12 3 if (defined $path and length $path) { }
3 0 elsif (defined $data and length $data) { }
301 0 12 unless $new->body($f)
309 0 3 unless $new->body($s)
319 0 17 unless defined $ct
320 1 16 if $charset
321 3 14 if (defined $filename_utf8) { }
8 6 elsif (defined $filename) { }
329 2 15 if defined $boundary
332 3 14 if (defined $encoding and lc $encoding eq "suggest")
338 11 4 if (not $is_multipart and defined $disposition || defined $filename)
340 10 1 unless defined $disposition
341 11 0 defined $disposition ? :
342 0 11 unless defined $field
343 3 8 if (defined $filename_utf8) { }
8 0 elsif (defined $filename) { }
353 2 15 if defined $encoding and length $encoding
354 0 17 if (defined $desc and length $desc)
356 0 0 if $self->_warnings_is_enabled
359 0 17 if (defined $id)
361 0 0 if $self->_warnings_is_enabled
367 40 0 unless exists $opts->{$_}
369 0 0 if (not defined $opts->{$_}) { }
0 0 elsif (length $opts->{$_}) { }
376 0 0 $self->_is_array($opts->{$_}) ? :
395 10 0 if defined $headers
396 6 4 if defined $body
398 1 9 unless ($parts->is_empty)
406 0 1 if ($paddr eq $addr)
416 10 0 if defined $new_headers
417 6 4 if defined $new_body
418 0 10 if $self->name
426 3 7 if ($msg = $self->http_message and $opts->{'clone_message'})
449 0 0 if (my $charset = $headers->content_type_charset and !exists $opts->{'content_type_charset'} || $opts->{'content_type_charset'})
455 0 11 unless $self->_load_class("Encode")
456 2 9 unless (defined $HTTP::Promise::Entity::BOM2ENC and scalar %$HTTP::Promise::Entity::BOM2ENC)
488 6 5 if (exists $opts->{'content'} and length $opts->{'content'}) { }
490 0 6 if ref $opts->{'content'} and not $self->_is_scalar($opts->{'content'})
491 6 0 $self->_is_scalar($opts->{'content'}) ? :
500 0 5 unless defined $bytes
501 0 5 unless $bytes
506 6 5 if ($$cref =~ /^($HTTP::Promise::Entity::BOM_RE)/)
513 0 5 if $$cref =~ /^\xEF\xBB\xBF/
514 0 5 if $$cref =~ /^\xFF\xFE\x00\x00/
515 0 5 if $$cref =~ /^\x00\x00\xFE\xFF/
516 0 5 if $$cref =~ /^\xFF\xFE/
517 0 5 if $$cref =~ /^\xFE\xFF/
519 0 5 if ($headers->content_is_xml) { }
5 0 elsif ($headers->content_is_text) { }
0 0 elsif ($headers->content_type eq 'application/json') { }
525 0 0 if $$cref =~ /^\x00\x00\x00</
526 0 0 if $$cref =~ /^<\x00\x00\x00/
527 0 0 if $$cref =~ /^(?:\x00\s)*\x00</
528 0 0 if $$cref =~ /^(?:\s\x00)*<\x00/
529 0 0 if ($$cref =~ /^[[:blank:]\h]*(<\?xml[^\x00]*?\?>)/)
531 0 0 if ($1 =~ /[[:blank:]\h\v]encoding[[:blank:]\h\v]*=[[:blank:]\h\v]*(["'])(.*?)\1/)
536 0 0 if $enc
544 0 0 ref $encoding ? :
0 5 if $encoding
549 0 0 if $$cref =~ /^\x00\x00\x00./s
550 0 0 if $$cref =~ /^.\x00\x00\x00/s
551 0 0 if $$cref =~ /^\x00.\x00./s
552 0 0 if $$cref =~ /^.\x00.\x00/s
556 5 0 if ($headers->content_type =~ m[^text/])
558 0 5 if (length $$cref)
560 0 0 unless $$cref =~ /[\x80-\xFF]/
569 0 0 if ($@)
585 0 21 unless defined $this
586 0 4 if not $self->_is_array($this) and (ref $this and not overload::Method($this, "\"\""))
587 17 4 $self->_is_array($this) ? :
590 0 21 unless $self->_load_class("HTTP::Promise::Stream")
592 0 21 if not scalar @$encodings and warnings::enabled(ref $self)
594 0 21 unless $body and scalar @$encodings
612 0 21 if ($body->isa('HTTP::Promise::Body::File')) { }
21 0 elsif ($body->isa('HTTP::Promise::Body::Scalar')) { }
615 0 0 if ($f->is_empty)
617 0 0 if warnings::enabled(ref $self)
623 0 0 if ($ext_vary)
630 0 0 if $enc eq "identity" or $enc eq "none"
632 0 0 if exists $enc2params->{$enc}
639 0 0 if ($ext_vary and $ext_enc = $s->encoding2suffix($enc)->first and $ext_parts->[-1] eq $ext_enc)
649 0 0 unless (defined $len)
651 0 0 if ($enc eq 'deflate' or $enc eq 'inflate') { }
654 0 0 if ($s->error->message =~ /Header Error: CRC mismatch/) { }
658 0 0 if exists $enc2params->{$enc}
665 0 0 unless defined $len
677 0 0 unless $len
682 0 0 if ($opts->{'replace'})
691 0 21 if ($body->is_empty)
693 0 0 if warnings::enabled(ref $self)
699 2 30 if $enc eq "identity" or $enc eq "none"
701 8 22 if exists $enc2params->{$enc}
712 1 26 unless (defined $len)
714 1 0 if ($enc eq 'deflate' or $enc eq 'inflate') { }
717 1 0 if ($s->error->message =~ /Header Error: CRC mismatch/) { }
721 1 0 if exists $enc2params->{$enc}
729 0 1 unless defined $len
741 0 27 unless $len
745 14 4 if ($opts->{'replace'}) { }
770 0 2 unless defined $maxlen
772 2 0 unless defined $no_content
777 2 0 if defined $mime_type
780 2 0 if (defined $body) { }
0 0 elsif (not $self->part->is_empty) { }
785 0 2 unless defined $bytes
789 0 2 if defined $encoding and length $encoding
790 0 2 unless $self->_load_class("HTTP::Promise::Stream")
792 0 2 if (scalar @$encodings and not $self->is_encoded)
802 0 0 unless defined $len
803 0 0 unless ($len)
811 0 0 unless $has_error
814 2 0 if (length $content) { }
816 0 2 if ($self->is_binary(\$content)) { }
822 1 1 if ($maxlen and $body->length > $maxlen)
841 0 2 if ($content eq $no_content)
852 1 1 if $chopped
858 0 0 if (defined $toptype and $toptype eq 'multipart') { }
864 0 0 if (defined $plines)
868 0 0 if @$plines > 0
884 0 0 if (defined $epilogue and not $epilogue->is_empty)
887 0 0 unless ($epilogue =~ /(?:\015?\012)\Z/)
902 0 0 if ($need_sep++)
912 0 2 if $opts->{'preheader'}
914 0 2 if ($self->http_message and $start_line = $self->http_message->start_line)
921 0 2 if $opts->{'prefix'}
929 0 0 unless $fh
930 0 0 unless defined $indent
936 0 0 if (my $msg = $self->http_message)
938 0 0 if ($msg->isa('HTTP::Promise::Request')) { }
946 0 0 if @first_line
949 0 0 unless print $fh $headers->as_string, $crlf
951 0 0 if ($body)
953 0 0 if ($body->isa('HTTP::Promise::Body::File')) { }
0 0 elsif ($body->isa('HTTP::Promise::Body::Form')) { }
955 0 0 unless print $fh "${ind}Body is stored in a temporary file at '", $body->filename, "' and is ", $body->length, " bytes big.$crlf"
960 0 0 unless print $fh "${ind}Body is a x-www-form-urlencoded data with ", $body->length, " elements:\n", $body->dump
965 0 0 unless print $fh "${ind}Body is stored in memory and is ", $body->length, " bytes big.$crlf"
969 0 0 if (my $cd = $headers->content_disposition)
971 0 0 unless print $fh "${ind}Body is encoded using $cd\n"
974 0 0 if $filename
990 10 13 if (@_)
1001 0 6 if not defined $this or not $self->_is_array($this) and (ref $this and not overload::Method($this, "\"\""))
1002 6 6 $self->_is_array($this) ? :
1003 0 12 unless $self->_load_class("HTTP::Promise::Stream")
1005 0 12 if not scalar @$encodings and warnings::enabled(ref $self)
1007 0 12 unless $body
1009 1 11 if ($body->isa('HTTP::Promise::Body::File')) { }
11 0 elsif ($body->isa('HTTP::Promise::Body::Scalar')) { }
1012 0 1 if ($f->is_empty)
1014 0 0 if warnings::enabled(ref $self)
1020 0 2 if $enc eq "identity" or $enc eq "none"
1021 0 2 if ++$seen->{$enc} > 1
1024 0 2 if ($self->ext_vary)
1028 0 0 unless ($enc_ext->is_empty)
1035 0 2 unless defined $len
1036 0 2 unless $len
1046 0 11 if ($body->is_empty)
1048 0 0 if warnings::enabled(ref $self)
1054 2 11 if $enc eq "identity" or $enc eq "none"
1055 0 11 if ++$seen->{$enc} > 1
1060 0 10 unless defined $len
1061 0 10 unless $len
1085 5 0 if (exists $opts->{'content'} and length $opts->{'content'}) { }
1087 0 5 if ref $opts->{'content'} and not $self->_is_scalar($opts->{'content'})
1088 5 0 $self->_is_scalar($opts->{'content'}) ? :
1093 0 0 if not $body or $body->is_empty
1099 0 0 unless defined $bytes
1102 0 5 if $self->is_binary($data)
1105 0 5 if ($$data =~ /^\xFe\xFF/) { }
0 5 elsif ($$data =~ /^\xFF\xFe/) { }
0 5 elsif ($$data =~ /^\xEF\xBB\xBF/) { }
1119 5 0 unless (defined $encoding)
1121 0 5 unless $self->_load_class("Encode")
1124 0 5 if ($$data =~ /^(?: # nothing left over
1134 0 0 if (defined $encoding and $opts->{'object'} and not ref $encoding)
1138 0 0 unless $self->_load_class("Encode")
1141 0 5 defined $encoding ? :
1162 2 0 if (not exists $opts->{'content'} and $opts->{'charset_strict'} && $self->{'_io_encoding_strict_cached'} || !$opts->{'charset_strict'} && $self->{'_io_encoding_cached'} and $body and $self->{'_checksum_md5'} eq $body->checksum_md5)
1169 0 2 $opts->{'charset_strict'} ? :
1172 0 11 if (exists $opts->{'content'} and length $opts->{'content'}) { }
1174 0 0 if ref $opts->{'content'} and not $self->_is_scalar($opts->{'content'})
1175 0 0 $self->_is_scalar($opts->{'content'}) ? :
1180 0 11 unless $body
1186 0 11 unless defined $bytes
1187 0 11 unless $bytes
1193 9 2 if ($headers->content_is_text or my $is_xml = $headers->content_is_xml)
1203 0 9 if ($charset eq 'none') { }
0 9 elsif ($charset eq 'us-ascii' or $charset eq 'iso-8859-1') { }
1210 0 0 if ($$data =~ /[^\x00-\x7F]/)
1217 0 9 unless $self->_load_class("Encode")
1222 2 7 $opts->{'charset_strict'} ? :
1225 2 7 if ($@)
1228 0 2 if ($@ =~ /^Unknown encoding/)
1231 0 0 if ($alt_charset and $charset ne $alt_charset)
1234 0 0 $opts->{'charset_strict'} ? :
0 0 unless $alt_charset eq "none"
1239 2 0 unless $retried
1243 0 9 if ($opts->{'charset_strict'}) { }
1251 7 2 defined $enc ? :
1262 0 7 unless $self->_load_class("Encode")
1264 7 0 if (@_) { }
1268 0 7 unless defined $this and length "$this"
1269 0 7 if ref $this and not $self->_is_scalar($this)
1270 7 0 ref $this ? :
1275 0 0 if not $body or $body->is_empty
1281 0 0 unless defined $bytes
1282 0 0 if not $bytes and warnings::enabled()
1283 0 0 unless $bytes
1295 0 7 if (utf8::is_utf8($$data))
1301 0 0 $@ ? :
1313 0 7 if index($$data, "\0") != -1
1322 0 7 if ($copy =~ tr/\200-\377//d > 0)
1328 0 7 if $odd / $length > "0.34"
1336 0 0 if not $body or $body->is_empty
1344 0 0 if not $body or $body->is_empty
1352 14 0 if (@_) { }
1369 0 5 unless $self->headers
1371 1 4 unless defined $mime_type and length $mime_type
1372 3 1 substr(lc $mime_type, 0, 9) eq 'multipart' ? :
1397 3 2 if $self->is_multipart and not $force
1441 1 1 if $part->body or $part->parts->length
1450 0 0 unless $self->is_multipart
1452 0 0 if $self->parts > 1
1462 0 0 if ($self->parts->length == 1) { }
1478 0 0 if $self->is_multipart
1492 0 105 unless defined $headers
1511 1 58 if ($type eq "form")
1513 0 1 unless $self->_load_class($class)
1516 0 59 unless defined $body
1524 0 36 unless $body
1542 1 58 unless defined $out
1543 0 59 unless ref $out
1544 0 59 unless $self->_load_class("HTTP::Promise::IO")
1545 23 36 $self->_is_a($out, 'HTTP::Promise::IO') ? :
1548 0 59 unless defined $io
1551 0 59 unless $self->print_start_line($io, $opts)
1553 0 59 unless $self->print_header($io, $opts)
1554 0 59 unless $io->print($eol)
1557 59 0 scalar keys %$opts ? :
0 59 unless $self->print_body($io, scalar keys %$opts ? $opts : ())
1566 0 59 unless $self->_is_glob($out) or $self->_is_a($out, "HTTP::Promise::IO")
1570 60 0 if defined $mime_type
1575 9 51 if (defined $toptype and $toptype eq 'multipart') { }
2 49 elsif (not $self->parts->is_empty) { }
1581 9 0 if (defined $plines)
1585 0 9 if @$plines > 0
1592 0 25 unless $out->print("--$boundary$crlf")
1594 0 25 unless $part->print($out)
1597 0 25 unless $out->print($crlf)
1600 0 9 unless $out->print("--$boundary--$crlf")
1605 0 9 if (defined $epilogue and not $epilogue->is_empty)
1607 0 0 unless $out->print($epilogue->join($crlf)->scalar)
1609 0 0 unless ($epilogue =~ /(?:\015?\012)\Z/)
1611 0 0 unless $out->print($crlf)
1627 0 2 if ($need_sep++)
1629 0 0 unless $out->print("$crlf$crlf")
1632 0 2 unless $part->print($out)
1639 36 13 if ($self->body)
1641 36 0 scalar keys %$opts ? :
0 36 unless $self->print_bodyhandle($out, scalar keys %$opts ? $opts : ())
1654 0 36 unless $self->_is_glob($out) or $self->_is_a($out, "HTTP::Promise::IO")
1657 6 0 if ($encoding and not $self->is_encoded and !exists $opts->{'no_encode'} || exists $opts->{'no_encode'} && !$opts->{'no_encode'})
1663 0 6 unless $self->encode_body($encoding)
1667 0 0 if exists $opts->{'binmode'} and $opts->{'binmode'}
1673 0 62 unless $out->print($buff)
1689 0 59 unless $self->_is_glob($out) or $self->_is_a($out, "HTTP::Promise::IO")
1692 40 19 if (my $msg = $self->http_message)
1695 33 7 unless length $sl
1705 0 0 if $self->body
1716 0 0 if lc substr($type, 0, 10) eq "multipart/"
1717 0 0 unless (defined $fname and length "$fname")
1720 0 0 if (my $val = $headers->content_disposition)
1723 0 0 unless defined $cd
1724 0 0 if (my $orig_name = $cd->filename)
1728 0 0 defined $ext && length $ext ? :
1735 0 0 unless ($ext)
1739 0 0 unless $self->_load_class("HTTP::Promise::MIME")
1742 0 0 unless defined $ext
1745 0 0 unless $self->_load_class("Module::Generic::File")
1751 0 0 unless (defined $fname and length $fname)
1755 0 0 unless $self->_load_class("HTTP::Promise::MIME")
1758 0 0 unless defined $ext
1763 0 0 if (my $enc = $self->headers->content_encoding)
1765 0 0 if $self->is_encoded
1767 0 0 $self->_is_a($fname, 'Module::Generic::File') ? :
1771 0 0 unless $self->print_body($io, "no_encode", 1)
1787 3 0 if defined $mime_type
1831 3 0 if (exists $rule->{$mime_type}) { }
0 0 elsif ($toptype eq 'image' or $toptype eq 'video' or $toptype eq 'audio' or $toptype eq 'multipart') { }
0 0 elsif ($toptype eq 'text' or $self->is_binary) { }
1833 1 2 if $rule->{$mime_type} eq "none"
1834 0 2 if not $threshold or $self->body->length >= $threshold
1846 0 0 if not $threshold or $self->body->length >= $threshold
1854 0 0 $_[0] =~ m[^(text|message)(/|\Z)]i ? :
1865 9 0 if defined $mime_type
1871 0 9 unless ($boundary)
1888 7 18 if ($mime_type eq 'multipart/form-data') { }
18 0 elsif ($mime_type eq 'multipart/mixed') { }
1891 3 4 unless ($name)
1893 3 0 if warnings::enabled()
1904 7 18 if (defined $name)
1907 4 3 if (defined $content_disposition and $content_disposition->length) { }
1910 0 4 if ($content_disposition->index("name=") == -1 or $content_disposition->index("form-data") == -1)
1914 0 0 unless length $cd->name
1940 0 4 unless $serialiser ne "CBOR"
1942 0 4 if $serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")