| 1 | package Zuzu::Module::HTTP; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | our $VERSION = '0.007002'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use HTTP::Tiny (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use File::Temp qw( tempfile ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use MIME::Base64 qw( encode_base64 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use URI::Escape qw( uri_escape ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Zuzu::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Zuzu::Util::NativeHelpers qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | native_class | ||||||||||||||||||||||||||||||||||||||||||
| 17 | native_function | ||||||||||||||||||||||||||||||||||||||||||
| 18 | native_object | ||||||||||||||||||||||||||||||||||||||||||
| 19 | perl_to_zuzu | ||||||||||||||||||||||||||||||||||||||||||
| 20 | zuzu_bool | ||||||||||||||||||||||||||||||||||||||||||
| 21 | zuzu_to_perl | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | my $HAS_HTTP_COOKIEJAR = eval { | |||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | require HTTP::CookieJar; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | package Zuzu::Module::HTTP::SimpleCookieJar; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my ( $class ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return bless { | |||||||||||||||||||||||||||||||||||||||||
| 35 | cookies => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ( $self, $url, $set_cookie ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $key = defined $url ? "$url" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $self->{cookies}{$key} = defined $set_cookie ? "$set_cookie" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub cookie_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cookie_header: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ( $self, $url ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $key = defined $url ? "$url" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return $self->{cookies}{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $self->{cookies} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | sub _hash_from { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hash_from: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 15 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 15 | ▶ | return {} if not defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | my $perl = zuzu_to_perl( $value ); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | ▶ | return {} if ref($perl) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | return $perl; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 11 | ▶ | sub _extract_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_config: called CC=5 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 11 | my ( $positional, $named ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | ▶ | my %config = %{ $named // {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$named // {}
MC/DC0%0/1
$named // {}
$named
Truth table50%1/2
A
A= $named
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | ▶ | if ( @{ $positional // [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$positional // []
MC/DC0%0/1
$positional // []
$positional
Truth table50%1/2
A
A= $positional
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $first = _hash_from( $positional->[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | for my $key ( CORE::keys %{ $first } ) { | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $config{$key} = $first->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | return \%config; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | sub _merge_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_query: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | my ( $url, $query ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | return $url if ref($query) ne 'HASH' or not CORE::keys %{ $query }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $query ne "HASH" or not keys %{$query;}
MC/DC50%1/2
ref $query ne "HASH" or not keys %{$query;}
ref $query ne "HASH"
not keys %{$query;}
Truth table66%2/3
A or not(B)
A= ref $query ne "HASH"B= not keys %{$query;}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my @pairs; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | for my $key ( sort CORE::keys %{ $query } ) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | my $value = defined $query->{$key} ? "$query->{$key}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | push @pairs, uri_escape($key) . '=' . uri_escape($value); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | my $qs = join '&', @pairs; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | return $url . ( $url =~ /\?/ ? '&' : '?' ) . $qs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub _build_multipart { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_multipart: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ( $fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return ( undef, '' ) if ref($fields) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $boundary = 'zuzu-' . int(rand(1000000)) . '-' . time; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my @chunks; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | for my $name ( sort CORE::keys %{ $fields } ) { | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $value = defined $fields->{$name} ? "$fields->{$name}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | push @chunks, | |||||||||||||||||||||||||||||||||||||||||
| 104 | "--$boundary\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 105 | . qq(Content-Disposition: form-data; name="$name"\r\n\r\n) | ||||||||||||||||||||||||||||||||||||||||||
| 106 | . $value | ||||||||||||||||||||||||||||||||||||||||||
| 107 | . "\r\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | push @chunks, "--$boundary--\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return ( "multipart/form-data; boundary=$boundary", join '', @chunks ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | sub _build_request_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_request_options: called CC=21 SCAR=50.2
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | my ( $spec, $tls_config, $client_config ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | my %opts; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | if ( exists $spec->{headers} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | $opts{headers} = _hash_from( $spec->{headers} ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | $opts{headers} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"headers"} //= {}
MC/DC0%0/1
$opts{"headers"} //= {}
$opts{"headers"}
Truth table50%1/2
A
A= $opts{"headers"}
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | if ( exists $spec->{timeout} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $timeout = 0 + $spec->{timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $opts{timeout} = $timeout if $timeout > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $client_config->{timeout} = $timeout | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $client_config and $timeout > 0
MC/DC0%0/2
defined $client_config and $timeout > 0
defined $client_config
$timeout > 0
Truth table0%0/3
A and B
A= defined $client_configB= $timeout > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | if defined $client_config and $timeout > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | if ( exists $spec->{body} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | $opts{content} = defined $spec->{body} ? "$spec->{body}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | if ( exists $spec->{json} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $opts{content} = JSON::PP::encode_json( zuzu_to_perl( $spec->{json} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | $opts{headers}{'content-type'} //= 'application/json'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"headers"}{"content-type"} //= "application/json"
MC/DC0%0/1
$opts{"headers"}{"content-type"} //= "application/json"
$opts{"headers"}{"content-type"}
Truth table0%0/2
A
A= $opts{"headers"}{"content-type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | if ( exists $spec->{upload_from} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | my $file = defined $spec->{upload_from} ? "$spec->{upload_from}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | open my $fh, '<', $file or die "HTTP request upload_from open failed for '$file': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $opts{content} = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | if ( exists $spec->{multipart} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my ( $content_type, $body ) = _build_multipart( _hash_from( $spec->{multipart} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $opts{content} = $body; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $opts{headers}{'content-type'} = $content_type if defined $content_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | if ( exists $spec->{download_to} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $file = defined $spec->{download_to} ? "$spec->{download_to}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | open my $fh, '>', $file or die "HTTP request download_to open failed for '$file': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $opts{data_callback} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my ( $chunk, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | print {$fh} $chunk; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $opts{_download_handle} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | _apply_tls_options( $client_config, $tls_config // {} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$tls_config // {}
MC/DC0%0/1
$tls_config // {}
$tls_config
Truth table50%1/2
A
A= $tls_config
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | if defined $client_config; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | return \%opts; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub _is_native_object { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_native_object: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my ( $value, $class ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | return blessed($value) | |||||||||||||||||||||||||||||||||||||||||
| 170 | and $value->isa( 'Zuzu::Value::Object' ) | ||||||||||||||||||||||||||||||||||||||||||
| 171 | and $value->can('class') | ||||||||||||||||||||||||||||||||||||||||||
| 172 | and $value->class->name eq $class; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub _write_tls_tempfile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_tls_tempfile: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my ( $label, $content, $keepers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my ( $fh, $path ) = tempfile( 'zuzu-http-tls-XXXXXX', TMPDIR => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | print {$fh} $content; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | push @{ $keepers }, $path; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return $path; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub _certificate_pem_from_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_certificate_pem_from_value: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my ( $value, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ( not defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ( not ref($value) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $pem = "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | die "$label expects PEM certificate text" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | if $pem !~ /-----BEGIN CERTIFICATE-----/; | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return $pem; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ( _is_native_object( $value, 'Certificate' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $der = $value->slots->{_der}; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $encoded = encode_base64( $der, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $encoded =~ s/(.{1,64})/$1\n/g; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | return "-----BEGIN CERTIFICATE-----\n" | |||||||||||||||||||||||||||||||||||||||||
| 203 | . $encoded | ||||||||||||||||||||||||||||||||||||||||||
| 204 | . "-----END CERTIFICATE-----\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | die "TypeException: $label expects Certificate, String PEM, or Array"; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub _ca_pem_from_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ca_pem_from_value: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my ( $value, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | return '' if not defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $perl = zuzu_to_perl($value); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ( ref($perl) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return join '', map { _certificate_pem_from_value( $_, $label ) } @{ $perl }; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return _certificate_pem_from_value( $value, $label ); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub _tls_identity_state { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tls_identity_state: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my ( $value, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | return undef if not defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | die "TypeException: $label expects TlsIdentity or null" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | if not _is_native_object( $value, 'TlsIdentity' ); | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | return $value->slots; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | sub _tls_min_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tls_min_version: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my ( $value, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | return undef if not defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $text = lc "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | return 'TLSv12:!SSLv2:!SSLv3:!TLSv1:!TLSv11' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | if $text eq 'tls1.2'; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | return 'TLSv13' if $text eq 'tls1.3'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | die "$label tls_min_version must be 'tls1.2' or 'tls1.3'"; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | sub _apply_tls_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_tls_options: called CC=20 SCAR=47.9
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | my ( $client_config, $tls ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | my %ssl; | |||||||||||||||||||||||||||||||||||||||||
| 244 | my @keepers; | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | my $label = 'std/net/http TLS configuration'; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | if ( exists $tls->{tls_identity} and defined $tls->{tls_identity} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $tls->{"tls_identity"} and defined $tls->{"tls_identity"}
MC/DC0%0/2
exists $tls->{"tls_identity"} and defined $tls->{"tls_identity"}
exists $tls->{"tls_identity"}
defined $tls->{"tls_identity"}
Truth table33%1/3
A and B
A= exists $tls->{"tls_identity"}B= defined $tls->{"tls_identity"}
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $identity = _tls_identity_state( $tls->{tls_identity}, $label ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | $ssl{SSL_cert_file} = _write_tls_tempfile( | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 'certificate', | ||||||||||||||||||||||||||||||||||||||||||
| 251 | $identity->{_chain_pem} // $identity->{_cert_pem}, | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | \@keepers, | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$identity->{"_chain_pem"} // $identity->{"_cert_pem"}
MC/DC0%0/2
$identity->{"_chain_pem"} // $identity->{"_cert_pem"}
$identity->{"_chain_pem"}
$identity->{"_cert_pem"}
Truth table0%0/3
A // B
A= $identity->{"_chain_pem"}B= $identity->{"_cert_pem"}
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | $ssl{SSL_key_file} = _write_tls_tempfile( | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 'private key', | ||||||||||||||||||||||||||||||||||||||||||
| 256 | $identity->{_key_pem}, | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | \@keepers, | |||||||||||||||||||||||||||||||||||||||||
| 258 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | ▶ | if ( exists $tls->{tls_ca} and defined $tls->{tls_ca} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $tls->{"tls_ca"} and defined $tls->{"tls_ca"}
MC/DC0%0/2
exists $tls->{"tls_ca"} and defined $tls->{"tls_ca"}
exists $tls->{"tls_ca"}
defined $tls->{"tls_ca"}
Truth table33%1/3
A and B
A= exists $tls->{"tls_ca"}B= defined $tls->{"tls_ca"}
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $pem = _ca_pem_from_value( $tls->{tls_ca}, $label ); | |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $ssl{SSL_ca_file} = _write_tls_tempfile( 'CA', $pem, \@keepers ); | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | if ( exists $tls->{tls_verify} and not zuzu_bool( $tls->{tls_verify}, 1 ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
exists $tls->{"tls_verify"} and not zuzu_bool($tls->{"tls_verify"}, 1)
MC/DC0%0/2
exists $tls->{"tls_verify"} and not zuzu_bool($tls->{"tls_verify"}, 1)
exists $tls->{"tls_verify"}
not zuzu_bool($tls->{"tls_verify"}, 1)
Truth table33%1/3
A and not(B)
A= exists $tls->{"tls_verify"}B= not zuzu_bool($tls->{"tls_verify"}, 1)
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $client_config->{verify_SSL} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ( eval { require IO::Socket::SSL; 1 } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $ssl{SSL_verify_mode} = IO::Socket::SSL::SSL_VERIFY_NONE(); | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | ▶ | elsif ( exists $tls->{tls_ca} and defined $tls->{tls_ca} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
exists $tls->{"tls_ca"} and defined $tls->{"tls_ca"}
MC/DC0%0/2
exists $tls->{"tls_ca"} and defined $tls->{"tls_ca"}
exists $tls->{"tls_ca"}
defined $tls->{"tls_ca"}
Truth table33%1/3
A and B
A= exists $tls->{"tls_ca"}B= defined $tls->{"tls_ca"}
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $client_config->{verify_SSL} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 2 | ▶ | if ( exists $tls->{tls_server_name} and defined $tls->{tls_server_name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $tls->{"tls_server_name"} and defined $tls->{"tls_server_name"}
MC/DC0%0/2
exists $tls->{"tls_server_name"} and defined $tls->{"tls_server_name"}
exists $tls->{"tls_server_name"}
defined $tls->{"tls_server_name"}
Truth table33%1/3
A and B
A= exists $tls->{"tls_server_name"}B= defined $tls->{"tls_server_name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $name = "$tls->{tls_server_name}"; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $ssl{SSL_hostname} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $ssl{SSL_verifycn_name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | ▶ | if ( exists $tls->{tls_min_version} and defined $tls->{tls_min_version} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $tls->{"tls_min_version"} and defined $tls->{"tls_min_version"}
MC/DC0%0/2
exists $tls->{"tls_min_version"} and defined $tls->{"tls_min_version"}
exists $tls->{"tls_min_version"}
defined $tls->{"tls_min_version"}
Truth table33%1/3
A and B
A= exists $tls->{"tls_min_version"}B= defined $tls->{"tls_min_version"}
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $ssl{SSL_version} = _tls_min_version( $tls->{tls_min_version}, $label ); | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | if ( exists $tls->{tls_ciphers} and defined $tls->{tls_ciphers} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $tls->{"tls_ciphers"} and defined $tls->{"tls_ciphers"}
MC/DC0%0/2
exists $tls->{"tls_ciphers"} and defined $tls->{"tls_ciphers"}
exists $tls->{"tls_ciphers"}
defined $tls->{"tls_ciphers"}
Truth table33%1/3
A and B
A= exists $tls->{"tls_ciphers"}B= defined $tls->{"tls_ciphers"}
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $ssl{SSL_cipher_list} = "$tls->{tls_ciphers}"; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | ▶ | if ( CORE::keys %ssl ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | $client_config->{SSL_options} = { | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | %{ $client_config->{SSL_options} // {} }, | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$client_config->{"SSL_options"} // {}
MC/DC0%0/1
$client_config->{"SSL_options"} // {}
$client_config->{"SSL_options"}
Truth table0%0/2
A
A= $client_config->{"SSL_options"}
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | %ssl, | ||||||||||||||||||||||||||||||||||||||||||
| 289 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 2 | ▶ | $client_config->{_tls_tempfiles} = \@keepers if @keepers; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | ▶ | sub _perform_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_perform_request: called CC=8 SCAR=23.9
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | my ( $ua, $method_name, $target, $opts, $retries, $tempfiles ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 2 | my $attempt = 0; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | my $response; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | ▶ | while ( $attempt <= $retries ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | $response = $ua->request( $method_name, $target, $opts ); | |||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | ▶ | last if $response->{success}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | ▶ | last if ( $response->{status} // 0 ) < 500; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$response->{"status"} // 0
MC/DC0%0/1
$response->{"status"} // 0
$response->{"status"}
Truth table50%1/2
A
A= $response->{"status"}
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | $attempt++; | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | ▶ | if ( exists $opts->{_download_handle} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | close $opts->{_download_handle}; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | delete $opts->{_download_handle}; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ( defined $tempfiles and @{$tempfiles} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $tempfiles and @{$tempfiles;}
MC/DC0%0/2
defined $tempfiles and @{$tempfiles;}
defined $tempfiles
@{$tempfiles;}
Truth table33%1/3
A and B
A= defined $tempfilesB= @{$tempfiles;}
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | unlink @{$tempfiles}; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | return $response; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | sub _wrap_cookie_jar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap_cookie_jar: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my ( $cookiejar_class, $jar ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | return native_object( | |||||||||||||||||||||||||||||||||||||||||
| 322 | class => $cookiejar_class, | ||||||||||||||||||||||||||||||||||||||||||
| 323 | slots => { | ||||||||||||||||||||||||||||||||||||||||||
| 324 | _jar => $jar, | ||||||||||||||||||||||||||||||||||||||||||
| 325 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 326 | const => { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | _jar => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 328 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 329 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 8 | ▶ | sub _wrap_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap_response: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 8 | my ( $response_class, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 8 | return native_object( | |||||||||||||||||||||||||||||||||||||||||
| 336 | class => $response_class, | ||||||||||||||||||||||||||||||||||||||||||
| 337 | slots => { | ||||||||||||||||||||||||||||||||||||||||||
| 338 | _response => $response, | ||||||||||||||||||||||||||||||||||||||||||
| 339 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 340 | const => { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | _response => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 342 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 343 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 6 | ▶ | sub _async_task { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_async_task: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 6 | my ( $runtime, $name, $work, $wrap ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 6 | my $worker = $runtime->_new_task( | |||||||||||||||||||||||||||||||||||||||||
| 350 | name => "$name.worker", | ||||||||||||||||||||||||||||||||||||||||||
| 351 | start => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 352 | schedule => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 353 | thunk => $work, | ||||||||||||||||||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 355 | return $runtime->_new_task( | ||||||||||||||||||||||||||||||||||||||||||
| 356 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 357 | schedule => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 6 | ▶ | thunk => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 6 | my $value = $worker->await; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 6 | ▶ | return defined $wrap ? $wrap->($value) : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 2 | ▶ | sub _warn_blocking_operation { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_warn_blocking_operation: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 2 | my ( $runtime, $operation ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | ▶ | $runtime->_warn_blocking_operation($operation) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | if $runtime->can('_warn_blocking_operation'); | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub _cookie_jar_from_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cookie_jar_from_value: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | return undef if not defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
builtin::blessed($value) and $value->isa("Zuzu::Value::Object") and exists $value->slots->{"_jar"}
builtin::blessed($value) and $value->isa("Zuzu::Value::Object")
MC/DC0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Object") and exists $value->slots->{"_jar"}
builtin::blessed($value)
$value->isa("Zuzu::Value::Object")
exists $value->slots->{"_jar"}
Truth table0%0/4
A and B and C
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Object")C= exists $value->slots->{"_jar"}
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | blessed($value) | ||||||||||||||||||||||||||||||||||||||||||
| 380 | and $value->isa( 'Zuzu::Value::Object' ) | ||||||||||||||||||||||||||||||||||||||||||
| 381 | and exists $value->slots->{_jar} | ||||||||||||||||||||||||||||||||||||||||||
| 382 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | return $value->slots->{_jar}; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 14 | ▶ | sub IMPORT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
IMPORT: called CC=3 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 14 | my ( $class, $runtime ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 14 | my $response_class = native_class( | |||||||||||||||||||||||||||||||||||||||||
| 393 | name => 'Response', | ||||||||||||||||||||||||||||||||||||||||||
| 394 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 14 | my $request_class = native_class( | |||||||||||||||||||||||||||||||||||||||||
| 396 | name => 'Request', | ||||||||||||||||||||||||||||||||||||||||||
| 397 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 14 | my $cookiejar_class = native_class( | |||||||||||||||||||||||||||||||||||||||||
| 399 | name => 'CookieJar', | ||||||||||||||||||||||||||||||||||||||||||
| 400 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 14 | my $useragent_class = native_class( | |||||||||||||||||||||||||||||||||||||||||
| 402 | name => 'UserAgent', | ||||||||||||||||||||||||||||||||||||||||||
| 403 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | $cookiejar_class->native_constructor( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my ( $rt, $klass, $positional, $named ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my %config = %{ _extract_config( $positional, $named ) }; | |||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my $jar; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | if ( $HAS_HTTP_COOKIEJAR ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $jar = HTTP::CookieJar->new( %config ); | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $jar = Zuzu::Module::HTTP::SimpleCookieJar->new(); | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | return _wrap_cookie_jar( $klass, $jar ); | |||||||||||||||||||||||||||||||||||||||||
| 418 | 14 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | $cookiejar_class->methods->{add} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 421 | name => 'add', | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | my ( $self, $url, $set_cookie ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $self->slots->{_jar}->add( $url, $set_cookie ); | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 426 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | $cookiejar_class->methods->{cookie_header} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 430 | name => 'cookie_header', | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my ( $self, $url ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | return $self->slots->{_jar}->cookie_header( $url ); | |||||||||||||||||||||||||||||||||||||||||
| 434 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | $cookiejar_class->methods->{clear} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 438 | name => 'clear', | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | if ( $self->slots->{_jar}->can( 'clear' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $self->slots->{_jar}->clear(); | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 445 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | $response_class->methods->{status} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 449 | name => 'status', | ||||||||||||||||||||||||||||||||||||||||||
| 450 | 3 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 3 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 3 | return $self->slots->{_response}{status}; | |||||||||||||||||||||||||||||||||||||||||
| 453 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | $response_class->methods->{reason} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 457 | name => 'reason', | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | return $self->slots->{_response}{reason}; | |||||||||||||||||||||||||||||||||||||||||
| 461 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | $response_class->methods->{url} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 465 | name => 'url', | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | return $self->slots->{_response}{url}; | |||||||||||||||||||||||||||||||||||||||||
| 469 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | $response_class->methods->{content} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 473 | name => 'content', | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 3 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 3 | return $self->slots->{_response}{content}; | |||||||||||||||||||||||||||||||||||||||||
| 477 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | $response_class->methods->{headers} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 481 | name => 'headers', | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | my $headers = $self->slots->{_response}{headers} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->slots->{"_response"}{"headers"} // {}
MC/DC0%0/1
$self->slots->{"_response"}{"headers"} // {}
$self->slots->{"_response"}{"headers"}
Truth table0%0/2
A
A= $self->slots->{"_response"}{"headers"}
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | return perl_to_zuzu( $headers ); | |||||||||||||||||||||||||||||||||||||||||
| 486 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | $response_class->methods->{header} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 490 | name => 'header', | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | my $headers = $self->slots->{_response}{headers} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->slots->{"_response"}{"headers"} // {}
MC/DC0%0/1
$self->slots->{"_response"}{"headers"} // {}
$self->slots->{"_response"}{"headers"}
Truth table0%0/2
A
A= $self->slots->{"_response"}{"headers"}
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | my $key = defined $name ? lc "$name" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | return $headers->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 496 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | $response_class->methods->{success} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 500 | name => 'success', | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 2 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | ▶ | return zuzu_bool( $self->slots->{_response}{success}, 0 ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | $response_class->methods->{to_Dict} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 508 | name => 'to_Dict', | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | return perl_to_zuzu( $self->slots->{_response} ); | |||||||||||||||||||||||||||||||||||||||||
| 512 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | $response_class->methods->{json} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 516 | name => 'json', | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | my $content = $self->slots->{_response}{content}; | |||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | ▶ | return undef if not defined $content or $content eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $content or $content eq ""
MC/DC0%0/2
not defined $content or $content eq ""
not defined $content
$content eq ""
Truth table33%1/3
not(A) or B
A= not defined $contentB= $content eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | return perl_to_zuzu( JSON::PP::decode_json($content) ); | |||||||||||||||||||||||||||||||||||||||||
| 522 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | $response_class->methods->{expect_success} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 526 | name => 'expect_success', | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | my ( $self, $message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 1 | ▶ | return $self if $self->slots->{_response}{success}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | my $status = $self->slots->{_response}{status} // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->slots->{"_response"}{"status"} // 0
MC/DC0%0/1
$self->slots->{"_response"}{"status"} // 0
$self->slots->{"_response"}{"status"}
Truth table0%0/2
A
A= $self->slots->{"_response"}{"status"}
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | my $reason = $self->slots->{_response}{reason} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->slots->{"_response"}{"reason"} // ""
MC/DC0%0/1
$self->slots->{"_response"}{"reason"} // ""
$self->slots->{"_response"}{"reason"}
Truth table0%0/2
A
A= $self->slots->{"_response"}{"reason"}
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | my $text = defined $message ? "$message" : 'HTTP request failed'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | die Zuzu::Error->new_runtime( | |||||||||||||||||||||||||||||||||||||||||
| 534 | message => "$text ($status $reason)", | ||||||||||||||||||||||||||||||||||||||||||
| 535 | file => '<std/net/http>', | ||||||||||||||||||||||||||||||||||||||||||
| 536 | line => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 537 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 538 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | $response_class->methods->{validate_json} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 542 | name => 'validate_json', | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my ( $self, $validator ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my $json = $response_class->methods->{json}{_native}->( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | if ( blessed($validator) and $validator->isa( 'Zuzu::Value::Function' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($validator) and $validator->isa("Zuzu::Value::Function")
MC/DC0%0/2
builtin::blessed($validator) and $validator->isa("Zuzu::Value::Function")
builtin::blessed($validator)
$validator->isa("Zuzu::Value::Function")
Truth table0%0/3
A and B
A= builtin::blessed($validator)B= $validator->isa("Zuzu::Value::Function")
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | return $runtime->_call_function( $validator, [ $json ], '<std/net/http>', 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | return $json; | |||||||||||||||||||||||||||||||||||||||||
| 550 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 5 | ▶ | $request_class->native_constructor( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 5 | my ( $rt, $klass, $positional, $named ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 555 | 5 | my %spec = %{ _extract_config( $positional, $named ) }; | |||||||||||||||||||||||||||||||||||||||||
| 556 | 5 | ▶ | $spec{method} //= 'GET'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$spec{"method"} //= "GET"
MC/DC0%0/1
$spec{"method"} //= "GET"
$spec{"method"}
Truth table50%1/2
A
A= $spec{"method"}
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 5 | $spec{headers} = _hash_from( $spec{headers} ); | |||||||||||||||||||||||||||||||||||||||||
| 558 | 5 | $spec{query} = _hash_from( $spec{query} ); | |||||||||||||||||||||||||||||||||||||||||
| 559 | 5 | return native_object( | |||||||||||||||||||||||||||||||||||||||||
| 560 | class => $klass, | ||||||||||||||||||||||||||||||||||||||||||
| 561 | slots => { | ||||||||||||||||||||||||||||||||||||||||||
| 562 | _spec => \%spec, | ||||||||||||||||||||||||||||||||||||||||||
| 563 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 564 | const => { | ||||||||||||||||||||||||||||||||||||||||||
| 565 | _spec => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 566 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 567 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 568 | 14 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 14 | for my $field ( qw( method url body timeout retries download_to upload_from tls_identity ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 571 | $request_class->methods->{$field} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 572 | name => $field, | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 2 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 2 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | $self->slots->{_spec}{$field} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 576 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 577 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 578 | 112 | ); | |||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | $request_class->methods->{header} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 582 | name => 'header', | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | my ( $self, $name, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | my $key = defined $name ? lc "$name" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | $self->slots->{_spec}{headers}{$key} = defined $value ? "$value" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 588 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | $request_class->methods->{headers} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 592 | name => 'headers', | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my ( $self, $headers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | my $next = _hash_from( $headers ); | |||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | for my $key ( CORE::keys %{ $next } ) { | |||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | $self->slots->{_spec}{headers}{lc $key} = defined $next->{$key} ? "$next->{$key}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 600 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 601 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | $request_class->methods->{query} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 604 | name => 'query', | ||||||||||||||||||||||||||||||||||||||||||
| 605 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 1 | my ( $self, $query ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 607 | 1 | my $next = _hash_from( $query ); | |||||||||||||||||||||||||||||||||||||||||
| 608 | 1 | for my $key ( CORE::keys %{ $next } ) { | |||||||||||||||||||||||||||||||||||||||||
| 609 | 1 | ▶ | $self->slots->{_spec}{query}{$key} = defined $next->{$key} ? "$next->{$key}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||
| 611 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 612 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | $request_class->methods->{json} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 616 | name => 'json', | ||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | $self->slots->{_spec}{json} = zuzu_to_perl($value); | |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 621 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | $request_class->methods->{multipart} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 625 | name => 'multipart', | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | my ( $self, $fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | $self->slots->{_spec}{multipart} = _hash_from( $fields ); | |||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 630 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 631 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | $request_class->methods->{auth_bearer} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 634 | name => 'auth_bearer', | ||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | my ( $self, $token ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | my $value = defined $token ? "$token" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | $self->slots->{_spec}{headers}{authorization} = "Bearer $value"; | |||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 640 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | $request_class->methods->{send} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 644 | name => 'send', | ||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | my ( $self, $ua_obj ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 647 | die 'Request.send expects a UserAgent' if not blessed($ua_obj) | ||||||||||||||||||||||||||||||||||||||||||
| 648 | or not $ua_obj->isa( 'Zuzu::Value::Object' ) | ||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | or not exists $ua_obj->slots->{_ua}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
builtin::blessed($ua_obj) and $ua_obj->isa("Zuzu::Value::Object") and exists $ua_obj->slots->{"_ua"}
builtin::blessed($ua_obj) and $ua_obj->isa("Zuzu::Value::Object")
MC/DC0%0/3
builtin::blessed($ua_obj) and $ua_obj->isa("Zuzu::Value::Object") and exists $ua_obj->slots->{"_ua"}
builtin::blessed($ua_obj)
$ua_obj->isa("Zuzu::Value::Object")
exists $ua_obj->slots->{"_ua"}
Truth table0%0/4
A and B and C
A= builtin::blessed($ua_obj)B= $ua_obj->isa("Zuzu::Value::Object")C= exists $ua_obj->slots->{"_ua"}
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | return $useragent_class->methods->{send}{_native}->( $ua_obj, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 651 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 652 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | $request_class->methods->{send_async} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 655 | name => 'send_async', | ||||||||||||||||||||||||||||||||||||||||||
| 656 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 1 | my ( $self, $ua_obj ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 658 | die 'Request.send_async expects a UserAgent' if not blessed($ua_obj) | ||||||||||||||||||||||||||||||||||||||||||
| 659 | or not $ua_obj->isa( 'Zuzu::Value::Object' ) | ||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | ▶ | or not exists $ua_obj->slots->{_ua}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
builtin::blessed($ua_obj) and $ua_obj->isa("Zuzu::Value::Object") and exists $ua_obj->slots->{"_ua"}
builtin::blessed($ua_obj) and $ua_obj->isa("Zuzu::Value::Object")
MC/DC0%0/3
builtin::blessed($ua_obj) and $ua_obj->isa("Zuzu::Value::Object") and exists $ua_obj->slots->{"_ua"}
builtin::blessed($ua_obj)
$ua_obj->isa("Zuzu::Value::Object")
exists $ua_obj->slots->{"_ua"}
Truth table25%1/4
A and B and C
A= builtin::blessed($ua_obj)B= $ua_obj->isa("Zuzu::Value::Object")C= exists $ua_obj->slots->{"_ua"}
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | 1 | return $useragent_class->methods->{send_async}{_native}->( | |||||||||||||||||||||||||||||||||||||||||
| 662 | $ua_obj, | ||||||||||||||||||||||||||||||||||||||||||
| 663 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 664 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 665 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 666 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | 6 | ▶ | $useragent_class->native_constructor( sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 6 | my ( $rt, $klass, $positional, $named ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 6 | my %config = %{ _extract_config( $positional, $named ) }; | |||||||||||||||||||||||||||||||||||||||||
| 671 | 6 | my $transport = delete $config{transport}; | |||||||||||||||||||||||||||||||||||||||||
| 672 | 6 | my %tls_config; | |||||||||||||||||||||||||||||||||||||||||
| 673 | 6 | for my $key ( qw( tls_identity tls_ca tls_verify tls_server_name tls_min_version tls_ciphers ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 674 | 36 | ▶ | $tls_config{$key} = delete $config{$key} if exists $config{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | 6 | ▶ | if ( exists $config{default_headers} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $config{default_headers} = _hash_from( $config{default_headers} ); | |||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 6 | ▶ | if ( exists $config{cookie_jar} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | $config{cookie_jar} = _cookie_jar_from_value( $config{cookie_jar} ); | |||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | 6 | ▶ | my $ua = $transport || HTTP::Tiny->new( %config ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$transport || 'HTTP::Tiny'->new(%config)
MC/DC0%0/2
$transport || 'HTTP::Tiny'->new(%config)
$transport
'HTTP::Tiny'->new(%config)
Truth table33%1/3
A || B
A= $transportB= 'HTTP::Tiny'->new(%config)
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||
| 686 | 6 | return native_object( | |||||||||||||||||||||||||||||||||||||||||
| 687 | class => $klass, | ||||||||||||||||||||||||||||||||||||||||||
| 688 | slots => { | ||||||||||||||||||||||||||||||||||||||||||
| 689 | _ua => $ua, | ||||||||||||||||||||||||||||||||||||||||||
| 690 | _tls_config => \%tls_config, | ||||||||||||||||||||||||||||||||||||||||||
| 691 | _ua_config => \%config, | ||||||||||||||||||||||||||||||||||||||||||
| 692 | _response_class => $response_class, | ||||||||||||||||||||||||||||||||||||||||||
| 693 | _request_class => $request_class, | ||||||||||||||||||||||||||||||||||||||||||
| 694 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 695 | const => { | ||||||||||||||||||||||||||||||||||||||||||
| 696 | _ua => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 697 | _tls_config => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 698 | _ua_config => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 699 | _response_class => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 700 | _request_class => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 701 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 702 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 703 | 14 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | $useragent_class->methods->{build_request} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 706 | name => 'build_request', | ||||||||||||||||||||||||||||||||||||||||||
| 707 | 3 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | 3 | my ( $self, $method, $url ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 709 | 3 | ▶ | my $spec = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | method => defined $method ? "$method" : 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 711 | url => defined $url ? "$url" : '', | ||||||||||||||||||||||||||||||||||||||||||
| 712 | headers => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 713 | query => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 714 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 715 | return native_object( | ||||||||||||||||||||||||||||||||||||||||||
| 716 | class => $self->slots->{_request_class}, | ||||||||||||||||||||||||||||||||||||||||||
| 717 | 3 | slots => { | |||||||||||||||||||||||||||||||||||||||||
| 718 | _spec => $spec, | ||||||||||||||||||||||||||||||||||||||||||
| 719 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 720 | const => { | ||||||||||||||||||||||||||||||||||||||||||
| 721 | _spec => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 722 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 723 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 724 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 725 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | $useragent_class->methods->{send} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 728 | name => 'send', | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 2 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | 2 | my ( $self, $request ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 731 | 2 | _warn_blocking_operation( $runtime, 'std/net/http UserAgent.send' ); | |||||||||||||||||||||||||||||||||||||||||
| 732 | die 'UserAgent.send expects a Request' if not blessed($request) | ||||||||||||||||||||||||||||||||||||||||||
| 733 | or not $request->isa( 'Zuzu::Value::Object' ) | ||||||||||||||||||||||||||||||||||||||||||
| 734 | 2 | ▶ | or not exists $request->slots->{_spec}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
builtin::blessed($request) and $request->isa("Zuzu::Value::Object") and exists $request->slots->{"_spec"}
builtin::blessed($request) and $request->isa("Zuzu::Value::Object")
MC/DC0%0/3
builtin::blessed($request) and $request->isa("Zuzu::Value::Object") and exists $request->slots->{"_spec"}
builtin::blessed($request)
$request->isa("Zuzu::Value::Object")
exists $request->slots->{"_spec"}
Truth table25%1/4
A and B and C
A= builtin::blessed($request)B= $request->isa("Zuzu::Value::Object")C= exists $request->slots->{"_spec"}
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | 2 | my $spec = $request->slots->{_spec}; | |||||||||||||||||||||||||||||||||||||||||
| 736 | 2 | ▶ | my $method_name = defined $spec->{method} ? uc "$spec->{method}" : 'GET'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | 2 | ▶ | my $target = defined $spec->{url} ? "$spec->{url}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | 2 | $target = _merge_query( $target, _hash_from( $spec->{query} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 739 | 2 | ▶ | my %tls_config = %{ $self->slots->{_tls_config} // {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->slots->{"_tls_config"} // {}
MC/DC0%0/1
$self->slots->{"_tls_config"} // {}
$self->slots->{"_tls_config"}
Truth table50%1/2
A
A= $self->slots->{"_tls_config"}
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | $tls_config{tls_identity} = $spec->{tls_identity} | ||||||||||||||||||||||||||||||||||||||||||
| 741 | 2 | ▶ | if exists $spec->{tls_identity}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | 2 | ▶ | my %client_config = %{ $self->slots->{_ua_config} // {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->slots->{"_ua_config"} // {}
MC/DC0%0/1
$self->slots->{"_ua_config"} // {}
$self->slots->{"_ua_config"}
Truth table50%1/2
A
A= $self->slots->{"_ua_config"}
| |||||||||||||||||||||||||||||||||||||||||||
| 743 | 2 | my $opts = _build_request_options( | |||||||||||||||||||||||||||||||||||||||||
| 744 | $spec, | ||||||||||||||||||||||||||||||||||||||||||
| 745 | \%tls_config, | ||||||||||||||||||||||||||||||||||||||||||
| 746 | \%client_config, | ||||||||||||||||||||||||||||||||||||||||||
| 747 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 748 | 2 | my $tempfiles = delete $client_config{_tls_tempfiles}; | |||||||||||||||||||||||||||||||||||||||||
| 749 | my $ua = CORE::keys(%tls_config) | ||||||||||||||||||||||||||||||||||||||||||
| 750 | ? HTTP::Tiny->new(%client_config) | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 2 | ▶ | : $self->slots->{_ua}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | 2 | ▶ | my $retries = defined $spec->{retries} ? int( $spec->{retries} ) : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | 2 | ▶ | $retries = 0 if $retries < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 2 | my $response = _perform_request( | |||||||||||||||||||||||||||||||||||||||||
| 755 | $ua, | ||||||||||||||||||||||||||||||||||||||||||
| 756 | $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 757 | $target, | ||||||||||||||||||||||||||||||||||||||||||
| 758 | $opts, | ||||||||||||||||||||||||||||||||||||||||||
| 759 | $retries, | ||||||||||||||||||||||||||||||||||||||||||
| 760 | $tempfiles, | ||||||||||||||||||||||||||||||||||||||||||
| 761 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 762 | 2 | return _wrap_response( $self->slots->{_response_class}, $response ); | |||||||||||||||||||||||||||||||||||||||||
| 763 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 764 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | $useragent_class->methods->{send_async} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 767 | name => 'send_async', | ||||||||||||||||||||||||||||||||||||||||||
| 768 | 6 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=28.2
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | 6 | my ( $self, $request ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 770 | die 'UserAgent.send_async expects a Request' if not blessed($request) | ||||||||||||||||||||||||||||||||||||||||||
| 771 | or not $request->isa( 'Zuzu::Value::Object' ) | ||||||||||||||||||||||||||||||||||||||||||
| 772 | 6 | ▶ | or not exists $request->slots->{_spec}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
builtin::blessed($request) and $request->isa("Zuzu::Value::Object") and exists $request->slots->{"_spec"}
builtin::blessed($request) and $request->isa("Zuzu::Value::Object")
MC/DC0%0/3
builtin::blessed($request) and $request->isa("Zuzu::Value::Object") and exists $request->slots->{"_spec"}
builtin::blessed($request)
$request->isa("Zuzu::Value::Object")
exists $request->slots->{"_spec"}
Truth table25%1/4
A and B and C
A= builtin::blessed($request)B= $request->isa("Zuzu::Value::Object")C= exists $request->slots->{"_spec"}
| |||||||||||||||||||||||||||||||||||||||||||
| 773 | 6 | my $spec = $request->slots->{_spec}; | |||||||||||||||||||||||||||||||||||||||||
| 774 | 6 | my $ua = $self->slots->{_ua}; | |||||||||||||||||||||||||||||||||||||||||
| 775 | 6 | ▶ | my $tls_config = { %{ $self->slots->{_tls_config} // {} } }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->slots->{"_tls_config"} // {}
MC/DC0%0/1
$self->slots->{"_tls_config"} // {}
$self->slots->{"_tls_config"}
Truth table50%1/2
A
A= $self->slots->{"_tls_config"}
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | $tls_config->{tls_identity} = $spec->{tls_identity} | ||||||||||||||||||||||||||||||||||||||||||
| 777 | 6 | ▶ | if exists $spec->{tls_identity}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | 6 | ▶ | my $ua_config = { %{ $self->slots->{_ua_config} // {} } }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->slots->{"_ua_config"} // {}
MC/DC0%0/1
$self->slots->{"_ua_config"} // {}
$self->slots->{"_ua_config"}
Truth table50%1/2
A
A= $self->slots->{"_ua_config"}
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 6 | my $response_class = $self->slots->{_response_class}; | |||||||||||||||||||||||||||||||||||||||||
| 780 | return _async_task( | ||||||||||||||||||||||||||||||||||||||||||
| 781 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 'http.send_async', | ||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | my $method_name = defined $spec->{method} | ||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | ▶ | ? uc "$spec->{method}" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | : 'GET'; | ||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | my $target = defined $spec->{url} ? "$spec->{url}" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | $target = _merge_query( $target, _hash_from( $spec->{query} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | my $opts = _build_request_options( | |||||||||||||||||||||||||||||||||||||||||
| 790 | $spec, | ||||||||||||||||||||||||||||||||||||||||||
| 791 | $tls_config, | ||||||||||||||||||||||||||||||||||||||||||
| 792 | $ua_config, | ||||||||||||||||||||||||||||||||||||||||||
| 793 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | my $tempfiles = delete $ua_config->{_tls_tempfiles}; | |||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | my $request_ua = CORE::keys( %{$tls_config} ) | |||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | ? HTTP::Tiny->new( %{$ua_config} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 797 | : $ua; | ||||||||||||||||||||||||||||||||||||||||||
| 798 | my $retries = defined $spec->{retries} | ||||||||||||||||||||||||||||||||||||||||||
| 799 | ? int( $spec->{retries} ) | ||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | ▶ | : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | $retries = 0 if $retries < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | return _perform_request( | |||||||||||||||||||||||||||||||||||||||||
| 803 | $request_ua, | ||||||||||||||||||||||||||||||||||||||||||
| 804 | $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 805 | $target, | ||||||||||||||||||||||||||||||||||||||||||
| 806 | $opts, | ||||||||||||||||||||||||||||||||||||||||||
| 807 | $retries, | ||||||||||||||||||||||||||||||||||||||||||
| 808 | $tempfiles, | ||||||||||||||||||||||||||||||||||||||||||
| 809 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 810 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 6 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | 6 | my ( $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 813 | 6 | return _wrap_response( $response_class, $response ); | |||||||||||||||||||||||||||||||||||||||||
| 814 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 815 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 816 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 817 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | $useragent_class->methods->{request} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 820 | name => 'request', | ||||||||||||||||||||||||||||||||||||||||||
| 821 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 1 | my ( $self, $method, $url, $data, $headers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 823 | my $req = $self->slots->{_request_class}->native_constructor->( | ||||||||||||||||||||||||||||||||||||||||||
| 824 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 825 | $self->slots->{_request_class}, | ||||||||||||||||||||||||||||||||||||||||||
| 826 | 1 | [], | |||||||||||||||||||||||||||||||||||||||||
| 827 | { | ||||||||||||||||||||||||||||||||||||||||||
| 828 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 829 | url => $url, | ||||||||||||||||||||||||||||||||||||||||||
| 830 | body => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 831 | headers => $headers, | ||||||||||||||||||||||||||||||||||||||||||
| 832 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 833 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 834 | 1 | return $useragent_class->methods->{send}{_native}->( $self, $req ); | |||||||||||||||||||||||||||||||||||||||||
| 835 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 836 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | $useragent_class->methods->{request_async} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 839 | name => 'request_async', | ||||||||||||||||||||||||||||||||||||||||||
| 840 | 4 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 841 | 4 | my ( $self, $method, $url, $data, $headers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 842 | my $req = $self->slots->{_request_class}->native_constructor->( | ||||||||||||||||||||||||||||||||||||||||||
| 843 | $runtime, | ||||||||||||||||||||||||||||||||||||||||||
| 844 | $self->slots->{_request_class}, | ||||||||||||||||||||||||||||||||||||||||||
| 845 | 4 | [], | |||||||||||||||||||||||||||||||||||||||||
| 846 | { | ||||||||||||||||||||||||||||||||||||||||||
| 847 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 848 | url => $url, | ||||||||||||||||||||||||||||||||||||||||||
| 849 | body => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 850 | headers => $headers, | ||||||||||||||||||||||||||||||||||||||||||
| 851 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 852 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 853 | 4 | return $useragent_class->methods->{send_async}{_native}->( | |||||||||||||||||||||||||||||||||||||||||
| 854 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 855 | $req, | ||||||||||||||||||||||||||||||||||||||||||
| 856 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 857 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 858 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||
| 860 | 14 | for my $method ( qw( get head delete post put patch options ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 861 | $useragent_class->methods->{$method} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 862 | name => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 863 | 1 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.3
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 1 | my ( $self, $url, $data_or_headers, $headers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 865 | 1 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 866 | my $extra_headers; | ||||||||||||||||||||||||||||||||||||||||||
| 867 | 1 | ▶ | if ( $method eq 'post' or $method eq 'put' or $method eq 'patch' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$method eq "post" or $method eq "put" or $method eq "patch"
$method eq "post" or $method eq "put"
MC/DC0%0/3
$method eq "post" or $method eq "put" or $method eq "patch"
$method eq "post"
$method eq "put"
$method eq "patch"
Truth table25%1/4
A or B or C
A= $method eq "post"B= $method eq "put"C= $method eq "patch"
| |||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | $data = $data_or_headers; | |||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | $extra_headers = $headers; | |||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||
| 871 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 872 | 1 | ▶ | $extra_headers = $data_or_headers if defined $data_or_headers; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||
| 874 | 1 | return $useragent_class->methods->{request}{_native}->( | |||||||||||||||||||||||||||||||||||||||||
| 875 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 876 | uc($method), | ||||||||||||||||||||||||||||||||||||||||||
| 877 | $url, | ||||||||||||||||||||||||||||||||||||||||||
| 878 | $data, | ||||||||||||||||||||||||||||||||||||||||||
| 879 | $extra_headers, | ||||||||||||||||||||||||||||||||||||||||||
| 880 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 881 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 882 | 98 | ); | |||||||||||||||||||||||||||||||||||||||||
| 883 | $useragent_class->methods->{ $method . '_async' } = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 884 | name => $method . '_async', | ||||||||||||||||||||||||||||||||||||||||||
| 885 | 4 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.3
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | 4 | my ( $self, $url, $data_or_headers, $headers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 887 | 4 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 888 | my $extra_headers; | ||||||||||||||||||||||||||||||||||||||||||
| 889 | 4 | ▶ | if ( $method eq 'post' or $method eq 'put' or $method eq 'patch' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$method eq "post" or $method eq "put" or $method eq "patch"
$method eq "post" or $method eq "put"
MC/DC0%0/3
$method eq "post" or $method eq "put" or $method eq "patch"
$method eq "post"
$method eq "put"
$method eq "patch"
Truth table25%1/4
A or B or C
A= $method eq "post"B= $method eq "put"C= $method eq "patch"
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | $data = $data_or_headers; | |||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | $extra_headers = $headers; | |||||||||||||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||||||||||||
| 893 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 894 | 4 | ▶ | $extra_headers = $data_or_headers if defined $data_or_headers; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||
| 896 | 4 | return $useragent_class->methods->{request_async}{_native}->( | |||||||||||||||||||||||||||||||||||||||||
| 897 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 898 | uc($method), | ||||||||||||||||||||||||||||||||||||||||||
| 899 | $url, | ||||||||||||||||||||||||||||||||||||||||||
| 900 | $data, | ||||||||||||||||||||||||||||||||||||||||||
| 901 | $extra_headers, | ||||||||||||||||||||||||||||||||||||||||||
| 902 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 903 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 904 | 98 | ); | |||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 908 | 14 | CookieJar => $cookiejar_class, | |||||||||||||||||||||||||||||||||||||||||
| 909 | Request => $request_class, | ||||||||||||||||||||||||||||||||||||||||||
| 910 | Response => $response_class, | ||||||||||||||||||||||||||||||||||||||||||
| 911 | UserAgent => $useragent_class, | ||||||||||||||||||||||||||||||||||||||||||
| 912 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||
| 919 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||
| 921 | Zuzu::Module::HTTP - std/net/http bindings for ZuzuScript. | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | Implements the C<std/net/http> module and exports C<CookieJar>, | ||||||||||||||||||||||||||||||||||||||||||
| 926 | C<Request>, C<Response>, and C<UserAgent>. | ||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | =head1 CLASSES | ||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | =head2 CookieJar | ||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | Cookie storage abstraction used by C<UserAgent>. Uses | ||||||||||||||||||||||||||||||||||||||||||
| 933 | C<HTTP::CookieJar> when available, otherwise a basic in-memory fallback. | ||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||
| 935 | Methods: | ||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||
| 939 | =item * C<add(url, set_cookie)> | ||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||
| 941 | =item * C<cookie_header(url)> | ||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||
| 943 | =item * C<clear()> | ||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||
| 945 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||
| 947 | =head2 Response | ||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||
| 949 | Wrapper around an HTTP response hash. | ||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||
| 951 | Methods include C<status>, C<reason>, C<url>, C<content>, C<headers>, | ||||||||||||||||||||||||||||||||||||||||||
| 952 | C<header(name)>, C<success>, C<json>, C<expect_success>, | ||||||||||||||||||||||||||||||||||||||||||
| 953 | C<validate_json>, and C<to_Dict>. | ||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||
| 955 | =head2 Request | ||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||
| 957 | Mutable request builder used by C<UserAgent>. | ||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||
| 959 | Methods include C<method>, C<url>, C<header>, C<headers>, C<query>, | ||||||||||||||||||||||||||||||||||||||||||
| 960 | C<body>, C<json>, C<auth_bearer>, C<timeout>, C<retries>, | ||||||||||||||||||||||||||||||||||||||||||
| 961 | C<download_to>, C<upload_from>, C<multipart>, and C<send(user_agent)>. | ||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||
| 963 | =head2 UserAgent | ||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | Wrapper around C<HTTP::Tiny>. | ||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||
| 967 | Methods include C<build_request(method, url)>, C<send(request)>, | ||||||||||||||||||||||||||||||||||||||||||
| 968 | C<request(method, url, data?, headers?)>, plus shorthand methods | ||||||||||||||||||||||||||||||||||||||||||
| 969 | C<get>, C<head>, C<delete>, C<post>, C<put>, C<patch>, and C<options>. | ||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||
| 971 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||
| 973 | B<< Zuzu::Module::HTTP >> is copyright Toby Inkster. | ||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||
| 975 | It is free software; you may redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 976 | the terms of either the Artistic License 1.0 or the GNU General Public | ||||||||||||||||||||||||||||||||||||||||||
| 977 | License version 2. | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | =cut | ||||||||||||||||||||||||||||||||||||||||||