| 1 | package Net::HTTP::Knork::Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: HTTP request object from SPORE env hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Net::HTTP::Knork::Response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | has env => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | default => sub { { } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 16 | ▶ | sub get_from_env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_from_env: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 16 | return $_[0]->env->{$_[1]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub set_to_env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_to_env: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $_[0]->env->{$_[1]} = $_[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | has path => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | default => sub { $_[0]->env->{PATH_INFO} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | has headers => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | header => 'header', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | my $env = $self->env; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | my $h = HTTP::Headers->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | ( my $field = $_ ) =~ s/^HTTPS?_//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ( $field => $env->{$_} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | } grep { /^(?:HTTP|CONTENT)/i } keys %$env | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | return $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | if (@_ == 1 && !exists $_[0]->{env}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and not exists $_[0]{"env"}
MC/DC0%0/2
@_ == 1 and not exists $_[0]{"env"}
@_ == 1
not exists $_[0]{"env"}
Truth table33%1/3
A and not(B)
A= @_ == 1B= not exists $_[0]{"env"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | return {env => $_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 16 | ▶ | sub set_or_get_from_env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_or_get_from_env: called CC=2 SCAR=8.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 16 | my ( $self, $var, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 16 | ▶ | if ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $self->set_to_env( $var, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 16 | return $self->get_from_env($var); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | ▶ | sub method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | return $self->set_or_get_from_env( 'REQUEST_METHOD', $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub host { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return $self->set_or_get_from_env( 'SERVER_NAME', $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub port { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
port: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return $self->set_or_get_from_env( 'SERVER_PORT', $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub script_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
script_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return $self->set_or_get_from_env( 'SCRIPT_NAME', $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub request_uri { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_uri: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return $self->set_or_get_from_env( 'REQUEST_URI', $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub scheme { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scheme: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return $self->set_or_get_from_env( 'spore.url_scheme', $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub logger { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logger: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return $self->set_or_get_from_env( 'sporex.logger', $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 8 | ▶ | sub body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 8 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 8 | return $self->set_or_get_from_env( 'spore.payload', $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub base { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | URI->new( $self->_uri_base )->canonical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub input { (shift)->body(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
input: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | ▶ | sub content { (shift)->body(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub secure { $_[0]->scheme eq 'https' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
secure: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # TODO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # need to refactor this method, with path_info and query_string construction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 8 | ▶ | sub uri { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: called CC=7 SCAR=23.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | my ($self, $path_info, $query_string) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | ▶ | if ( !defined $path_info || !defined $query_string ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $path_info and defined $query_string
MC/DC0%0/2
defined $path_info and defined $query_string
defined $path_info
defined $query_string
Truth table33%1/3
A and B
A= defined $path_infoB= defined $query_string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ($path_info,$query_string) = $self->_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | my $base = $self->_uri_base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | my $path_escape_class = '^A-Za-z0-9\-\._~/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 8 | ▶ | my $path = URI::Escape::uri_escape($path_info // '', $path_escape_class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$path_info // ""
MC/DC0%0/1
$path_info // ""
$path_info
Truth table50%1/2
A
A= $path_info
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 8 | ▶ | if (defined $query_string && length($query_string) > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $query_string and length $query_string > 0
MC/DC0%0/2
defined $query_string and length $query_string > 0
defined $query_string
length $query_string > 0
Truth table33%1/3
A and B
A= defined $query_stringB= length $query_string > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $path .= '?' . $query_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | ▶ | $base =~ s/\/$// if $path =~ m/^\//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 8 | return URI->new( $base . $path )->canonical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub _path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_path: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $query_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $path = $self->env->{PATH_INFO}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my @params = @{ $self->env->{'spore.params'} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->env->{'spore.params'} || []
MC/DC0%0/1
$self->env->{'spore.params'} || []
$self->env->{'spore.params'}
Truth table0%0/2
A
A= $self->env->{'spore.params'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $j = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | for (my $i = 0; $i < scalar @params; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $key = $params[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $value = $params[++$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if (!$value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $query_string .= $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | unless ( $path && $path =~ s/\:$key/$value/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$path and $path =~ s/\:$key/$value/
MC/DC0%0/2
$path and $path =~ s/\:$key/$value/
$path
$path =~ s/\:$key/$value/
Truth table0%0/3
A and B
A= $pathB= $path =~ s/\:$key/$value/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $query_string .= $key . '=' . $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $query_string .= '&' if $query_string && scalar @params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$query_string and scalar @params
MC/DC0%0/1
$query_string and scalar @params
$query_string
Truth table0%0/2
A
A= $query_string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $query_string =~ s/&$// if $query_string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return ( $path, $query_string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 8 | ▶ | sub _uri_base { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uri_base: called CC=7 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 8 | my $env = $self->env; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | my $uri = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ( $env->{'spore.url_scheme'} || "http" ) . "://" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | . ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | defined $env->{'spore.userinfo'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ? $env->{'spore.userinfo'} . '@' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | : '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | . ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | $env->{HTTP_HOST} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | || (( $env->{SERVER_NAME} || "" ) . ":" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | . ( $env->{SERVER_PORT} || 80 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 8 | ▶ | ) . ( $env->{SCRIPT_NAME} || '/' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%5/10
$env->{'spore.url_scheme'} || 'http'
$env->{'HTTP_HOST'} || ($env->{'SERVER_NAME'} || '') . ':' . ($env->{'SERVER_PORT'} || 80)
$env->{'SERVER_NAME'} || ''
$env->{'SERVER_PORT'} || 80
$env->{'SCRIPT_NAME'} || '/'
MC/DC0%0/1
$env->{'spore.url_scheme'} || 'http'
$env->{'spore.url_scheme'}
MC/DC0%0/1
$env->{'HTTP_HOST'} || ($env->{'SERVER_NAME'} || '') . ':' . ($env->{'SERVER_PORT'} || 80)
$env->{'HTTP_HOST'}
MC/DC0%0/1
$env->{'SERVER_PORT'} || 80
$env->{'SERVER_PORT'}
MC/DC0%0/1
$env->{'SCRIPT_NAME'} || '/'
$env->{'SCRIPT_NAME'}
Truth table50%1/2
A
A= $env->{'spore.url_scheme'}
Truth table50%1/2
A
A= $env->{'HTTP_HOST'}
Truth table50%1/2
A
A= $env->{'SERVER_PORT'}
Truth table50%1/2
A
A= $env->{'SCRIPT_NAME'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 8 | return $uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 8 | ▶ | sub new_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_response: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 8 | my $res = Net::HTTP::Knork::Response->new(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 8 | my $decoding = $self->env->{'spore.decode'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 8 | ▶ | if ( defined($decoding) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | ▶ | if ( ref($decoding) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | $res = $self->env->{'spore.decode'}->($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | carp 'Decoding is not a sub, returning the raw response'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 8 | $res->request($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 8 | $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 8 | ▶ | sub finalize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finalize: called CC=17 SCAR=32.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 8 | my $path_info = $self->env->{PATH_INFO}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 8 | my $headers = $self->env->{'spore.headers'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | ▶ | my $params = $self->env->{'spore.params'} || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->env->{'spore.params'} || []
MC/DC100%1/1
$self->env->{'spore.params'} || []
$self->env->{'spore.params'}
Truth table100%2/2
A
A= $self->env->{'spore.params'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | my $query = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 8 | ▶ | for ( my $i = 0 ; $i < scalar @$params ; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | my $k = $params->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 3 | ▶ | my $v = $params->[++$i] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$params[++$i] // ""
MC/DC0%0/1
$$params[++$i] // ""
$$params[++$i]
Truth table50%1/2
A
A= $$params[++$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 3 | my $modified = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | if ($path_info && $path_info =~ s/\:$k/$v/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$path_info and $path_info =~ s/\:$k/$v/
MC/DC0%0/2
$path_info and $path_info =~ s/\:$k/$v/
$path_info
$path_info =~ s/\:$k/$v/
Truth table33%1/3
A and B
A= $path_infoB= $path_info =~ s/\:$k/$v/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | $modified++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | foreach my $h_k (keys %$headers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $h_v = $headers->{$h_k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | if ($h_v =~ s/^\:$k/$v/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $self->header($h_k => $h_v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $modified++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | if ($modified == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if (defined $v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | push @$query, $k.'='.$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | push @$query, $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # clean remaining :name in url | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 8 | ▶ | $path_info =~ s/:\w+//g if $path_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 8 | my $query_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 8 | ▶ | if (scalar @$query) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $query_string = join('&', @$query); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 8 | $self->env->{PATH_INFO} = $path_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 8 | $self->env->{QUERY_STRING} = $query_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 8 | ▶ | my $uri = $self->uri($path_info, $query_string || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$query_string || ''
MC/DC0%0/1
$query_string || ''
$query_string
Truth table50%1/2
A
A= $query_string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 8 | my $request = HTTP::Request->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | $self->method => $uri, $self->headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 8 | ▶ | if ( my $payload = $self->content ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | my $encoding = $self->env->{'spore.encode'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | $request->content($payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | ▶ | if (defined($encoding)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | ▶ | if (ref($encoding) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | $request = $self->env->{'spore.encode'}->($request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | carp 'Encoding specified is not a sub, sending form-urlencoded request instead'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # stolen from HTTP::Request::Common | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | my $url = URI->new('http:'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 2 | ▶ | $url->query_form( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | ref($payload) eq 'HASH' ? %$payload : @$payload ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | $payload = $url->query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | $request->header( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 'Content-Type' => 'application/x-www-form-urlencoded' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | $request->content($payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 8 | return $request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||