| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 2 | ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Body/Form/Data.pm | ||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.2.1 | ||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||
| 6 | ## Created 2022/06/13 | ||||||||||||||||||||||||||||||||||
| 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::Body::Form::Data; | ||||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 3 | warnings::register_categories( 'HTTP::Promise' ); | |||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use parent qw( HTTP::Promise::Body::Form ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use vars qw( $VERSION $CRLF $DEBUG ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Crypt::Misc (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 23 | 3 | our $CRLF = "\015\012"; | |||||||||||||||||||||||||||||||||
| 24 | 3 | our $VERSION = 'v0.2.1'; | |||||||||||||||||||||||||||||||||
| 25 | 3 | our $DEBUG = 0; # REMOVE ME | |||||||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | sub init | ||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 34 | 0 | $self->{order} = []; | |||||||||||||||||||||||||||||||||
| 35 | 0 | $self->{debug} = $DEBUG; | |||||||||||||||||||||||||||||||||
| 36 | 0 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | sub as_string | ||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=8 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 43 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 44 | 1 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | my $boundary = $opts->{boundary} || $self->boundary || Crypt::Misc::random_v4uuid(); | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$opts->{'boundary'} || $self->boundary || &Crypt::Misc::random_v4uuid()
$opts->{"boundary"} or $self->boundary
MC/DC0%0/3
$opts->{'boundary'} || $self->boundary || &Crypt::Misc::random_v4uuid()
$opts->{"boundary"}
$self->boundary
&Crypt::Misc::random_v4uuid()
Truth table25%1/4
A or B || C
A= $opts->{"boundary"}B= $self->boundaryC= &Crypt::Misc::random_v4uuid()
| |||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | my $eol = $opts->{eol} || $CRLF; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{'eol'} || $HTTP::Promise::Body::Form::Data::CRLF
MC/DC0%0/2
$opts->{'eol'} || $HTTP::Promise::Body::Form::Data::CRLF
$opts->{'eol'}
$HTTP::Promise::Body::Form::Data::CRLF
Truth table33%1/3
A || B
A= $opts->{'eol'}B= $HTTP::Promise::Body::Form::Data::CRLF
| |||||||||||||||||||||||||||||||||||
| 47 | 1 | my $parts = $self->make_parts( $opts ); | |||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | return( $self->pass_error ) if( !defined( $parts ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 49 | 1 | my $res = $self->new_scalar; | |||||||||||||||||||||||||||||||||
| 50 | 1 | for( @$parts ) | |||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||
| 52 | 4 | my $part = $_->as_string( $eol ) . $eol; | |||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | return( $self->pass_error( $_->error ) ) if( !defined( $part ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 54 | 4 | $$res .= "--${boundary}" . $eol . $part; | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | $res .= "--${boundary}--${eol}" if( $res->length ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 57 | 1 | return( $res ); | |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | sub as_urlencoded | ||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_urlencoded: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 62 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 63 | 0 | my $hash = {}; | |||||||||||||||||||||||||||||||||
| 64 | 0 | my $keys = $self->keys->sort; | |||||||||||||||||||||||||||||||||
| 65 | my $process = sub | ||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 67 | 0 | my( $n, $v ) = @_; | |||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if( $self->_is_a( $v => 'HTTP::Promise::Body::Form::Field' ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||
| 70 | 0 | my $this = $v; | |||||||||||||||||||||||||||||||||
| 71 | 0 | $v = $this->as_string( binmode => 'utf-8' ); | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return( $self->pass_error( $this->error ) ) if( !defined( $v ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if( exists( $hash->{ $n } ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $hash->{ $n } = [$hash->{ $n }] if( ref( $hash->{ $n } ) ne 'ARRAY' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | 0 | push( @{$hash->{ $n }}, $v ); | |||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||
| 79 | else | ||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||
| 81 | 0 | $hash->{ $n } = $v; | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | 0 | return(1); | |||||||||||||||||||||||||||||||||
| 84 | 0 | }; | |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 0 | foreach my $n ( @$keys ) | |||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||||
| 88 | 0 | my $v = $self->{ $n }; | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if( $self->_is_array( $v ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||
| 91 | 0 | foreach my $v2 ( @$v ) | |||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $process->( $n, $v2 ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | else | ||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $process->( $n, $v ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $self->_load_class( 'HTTP::Promise::Body::Form' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $form = HTTP::Promise::Body::Form->new( $hash ) || | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
'HTTP::Promise::Body::Form'->new($hash) || (return $self->pass_error('HTTP::Promise::Body::Form'->error))
MC/DC0%0/1
'HTTP::Promise::Body::Form'->new($hash) || (return $self->pass_error('HTTP::Promise::Body::Form'->error))
'HTTP::Promise::Body::Form'->new($hash)
Truth table0%0/2
A
A= 'HTTP::Promise::Body::Form'->new($hash)
| |||||||||||||||||||||||||||||||||||
| 103 | return( $self->pass_error( HTTP::Promise::Body::Form->error ) ); | ||||||||||||||||||||||||||||||||||
| 104 | 0 | return( $form ); | |||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub boundary { return( shift->_internal( 'boundary', '_set_get_scalar', @_ ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
boundary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | # in HTTP::Promise::Body::Form::Data | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | sub length | ||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
length: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 113 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 114 | 0 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | my $eol = $opts->{eol} || $CRLF; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{'eol'} || $HTTP::Promise::Body::Form::Data::CRLF
MC/DC0%0/2
$opts->{'eol'} || $HTTP::Promise::Body::Form::Data::CRLF
$opts->{'eol'}
$HTTP::Promise::Body::Form::Data::CRLF
Truth table0%0/3
A || B
A= $opts->{'eol'}B= $HTTP::Promise::Body::Form::Data::CRLF
| |||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $boundary = $opts->{boundary} || $self->boundary || Crypt::Misc::random_v4uuid(); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$opts->{'boundary'} || $self->boundary || &Crypt::Misc::random_v4uuid()
$opts->{"boundary"} or $self->boundary
MC/DC0%0/3
$opts->{'boundary'} || $self->boundary || &Crypt::Misc::random_v4uuid()
$opts->{"boundary"}
$self->boundary
&Crypt::Misc::random_v4uuid()
Truth table0%0/4
A or B || C
A= $opts->{"boundary"}B= $self->boundaryC= &Crypt::Misc::random_v4uuid()
| |||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 0 | my $total = 0; | |||||||||||||||||||||||||||||||||
| 119 | 0 | my $sep = '--' . $boundary . $eol; | |||||||||||||||||||||||||||||||||
| 120 | 0 | my $end = '--' . $boundary . '--' . $eol; | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 0 | require bytes; | |||||||||||||||||||||||||||||||||
| 123 | 0 | my $parts = $self->make_parts( $opts ); | |||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return( $self->pass_error ) if( !defined( $parts ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | 0 | foreach my $ent ( @$parts ) | |||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||
| 128 | # leading boundary | ||||||||||||||||||||||||||||||||||
| 129 | 0 | $total += CORE::length( $sep ); | |||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | # body bytes + trailing CRLF | ||||||||||||||||||||||||||||||||||
| 132 | 0 | my $part = $ent->as_string( $eol ); | |||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | return( $self->pass_error( $_->error ) ) if( !defined( $part ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | # my $blen = bytes::length( $part ); | ||||||||||||||||||||||||||||||||||
| 135 | # Ensure text parts are ASCII, use bytes::length for binary | ||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $blen = ( ref( $ent ) && $ent->is_binary ) ? bytes::length( $part ) : CORE::length( $part ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $ent and $ent->is_binary
MC/DC0%0/2
ref $ent and $ent->is_binary
ref $ent
$ent->is_binary
Truth table0%0/3
A and B
A= ref $entB= $ent->is_binary
| |||||||||||||||||||||||||||||||||||
| 137 | 0 | $total += $blen; | |||||||||||||||||||||||||||||||||
| 138 | 0 | $total += CORE::length( $eol ); | |||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | # closing boundary | ||||||||||||||||||||||||||||||||||
| 142 | 0 | $total += CORE::length( $end ); | |||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | 0 | return( $total ); | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | sub make_parts | ||||||||||||||||||||||||||||||||||
| 148 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
make_parts: called CC=15 SCAR=29.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 149 | 4 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 150 | 4 | my $tie_obj = $self->_tie_object; | |||||||||||||||||||||||||||||||||
| 151 | 4 | my $tie_flag = $tie_obj->enable; | |||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | $tie_obj->enable(1) if( !$tie_flag ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 153 | 4 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||
| 154 | 4 | my $order = $self->order; | |||||||||||||||||||||||||||||||||
| 155 | my $keys = $self->_is_array( $opts->{fields} ) | ||||||||||||||||||||||||||||||||||
| 156 | ? $self->new_array( $opts->{fields} ) | ||||||||||||||||||||||||||||||||||
| 157 | 4 | ▶ | : ( defined( $order ) && scalar( @$order ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
defined $order and scalar @$order
MC/DC0%0/1
defined $order and scalar @$order
defined $order
Truth table50%1/2
A
A= defined $order
| |||||||||||||||||||||||||||||||||||
| 158 | ? $order | ||||||||||||||||||||||||||||||||||
| 159 | : $self->keys->sort; | ||||||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | $self->_load_class( 'HTTP::Promise::Entity' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 161 | 4 | ▶ | $self->_load_class( 'HTTP::Promise::Headers' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | 4 | my $parts = $self->new_array; | |||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | my $process = sub | ||||||||||||||||||||||||||||||||||
| 165 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=20 SCAR=31.2
| |||||||||||||||||||||||||||||||||||
| 166 | 7 | my( $n, $v ) = @_; | |||||||||||||||||||||||||||||||||
| 167 | 7 | my( $headers, $body ); | |||||||||||||||||||||||||||||||||
| 168 | 7 | ▶ | if( $self->_is_a( $v => 'HTTP::Promise::Body::Form::Field' ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||||||||
| 170 | 4 | ▶ | $headers = $v->headers || HTTP::Promise::Headers->new; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$v->headers || 'HTTP::Promise::Headers'->new
MC/DC0%0/2
$v->headers || 'HTTP::Promise::Headers'->new
$v->headers
'HTTP::Promise::Headers'->new
Truth table33%1/3
A || B
A= $v->headersB= 'HTTP::Promise::Headers'->new
| |||||||||||||||||||||||||||||||||||
| 171 | 4 | $body = $v->body; | |||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||
| 173 | else | ||||||||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||||||||
| 175 | 3 | $headers = HTTP::Promise::Headers->new; | |||||||||||||||||||||||||||||||||
| 176 | # $body = HTTP::Promise::Entity->new_body( string => $v ) || | ||||||||||||||||||||||||||||||||||
| 177 | # return( $self->pass_error( HTTP::Promise::Entity->error ) ); | ||||||||||||||||||||||||||||||||||
| 178 | 3 | ▶ | if( $self->_is_a( $v => 'Module::Generic::File' ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||
| 180 | 3 | $body = HTTP::Promise::Entity->new_body( file => $v ); | |||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||
| 182 | else | ||||||||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||||||||
| 184 | 0 | $body = HTTP::Promise::Entity->new_body( string => $v ); | |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | 3 | ▶ | if( !defined( $body ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||
| 188 | 0 | return( $self->pass_error( HTTP::Promise::Entity->error ) ); | |||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||
| 191 | 7 | my $dispo = $headers->content_disposition; | |||||||||||||||||||||||||||||||||
| 192 | 7 | ▶ | my $cd = $dispo | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 193 | ? $headers->new_field( 'Content-Disposition' => $dispo ) | ||||||||||||||||||||||||||||||||||
| 194 | : $headers->new_field( 'Content-Disposition' ); | ||||||||||||||||||||||||||||||||||
| 195 | 7 | ▶ | return( $self->pass_error( $headers->error ) ) if( !defined( $cd ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 196 | 7 | $cd->disposition( 'form-data' ); | |||||||||||||||||||||||||||||||||
| 197 | 7 | $cd->name( $n ); | |||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||
| 199 | 7 | ▶ | if( $self->_is_a( $body => 'HTTP::Promise::Body::File' ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | if( !$cd->filename ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 202 | { | ||||||||||||||||||||||||||||||||||
| 203 | 3 | my $basename = $body->basename; | |||||||||||||||||||||||||||||||||
| 204 | 3 | $cd->filename( $basename ); | |||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||
| 206 | # Set Content-Type per part when we can | ||||||||||||||||||||||||||||||||||
| 207 | 3 | ▶ | my $raw_mime = $body->finfo->mime_type || 'application/octet-stream'; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$body->finfo->mime_type || 'application/octet-stream'
MC/DC0%0/1
$body->finfo->mime_type || 'application/octet-stream'
$body->finfo->mime_type
Truth table50%1/2
A
A= $body->finfo->mime_type
| |||||||||||||||||||||||||||||||||||
| 208 | 3 | ▶ | my $filename = $body->basename // ''; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$body->basename // ""
MC/DC0%0/1
$body->basename // ""
$body->basename
Truth table50%1/2
A
A= $body->basename
| |||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | 3 | ▶ | $self->_load_class( 'HTTP::Promise::Stream' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 211 | 3 | ▶ | my $stream = HTTP::Promise::Stream->new( \'' ) || return( $self->pass_error( HTTP::Promise::Stream->error ) ); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
'HTTP::Promise::Stream'->new(\'') || (return $self->pass_error('HTTP::Promise::Stream'->error))
MC/DC0%0/1
'HTTP::Promise::Stream'->new(\'') || (return $self->pass_error('HTTP::Promise::Stream'->error))
'HTTP::Promise::Stream'->new(\'')
Truth table50%1/2
A
A= 'HTTP::Promise::Stream'->new(\'')
| |||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | # Determine encoding layers from file extensions (handles multiple encodings) | ||||||||||||||||||||||||||||||||||
| 214 | 3 | my $encodings = $stream->suffix2encoding( $filename ); | |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | 3 | my $ctype; | |||||||||||||||||||||||||||||||||
| 217 | 3 | ▶ | if( $encodings->length ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||||||||
| 219 | 3 | my $enc_suffix = $stream->_encoding2suffix_map; | |||||||||||||||||||||||||||||||||
| 220 | 3 | my %enc_suffixes = map{ $enc_suffix->{ $_ } => 1 } | |||||||||||||||||||||||||||||||||
| 221 | 3 | grep{ exists( $enc_suffix->{ $_ } ) } @$encodings; | |||||||||||||||||||||||||||||||||
| 222 | # Strip the encoding suffixes to find the inner format. | ||||||||||||||||||||||||||||||||||
| 223 | # reverse + pop removes the basename, leaving extensions outermost-first. | ||||||||||||||||||||||||||||||||||
| 224 | 3 | my @parts = reverse( split( /\./, $filename ) ); | |||||||||||||||||||||||||||||||||
| 225 | 3 | pop( @parts ); | |||||||||||||||||||||||||||||||||
| 226 | # Skip the encoding suffixes to reach the inner format extension | ||||||||||||||||||||||||||||||||||
| 227 | 3 | ▶ | while( @parts && exists( $enc_suffixes{ $parts[0] } ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@parts and exists $enc_suffixes{$parts[0]}
MC/DC100%2/2
@parts and exists $enc_suffixes{$parts[0]}
@parts
exists $enc_suffixes{$parts[0]}
Truth table100%3/3
A and B
A= @partsB= exists $enc_suffixes{$parts[0]}
| |||||||||||||||||||||||||||||||||||
| 228 | { | ||||||||||||||||||||||||||||||||||
| 229 | 3 | shift( @parts ); | |||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||
| 231 | 3 | ▶ | my $inner_ext = @parts ? lc( $parts[0] ) : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 232 | 3 | ▶ | $ctype = ( $inner_ext eq 'tar' ) ? 'application/x-tar' : "$raw_mime"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 233 | 3 | $headers->header( 'Content-Encoding' => join( ', ', @$encodings ) ); | |||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||
| 235 | else | ||||||||||||||||||||||||||||||||||
| 236 | { | ||||||||||||||||||||||||||||||||||
| 237 | 0 | $ctype = "$raw_mime"; | |||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | 3 | ▶ | my $ctfld = $headers->new_field( 'Content-Type' ) || return( $self->pass_error( $headers->error ) ); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$headers->new_field('Content-Type') || (return $self->pass_error($headers->error))
MC/DC0%0/1
$headers->new_field('Content-Type') || (return $self->pass_error($headers->error))
$headers->new_field('Content-Type')
Truth table50%1/2
A
A= $headers->new_field('Content-Type')
| |||||||||||||||||||||||||||||||||||
| 241 | 3 | $ctfld->type( $ctype ); | |||||||||||||||||||||||||||||||||
| 242 | 3 | $headers->content_type( "$ctfld" ); | |||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||
| 244 | 7 | $headers->content_disposition( "$cd" ); | |||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | 7 | ▶ | my $ent = HTTP::Promise::Entity->new( headers => $headers, body => $body ) || | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
'HTTP::Promise::Entity'->new('headers', $headers, 'body', $body) || (return $self->pass_error('HTTP::Promise::Entity'->error))
MC/DC0%0/1
'HTTP::Promise::Entity'->new('headers', $headers, 'body', $body) || (return $self->pass_error('HTTP::Promise::Entity'->error))
'HTTP::Promise::Entity'->new('headers', $headers, 'body', $body)
Truth table50%1/2
A
A= 'HTTP::Promise::Entity'->new('headers', $headers, 'body', $body)
| |||||||||||||||||||||||||||||||||||
| 247 | return( $self->pass_error( HTTP::Promise::Entity->error ) ); | ||||||||||||||||||||||||||||||||||
| 248 | 7 | $ent->name( $n ); | |||||||||||||||||||||||||||||||||
| 249 | 7 | return( $ent ); | |||||||||||||||||||||||||||||||||
| 250 | 4 | }; | |||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | 4 | foreach my $n ( @$keys ) | |||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||||
| 254 | 7 | my $v = $self->{ $n }; | |||||||||||||||||||||||||||||||||
| 255 | 7 | ▶ | if( ref( $v ) eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||||||||
| 257 | 0 | foreach my $v2 ( @$v ) | |||||||||||||||||||||||||||||||||
| 258 | { | ||||||||||||||||||||||||||||||||||
| 259 | 0 | my $ent = $process->( $n, $v2 ); | |||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if( !defined( $ent ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 261 | { | ||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | $tie_obj->enable(0) if( !$tie_flag ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 263 | 0 | return( $self->pass_error ); | |||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||
| 265 | 0 | $ent->name( $n ); | |||||||||||||||||||||||||||||||||
| 266 | 0 | $parts->push( $ent ); | |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||
| 269 | else | ||||||||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||||||||
| 271 | 7 | my $ent = $process->( $n, $v ); | |||||||||||||||||||||||||||||||||
| 272 | 7 | ▶ | if( !defined( $ent ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | $tie_obj->enable(0) if( !$tie_flag ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 275 | 0 | return( $self->pass_error ); | |||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||
| 277 | 7 | $ent->name( $n ); | |||||||||||||||||||||||||||||||||
| 278 | 7 | $parts->push( $ent ); | |||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||
| 281 | 4 | ▶ | $tie_obj->enable(0) if( !$tie_flag ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 282 | 4 | return( $parts ); | |||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | sub new_field | ||||||||||||||||||||||||||||||||||
| 286 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
new_field: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 287 | 4 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 288 | 4 | ▶ | $self->_load_class( 'HTTP::Promise::Body::Form::Field' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 289 | 4 | ▶ | my $f = HTTP::Promise::Body::Form::Field->new( @_ ) || | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
'HTTP::Promise::Body::Form::Field'->new(@_) || (return $self->pass_error('HTTP::Promise::Body::Form::Field'->error))
MC/DC0%0/1
'HTTP::Promise::Body::Form::Field'->new(@_) || (return $self->pass_error('HTTP::Promise::Body::Form::Field'->error))
'HTTP::Promise::Body::Form::Field'->new(@_)
Truth table50%1/2
A
A= 'HTTP::Promise::Body::Form::Field'->new(@_)
| |||||||||||||||||||||||||||||||||||
| 290 | return( $self->pass_error( HTTP::Promise::Body::Form::Field->error ) ); | ||||||||||||||||||||||||||||||||||
| 291 | 4 | return( $f ); | |||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||
| 294 | sub open | ||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
open: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 296 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 297 | 0 | my $s = $self->as_string; | |||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | return( $self->pass_error ) if( !defined( $s ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | my $io = $s->open( @_ ) || | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$s->open(@_) || (return $self->pass_error($s->error))
MC/DC0%0/1
$s->open(@_) || (return $self->pass_error($s->error))
$s->open(@_)
Truth table0%0/2
A
A= $s->open(@_)
| |||||||||||||||||||||||||||||||||||
| 300 | return( $self->pass_error( $s->error ) ); | ||||||||||||||||||||||||||||||||||
| 301 | 0 | return( $io ); | |||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||
| 304 | # sub order { return( shift->_set_get_array_as_object( 'order', @_ ) ); } | ||||||||||||||||||||||||||||||||||
| 305 | 4 | ▶ | sub order { return( shift->_internal( 'order', '_set_get_array_as_object', @_ ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 306 | # sub order | ||||||||||||||||||||||||||||||||||
| 307 | # { | ||||||||||||||||||||||||||||||||||
| 308 | # my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||
| 309 | # $self->_tie_object->enable(0); | ||||||||||||||||||||||||||||||||||
| 310 | # my $rv = $self->SUPER::_set_get_array_as_object( 'order', @_ ); | ||||||||||||||||||||||||||||||||||
| 311 | # $self->_tie_object->enable(1); | ||||||||||||||||||||||||||||||||||
| 312 | # return( $rv ); | ||||||||||||||||||||||||||||||||||
| 313 | # } | ||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | sub print | ||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
print: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 317 | 0 | my( $self, $fh ) = @_; | |||||||||||||||||||||||||||||||||
| 318 | 0 | my $nread; | |||||||||||||||||||||||||||||||||
| 319 | # Get output filehandle, and ensure that it's a printable object: | ||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | $fh ||= select; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$fh ||= select
MC/DC0%0/2
$fh ||= select
$fh
select
Truth table0%0/3
A ||= B
A= $fhB= select
| |||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | return( $self->error( "Filehandle provided ($fh) is not a valid filehandle." ) ) if( !$self->_is_glob( $fh ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 322 | 0 | my $encoded = $self->as_string; | |||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | return( $self->pass_error ) if( !defined( $encoded ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | CORE::print( $fh $$encoded ) || return( $self->error( "Unable to print on given filehandle '$fh': $!" ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 325 | 0 | return(1); | |||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||
| 328 | 1 | ▶ | sub size { return( shift->Module::Generic::Hash::length ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | sub _is_warnings_enabled { return( warnings::enabled( 'HTTP::Promise' ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
_is_warnings_enabled: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | # NOTE: FREEZE is inherited | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | # NOTE: STORABLE_freeze is inherited | ||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||
| 336 | # NOTE: STORABLE_thaw is inherited | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | # NOTE: THAW is inherited | ||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||
| 340 | 3 | 1; | |||||||||||||||||||||||||||||||||
| 341 | # NOTE: POD | ||||||||||||||||||||||||||||||||||
| 342 | __END__ | ||||||||||||||||||||||||||||||||||