| 1 | package Dancer2::Core::Request; | ||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Interface for accessing incoming requests | ||||||||||||||||||||||||||||||||||||||||
| 3 | 187 | $Dancer2::Core::Request::VERSION = '2.2.1'; | |||||||||||||||||||||||||||||||||||||||
| 4 | 187 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | 187 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 6 | 187 | ▶ | use parent 'Plack::Request'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | 187 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 187 | ▶ | use Encode qw(decode FB_CROAK LEAVE_SRC); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | 187 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 11 | 187 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 12 | 187 | ▶ | use Safe::Isa; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 13 | 187 | ▶ | use Hash::MultiValue; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 14 | 187 | ▶ | use Ref::Util qw< is_ref is_arrayref is_hashref is_coderef >; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||
| 16 | 187 | ▶ | use Dancer2::Core::Types; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 17 | 187 | ▶ | use Dancer2::Core::Request::Upload; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 18 | 187 | ▶ | use Dancer2::Core::Cookie; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||
| 20 | # add an attribute for each HTTP_* variables | ||||||||||||||||||||||||||||||||||||||||
| 21 | # (HOST is managed manually) | ||||||||||||||||||||||||||||||||||||||||
| 22 | 187 | my @http_env_keys = (qw/ | |||||||||||||||||||||||||||||||||||||||
| 23 | accept_charset | ||||||||||||||||||||||||||||||||||||||||
| 24 | accept_encoding | ||||||||||||||||||||||||||||||||||||||||
| 25 | accept_language | ||||||||||||||||||||||||||||||||||||||||
| 26 | connection | ||||||||||||||||||||||||||||||||||||||||
| 27 | keep_alive | ||||||||||||||||||||||||||||||||||||||||
| 28 | x_requested_with | ||||||||||||||||||||||||||||||||||||||||
| 29 | /); | ||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||
| 31 | # apparently you can't eval core functions | ||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub accept { $_[0]->env->{'HTTP_ACCEPT'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | eval << "_EVAL" or die $@ for @http_env_keys; ## no critic | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_charset: called CC=1 SCAR=0.0
Subroutine
accept_encoding: called CC=1 SCAR=0.0
Subroutine
accept_language: called CC=1 SCAR=0.0
Subroutine
connection: called CC=1 SCAR=0.0
Subroutine
keep_alive: called CC=1 SCAR=0.0
Subroutine
x_requested_with: called CC=1 SCAR=0.0
Pod
documented
Pod
documented
Pod
documented
Pod
documented
Pod
documented
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 35 | sub $_ { \$_[0]->env->{ 'HTTP_' . ( uc "$_" ) } } | ||||||||||||||||||||||||||||||||||||||||
| 36 | 1; | ||||||||||||||||||||||||||||||||||||||||
| 37 | _EVAL | ||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||
| 39 | eval { | ||||||||||||||||||||||||||||||||||||||||
| 40 | 187 | require Unicode::UTF8; | |||||||||||||||||||||||||||||||||||||||
| 41 | 187 | ▶ | no warnings qw<redefine once>; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 42 | 34 | ▶ | *__decode = sub { Unicode::UTF8::decode_utf8($_[0]) }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 43 | 39 | ▶ | *__valid = sub { Unicode::UTF8::valid_utf8($_[0]) }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 44 | 187 | 1; | |||||||||||||||||||||||||||||||||||||||
| 45 | 187 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 46 | 187 | ▶ | no warnings qw<redefine once>; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | *__decode = sub { decode( 'UTF-8', $_[0] ) }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 48 | *__valid = sub { | ||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | eval { decode( 'UTF-8', $_[0], FB_CROAK | LEAVE_SRC ); 1 }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | }; | |||||||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||
| 53 | # check presence of XS module to speedup request | ||||||||||||||||||||||||||||||||||||||||
| 54 | 187 | our $XS_URL_DECODE = eval { require URL::Encode::XS; 1; }; | |||||||||||||||||||||||||||||||||||||||
| 55 | 187 | our $XS_PARSE_QUERY_STRING = eval { require CGI::Deurl::XS; 1; }; | |||||||||||||||||||||||||||||||||||||||
| 56 | 187 | our $XS_HTTP_COOKIES = eval { require HTTP::XSCookies; 1; }; | |||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | 187 | our $_id = 0; | |||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | # self->new( env => {}, serializer => $s, is_behind_proxy => 0|1 ) | ||||||||||||||||||||||||||||||||||||||||
| 61 | sub new { | ||||||||||||||||||||||||||||||||||||||||
| 62 | 978 | ▶ | my ( $class, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | # even sized list | ||||||||||||||||||||||||||||||||||||||||
| 65 | 978 | ▶ | @args % 2 == 0 | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 66 | or croak 'Must provide even sized list'; | ||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||
| 68 | 978 | my %opts = @args; | |||||||||||||||||||||||||||||||||||||||
| 69 | 978 | my $env = $opts{'env'}; | |||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||
| 71 | 978 | my $self = $class->SUPER::new($env); | |||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||
| 73 | 978 | ▶ | if ( my $s = $opts{'serializer'} ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 74 | 116 | ▶ | $s->$_does('Dancer2::Core::Role::Serializer') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 75 | or croak 'Serializer provided not a Serializer object'; | ||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||
| 77 | 115 | $self->{'serializer'} = $s; | |||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||
| 80 | # additionally supported attributes | ||||||||||||||||||||||||||||||||||||||||
| 81 | 977 | $self->{'id'} = ++$_id; | |||||||||||||||||||||||||||||||||||||||
| 82 | 977 | $self->{'vars'} = {}; | |||||||||||||||||||||||||||||||||||||||
| 83 | 977 | $self->{'is_behind_proxy'} = !!$opts{'is_behind_proxy'}; | |||||||||||||||||||||||||||||||||||||||
| 84 | 977 | $self->{'uri_for_route'} = $opts{'uri_for_route'}; | |||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||
| 86 | $opts{'body_params'} | ||||||||||||||||||||||||||||||||||||||||
| 87 | 977 | ▶ | and $self->{'_body_params'} = $opts{'body_params'}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 88 | 977 | $self->{'_strict_utf8'} = !!$opts{'strict_utf8'}; | |||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||
| 90 | # Deserialize/parse body for HMV | ||||||||||||||||||||||||||||||||||||||||
| 91 | 977 | $self->data; | |||||||||||||||||||||||||||||||||||||||
| 92 | 973 | $self->_build_uploads(); | |||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||
| 94 | 972 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||
| 97 | # a buffer for per-request variables | ||||||||||||||||||||||||||||||||||||||||
| 98 | 130 | ▶ | sub vars { $_[0]->{'vars'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
vars: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||
| 100 | sub var { | ||||||||||||||||||||||||||||||||||||||||
| 101 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
var: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 102 | @_ == 2 | ||||||||||||||||||||||||||||||||||||||||
| 103 | ? $self->vars->{ $_[0] } = $_[1] | ||||||||||||||||||||||||||||||||||||||||
| 104 | 13 | ▶ | : $self->vars->{ $_[0] }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||
| 107 | # I don't like this. I know send_file uses this and I wonder | ||||||||||||||||||||||||||||||||||||||||
| 108 | # if we can remove it. | ||||||||||||||||||||||||||||||||||||||||
| 109 | # -- Sawyer | ||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub set_path_info { $_[0]->env->{'PATH_INFO'} = $_[1] } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_path_info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||
| 112 | # XXX: incompatible with Plack::Request | ||||||||||||||||||||||||||||||||||||||||
| 113 | 47 | ▶ | sub body { $_[0]->raw_body } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||
| 115 | 20 | ▶ | sub id { $_id } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||
| 117 | # Private 'read-only' attributes for request params. See the params() | ||||||||||||||||||||||||||||||||||||||||
| 118 | # method for the public interface. | ||||||||||||||||||||||||||||||||||||||||
| 119 | # | ||||||||||||||||||||||||||||||||||||||||
| 120 | # _body_params, _query_params and _route_params have setter methods that | ||||||||||||||||||||||||||||||||||||||||
| 121 | # decode byte string to characters before setting; If you know you have | ||||||||||||||||||||||||||||||||||||||||
| 122 | # decoded (character) params, such as output from a deserializer, you can | ||||||||||||||||||||||||||||||||||||||||
| 123 | # set these directly in the request object hash to avoid the decode op. | ||||||||||||||||||||||||||||||||||||||||
| 124 | 364 | ▶ | sub _params { $_[0]->{'_params'} ||= $_[0]->_build_params } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_params: called CC=2 SCAR=7.2
Condition66%2/3
$_[0]{"_params"} ||= $_[0]->_build_params
MC/DC0%0/2
$_[0]{"_params"} ||= $_[0]->_build_params
$_[0]{"_params"}
$_[0]->_build_params
Truth table66%2/3
A ||= B
A= $_[0]{"_params"}B= $_[0]->_build_params
| |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||
| 126 | 781 | ▶ | sub _has_params { defined $_[0]->{'_params'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_params: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1770 | ▶ | sub _body_params { $_[0]->{'_body_params'} ||= $_[0]->body_parameters->as_hashref_mixed } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_body_params: called CC=2 SCAR=7.2
Condition66%2/3
$_[0]{"_body_params"} ||= $_[0]->body_parameters->as_hashref_mixed
MC/DC0%0/2
$_[0]{"_body_params"} ||= $_[0]->body_parameters->as_hashref_mixed
$_[0]{"_body_params"}
$_[0]->body_parameters->as_hashref_mixed
Truth table66%2/3
A ||= B
A= $_[0]{"_body_params"}B= $_[0]->body_parameters->as_hashref_mixed
| |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||
| 130 | 101 | ▶ | sub _query_params { $_[0]->{'_query_params'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_query_params: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||
| 132 | sub _set_query_params { | ||||||||||||||||||||||||||||||||||||||||
| 133 | 46 | ▶ | my ( $self, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_query_params: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 134 | 46 | $self->{_query_params} = $self->_decode( $params, 'query parameters' ); | |||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||
| 137 | 782 | ▶ | sub _route_params { $_[0]->{'_route_params'} ||= {} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_route_params: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]{"_route_params"} ||= {}
MC/DC100%1/1
$_[0]{"_route_params"} ||= {}
$_[0]{"_route_params"}
Truth table100%2/2
A
A= $_[0]{"_route_params"}
| |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||
| 139 | sub _set_route_params { | ||||||||||||||||||||||||||||||||||||||||
| 140 | 744 | ▶ | my ( $self, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_route_params: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 141 | 744 | $self->{_route_params} = $self->_decode( $params, 'route parameters' ); | |||||||||||||||||||||||||||||||||||||||
| 142 | 744 | $self->_build_params(); | |||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||
| 145 | # XXX: incompatible with Plack::Request | ||||||||||||||||||||||||||||||||||||||||
| 146 | 6 | ▶ | sub uploads { $_[0]->{'uploads'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
uploads: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||
| 148 | 415 | ▶ | sub is_behind_proxy { $_[0]->{'is_behind_proxy'} || 0 } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_behind_proxy: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||
| 150 | sub host { | ||||||||||||||||||||||||||||||||||||||||
| 151 | 201 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
host: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||
| 153 | 201 | ▶ | if ( $self->is_behind_proxy and exists $self->env->{'HTTP_X_FORWARDED_HOST'} ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->is_behind_proxy and exists $self->env->{"HTTP_X_FORWARDED_HOST"}
MC/DC100%2/2
$self->is_behind_proxy and exists $self->env->{"HTTP_X_FORWARDED_HOST"}
$self->is_behind_proxy
exists $self->env->{"HTTP_X_FORWARDED_HOST"}
Truth table100%3/3
A and B
A= $self->is_behind_proxyB= exists $self->env->{"HTTP_X_FORWARDED_HOST"}
| |||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | my @hosts = split /\s*,\s*/, $self->env->{'HTTP_X_FORWARDED_HOST'}, 2; | |||||||||||||||||||||||||||||||||||||||
| 155 | 3 | return $hosts[0]; | |||||||||||||||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 157 | 198 | return $self->env->{'HTTP_HOST'}; | |||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||
| 161 | # aliases, kept for backward compat | ||||||||||||||||||||||||||||||||||||||||
| 162 | 17 | ▶ | sub agent { shift->user_agent } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
agent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | ▶ | sub remote_address { shift->address } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
remote_address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | ▶ | sub forwarded_for_address { shift->env->{'HTTP_X_FORWARDED_FOR'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
forwarded_for_address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub forwarded_host { shift->env->{'HTTP_X_FORWARDED_HOST'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
forwarded_host: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||
| 167 | # there are two options | ||||||||||||||||||||||||||||||||||||||||
| 168 | sub forwarded_protocol { | ||||||||||||||||||||||||||||||||||||||||
| 169 | $_[0]->env->{'HTTP_X_FORWARDED_PROTO'} || | ||||||||||||||||||||||||||||||||||||||||
| 170 | $_[0]->env->{'HTTP_X_FORWARDED_PROTOCOL'} || | ||||||||||||||||||||||||||||||||||||||||
| 171 | 14 | ▶ | $_[0]->env->{'HTTP_FORWARDED_PROTO'} | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
forwarded_protocol: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
Condition100%3/3
$_[0]->env->{"HTTP_X_FORWARDED_PROTO"} or $_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"}
MC/DC100%2/2
$_[0]->env->{"HTTP_X_FORWARDED_PROTO"} or $_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"}
$_[0]->env->{"HTTP_X_FORWARDED_PROTO"}
$_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"}
Truth table100%3/3
A or B
A= $_[0]->env->{"HTTP_X_FORWARDED_PROTO"}B= $_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"}
| |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||
| 174 | sub scheme { | ||||||||||||||||||||||||||||||||||||||||
| 175 | 213 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
scheme: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 176 | 213 | ▶ | my $scheme = $self->is_behind_proxy | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 177 | ? $self->forwarded_protocol | ||||||||||||||||||||||||||||||||||||||||
| 178 | : ''; | ||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||
| 180 | 213 | ▶ | return $scheme || $self->env->{'psgi.url_scheme'}; | ||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$scheme || $self->env->{'psgi.url_scheme'}
MC/DC100%2/2
$scheme || $self->env->{'psgi.url_scheme'}
$scheme
$self->env->{'psgi.url_scheme'}
Truth table100%3/3
A || B
A= $schemeB= $self->env->{'psgi.url_scheme'}
| |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||
| 183 | 1061 | ▶ | sub serializer { $_[0]->{'serializer'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
serializer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||
| 185 | 1043 | ▶ | sub data { $_[0]->{'data'} ||= $_[0]->deserialize() } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: called CC=2 SCAR=6.9
Pod
documented
Condition100%3/3
$_[0]{"data"} ||= $_[0]->deserialize
MC/DC100%2/2
$_[0]{"data"} ||= $_[0]->deserialize
$_[0]{"data"}
$_[0]->deserialize
Truth table100%3/3
A ||= B
A= $_[0]{"data"}B= $_[0]->deserialize
| |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||
| 187 | sub deserialize { | ||||||||||||||||||||||||||||||||||||||||
| 188 | 981 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
deserialize: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||
| 190 | # don't attempt to deserialize if the form is 'multipart/form-data' | ||||||||||||||||||||||||||||||||||||||||
| 191 | 981 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->content_type and $self->content_type =~ m[^multipart/form-data]i
MC/DC100%2/2
$self->content_type and $self->content_type =~ m[^multipart/form-data]i
$self->content_type
$self->content_type =~ m[^multipart/form-data]i
Truth table100%3/3
A and B
A= $self->content_typeB= $self->content_type =~ m[^multipart/form-data]i
| |||||||||||||||||||||||||||||||||||||||||
| 192 | $self->content_type | ||||||||||||||||||||||||||||||||||||||||
| 193 | && $self->content_type =~ /^multipart\/form-data/i | ||||||||||||||||||||||||||||||||||||||||
| 194 | ) { | ||||||||||||||||||||||||||||||||||||||||
| 195 | 9 | return; | |||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||
| 199 | 972 | ▶ | my $serializer = $self->serializer | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 200 | or return; | ||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||
| 202 | # The latest draft of the RFC does not forbid DELETE to have content, | ||||||||||||||||||||||||||||||||||||||||
| 203 | # rather the behaviour is undefined. Take the most lenient route and | ||||||||||||||||||||||||||||||||||||||||
| 204 | # deserialize any content on delete as well. | ||||||||||||||||||||||||||||||||||||||||
| 205 | return | ||||||||||||||||||||||||||||||||||||||||
| 206 | 116 | ▶ | unless grep { $self->method eq $_ } qw/ PUT POST PATCH DELETE /; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||
| 208 | # try to deserialize | ||||||||||||||||||||||||||||||||||||||||
| 209 | 46 | my $body = $self->body; | |||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||
| 211 | 46 | ▶ | $body && length $body > 0 | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$body and length $body > 0
MC/DC50%1/2
$body and length $body > 0
$body
length $body > 0
Truth table66%2/3
A and B
A= $bodyB= length $body > 0
| |||||||||||||||||||||||||||||||||||||||||
| 212 | or return; | ||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||
| 214 | # Catch serializer fails - which is tricky as Role::Serializer | ||||||||||||||||||||||||||||||||||||||||
| 215 | # wraps the deserializaion in an eval and returns undef. | ||||||||||||||||||||||||||||||||||||||||
| 216 | # We want to generate a 500 error on serialization fail (Ref #794) | ||||||||||||||||||||||||||||||||||||||||
| 217 | # to achieve that, override the log callback so we can catch a signal | ||||||||||||||||||||||||||||||||||||||||
| 218 | # that it failed. This is messy (messes with serializer internals), but | ||||||||||||||||||||||||||||||||||||||||
| 219 | # "works". | ||||||||||||||||||||||||||||||||||||||||
| 220 | 43 | my $serializer_fail; | |||||||||||||||||||||||||||||||||||||||
| 221 | 43 | my $serializer_log_cb = $serializer->log_cb; | |||||||||||||||||||||||||||||||||||||||
| 222 | local $serializer->{log_cb} = sub { | ||||||||||||||||||||||||||||||||||||||||
| 223 | 4 | ▶ | $serializer_fail = $_[1]; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | $serializer_log_cb->(@_); | |||||||||||||||||||||||||||||||||||||||
| 225 | 43 | }; | |||||||||||||||||||||||||||||||||||||||
| 226 | # work-around to resolve a chicken-and-egg issue when instantiating a | ||||||||||||||||||||||||||||||||||||||||
| 227 | # request object; the serializer needs that request object to deserialize | ||||||||||||||||||||||||||||||||||||||||
| 228 | # the body params. | ||||||||||||||||||||||||||||||||||||||||
| 229 | 43 | Scalar::Util::weaken( my $request = $self ); | |||||||||||||||||||||||||||||||||||||||
| 230 | 43 | ▶ | $self->serializer->has_request || $self->serializer->set_request($request); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 231 | 43 | my $data = $serializer->deserialize($body); | |||||||||||||||||||||||||||||||||||||||
| 232 | 43 | ▶ | die $serializer_fail if $serializer_fail; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||
| 234 | # Set _body_params directly rather than using the setter. Deserializiation | ||||||||||||||||||||||||||||||||||||||||
| 235 | # returns characters and skipping the decode op in the setter ensures | ||||||||||||||||||||||||||||||||||||||||
| 236 | # that numerical data "stays" numerical; decoding an SV that is an IV | ||||||||||||||||||||||||||||||||||||||||
| 237 | # converts that to a PVIV. Some serializers are picky (JSON).. | ||||||||||||||||||||||||||||||||||||||||
| 238 | 39 | $self->{_body_params} = $data; | |||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||
| 240 | # Set body parameters (decoded HMV) | ||||||||||||||||||||||||||||||||||||||||
| 241 | 39 | ▶ | $self->{'body_parameters'} = | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 242 | Hash::MultiValue->from_mixed( is_hashref($data) ? %$data : () ); | ||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||
| 244 | 39 | return $data; | |||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | ▶ | sub uri { $_[0]->request_uri } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | ▶ | sub is_head { $_[0]->method eq 'HEAD' } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_head: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 250 | 7 | ▶ | sub is_post { $_[0]->method eq 'POST' } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_post: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 251 | 7 | ▶ | sub is_get { $_[0]->method eq 'GET' } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | ▶ | sub is_put { $_[0]->method eq 'PUT' } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_put: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | sub is_delete { $_[0]->method eq 'DELETE' } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | ▶ | sub is_patch { $_[0]->method eq 'PATCH' } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_patch: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub is_options { $_[0]->method eq 'OPTIONS' } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_options: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||
| 257 | # public interface compat with CGI.pm objects | ||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | ▶ | sub request_method { $_[0]->method } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub input_handle { $_[0]->env->{'psgi.input'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
input_handle: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||
| 261 | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
| 262 | 7 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | return "[#" . $self->id . "] " . $self->method . " " . $self->path; | |||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||
| 266 | sub base { | ||||||||||||||||||||||||||||||||||||||||
| 267 | 41 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
base: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 268 | 41 | my $uri = $self->_common_uri; | |||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||
| 270 | 41 | return $uri->canonical; | |||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||
| 273 | sub _common_uri { | ||||||||||||||||||||||||||||||||||||||||
| 274 | 195 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_common_uri: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||
| 276 | 195 | my $path = $self->env->{SCRIPT_NAME}; | |||||||||||||||||||||||||||||||||||||||
| 277 | 195 | my $port = $self->env->{SERVER_PORT}; | |||||||||||||||||||||||||||||||||||||||
| 278 | 195 | my $server = $self->env->{SERVER_NAME}; | |||||||||||||||||||||||||||||||||||||||
| 279 | 195 | my $host = $self->host; | |||||||||||||||||||||||||||||||||||||||
| 280 | 195 | my $scheme = $self->scheme; | |||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||
| 282 | 195 | my $uri = URI->new; | |||||||||||||||||||||||||||||||||||||||
| 283 | 195 | $uri->scheme($scheme); | |||||||||||||||||||||||||||||||||||||||
| 284 | 195 | ▶ | $uri->authority( $host || "$server:$port" ); | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$host || "${server}:$port"
MC/DC100%1/1
$host || "${server}:$port"
$host
Truth table100%2/2
A
A= $host
| |||||||||||||||||||||||||||||||||||||||||
| 285 | 195 | ▶ | $uri->path( $path || '/' ); | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$path || '/'
MC/DC100%1/1
$path || '/'
$path
Truth table100%2/2
A
A= $path
| |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||
| 287 | 195 | return $uri; | |||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||
| 290 | sub uri_base { | ||||||||||||||||||||||||||||||||||||||||
| 291 | 154 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri_base: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 292 | 154 | my $uri = $self->_common_uri; | |||||||||||||||||||||||||||||||||||||||
| 293 | 154 | my $canon = $uri->canonical; | |||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||
| 295 | 154 | ▶ | if ( $uri->path eq '/' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 296 | 142 | $canon =~ s{/$}{}; | |||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||
| 299 | 154 | return $canon; | |||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||
| 302 | sub path { | ||||||||||||||||||||||||||||||||||||||||
| 303 | 2166 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
path: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 304 | 2166 | ▶ | my $path = $self->env->{PATH_INFO} || '/'; | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->env->{'PATH_INFO'} || '/'
MC/DC100%1/1
$self->env->{'PATH_INFO'} || '/'
$self->env->{'PATH_INFO'}
Truth table100%2/2
A
A= $self->env->{'PATH_INFO'}
| |||||||||||||||||||||||||||||||||||||||||
| 305 | 2166 | return $self->_decode_bytes( $path, 'PATH_INFO' ); | |||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||
| 308 | sub dispatch_path { | ||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | Carp::croak q{DEPRECATED: request->dispatch_path. Please use request->path instead}; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
dispatch_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||
| 312 | sub uri_for { | ||||||||||||||||||||||||||||||||||||||||
| 313 | 32 | ▶ | my ( $self, $part, $params, $dont_escape ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri_for: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||
| 315 | 32 | ▶ | $part ||= ''; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$part ||= ""
MC/DC0%0/1
$part ||= ""
$part
Truth table50%1/2
A
A= $part
| |||||||||||||||||||||||||||||||||||||||||
| 316 | 32 | my $uri = $self->base; | |||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||
| 318 | # Make sure there's exactly one slash between the base and the new part | ||||||||||||||||||||||||||||||||||||||||
| 319 | 32 | my $base = $uri->path; | |||||||||||||||||||||||||||||||||||||||
| 320 | 32 | $base =~ s|/$||; | |||||||||||||||||||||||||||||||||||||||
| 321 | 32 | $part =~ s|^/||; | |||||||||||||||||||||||||||||||||||||||
| 322 | 32 | $uri->path("$base/$part"); | |||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||
| 324 | 32 | ▶ | $uri->query_form($params) if $params; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||
| 326 | return $dont_escape | ||||||||||||||||||||||||||||||||||||||||
| 327 | 3 | ? uri_unescape( ${ $uri->canonical } ) | |||||||||||||||||||||||||||||||||||||||
| 328 | 32 | ▶ | : ${ $uri->canonical }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||
| 331 | sub uri_for_route { | ||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | my ( $self, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri_for_route: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | is_coderef( $self->{'uri_for_route'} ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 335 | or die 'uri_for_route called on a request instance without it'; | ||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return $self->{'uri_for_route'}->(@_); | |||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||
| 340 | sub params { | ||||||||||||||||||||||||||||||||||||||||
| 341 | 333 | ▶ | my ( $self, $source ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
params: called CC=12 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||
| 343 | 333 | ▶ | return %{ $self->_params } if wantarray && @_ == 1; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
wantarray and @_ == 1
MC/DC50%1/2
wantarray and @_ == 1
wantarray
@_ == 1
Truth table66%2/3
A and B
A= wantarrayB= @_ == 1
| |||||||||||||||||||||||||||||||||||||||||
| 344 | 303 | ▶ | return $self->_params if @_ == 1; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||
| 346 | 25 | ▶ | if ( $source eq 'query' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 347 | 6 | ▶ | return %{ $self->_query_params || {} } if wantarray; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 348 | 6 | return $self->_query_params; | |||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||
| 350 | elsif ( $source eq 'body' ) { | ||||||||||||||||||||||||||||||||||||||||
| 351 | 16 | ▶ | return %{ $self->_body_params || {} } if wantarray; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 352 | 16 | return $self->_body_params; | |||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | ▶ | if ( $source eq 'route' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | return %{ $self->_route_params } if wantarray; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | return $self->_route_params; | |||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||
| 358 | else { | ||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | croak "Unknown source params \"$source\"."; | |||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||
| 363 | sub query_parameters { | ||||||||||||||||||||||||||||||||||||||||
| 364 | 75 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_parameters: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 365 | 75 | ▶ | $self->{'query_parameters'} ||= do { | ||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"query_parameters"} ||= do {
if ($Dancer2::Core::Request::XS_PARSE_QUERY_STRING) {
my $query = $self->_decode(CGI::Deurl::XS::parse_query_string($self->env->{"QUERY_STRING"}), "query parameters");
"Hash::MultiValue"->new(map({my $key = $_;
is_arrayref($query->{$key}) ? map(($key, $_), @{$$query{$key};}) : ($key, $query->{$key});} keys %{$query;}));
}
else {
$self->_decode($self->SUPER::query_parameters, "query parameters");
}
}
MC/DC0%0/2
$self->{"query_parameters"} ||= do {
if ($Dancer2::Core::Request::XS_PARSE_QUERY_STRING) {
my $query = $self->_decode(CGI::Deurl::XS::parse_query_string($self->env->{"QUERY_STRING"}), "query parameters");
"Hash::MultiValue"->new(map({my $key = $_;
is_arrayref($query->{$key}) ? map(($key, $_), @{$$query{$key};}) : ($key, $query->{$key});} keys %{$query;}));
}
else {
$self->_decode($self->SUPER::query_parameters, "query parameters");
}
}
$self->{"query_parameters"}
do {
if ($Dancer2::Core::Request::XS_PARSE_QUERY_STRING) {
my $query = $self->_decode(CGI::Deurl::XS::parse_query_string($self->env->{"QUERY_STRING"}), "query parameters");
"Hash::MultiValue"->new(map({my $key = $_;
is_arrayref($query->{$key}) ? map(($key, $_), @{$$query{$key};}) : ($key, $query->{$key});} keys %{$query;}));
}
else {
$self->_decode($self->SUPER::query_parameters, "query parameters");
}
}
Truth table66%2/3
A ||= B
A= $self->{"query_parameters"}B= do {
if ($Dancer2::Core::Request::XS_PARSE_QUERY_STRING) {
my $query = $self->_decode(CGI::Deurl::XS::parse_query_string($self->env->{"QUERY_STRING"}), "query parameters");
"Hash::MultiValue"->new(map({my $key = $_;
is_arrayref($query->{$key}) ? map(($key, $_), @{$$query{$key};}) : ($key, $query->{$key});} keys %{$query;}));
}
else {
$self->_decode($self->SUPER::query_parameters, "query parameters");
}
}
| |||||||||||||||||||||||||||||||||||||||||
| 366 | 61 | ▶ | if ($XS_PARSE_QUERY_STRING) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 367 | my $query = $self->_decode(CGI::Deurl::XS::parse_query_string( | ||||||||||||||||||||||||||||||||||||||||
| 368 | 57 | $self->env->{'QUERY_STRING'} | |||||||||||||||||||||||||||||||||||||||
| 369 | ), 'query parameters'); | ||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||
| 371 | Hash::MultiValue->new( | ||||||||||||||||||||||||||||||||||||||||
| 372 | map {; | ||||||||||||||||||||||||||||||||||||||||
| 373 | 20 | my $key = $_; | |||||||||||||||||||||||||||||||||||||||
| 374 | is_arrayref( $query->{$key} ) | ||||||||||||||||||||||||||||||||||||||||
| 375 | 3 | ? ( map +( $key => $_ ), @{ $query->{$key} } ) | |||||||||||||||||||||||||||||||||||||||
| 376 | 20 | ▶ | : ( $key => $query->{$key} ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 377 | 57 | } keys %{$query} | |||||||||||||||||||||||||||||||||||||||
| 378 | ); | ||||||||||||||||||||||||||||||||||||||||
| 379 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 380 | # defer to Plack::Request | ||||||||||||||||||||||||||||||||||||||||
| 381 | 4 | $self->_decode($self->SUPER::query_parameters, 'query parameters'); | |||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||
| 383 | }; | ||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||
| 386 | # this will be filled once the route is matched | ||||||||||||||||||||||||||||||||||||||||
| 387 | 21 | ▶ | sub route_parameters { $_[0]->{'route_parameters'} ||= Hash::MultiValue->new } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
route_parameters: called CC=2 SCAR=9.2
Pod
undocumented
Condition33%1/3
$_[0]{"route_parameters"} ||= "Hash::MultiValue"->new
MC/DC0%0/2
$_[0]{"route_parameters"} ||= "Hash::MultiValue"->new
$_[0]{"route_parameters"}
"Hash::MultiValue"->new
Truth table33%1/3
A ||= B
A= $_[0]{"route_parameters"}B= "Hash::MultiValue"->new
| |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||
| 389 | sub _set_route_parameters { | ||||||||||||||||||||||||||||||||||||||||
| 390 | 744 | ▶ | my ( $self, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_route_parameters: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 391 | # remove reserved splat parameter name | ||||||||||||||||||||||||||||||||||||||||
| 392 | # you should access splat parameters using splat() keyword | ||||||||||||||||||||||||||||||||||||||||
| 393 | 744 | delete @{$params}{qw<splat captures>}; | |||||||||||||||||||||||||||||||||||||||
| 394 | $self->{'route_parameters'} = Hash::MultiValue->from_mixed( | ||||||||||||||||||||||||||||||||||||||||
| 395 | 744 | %{ $self->_decode( $params, 'route parameters' ) } | |||||||||||||||||||||||||||||||||||||||
| 396 | ); | ||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||
| 399 | sub body_parameters { | ||||||||||||||||||||||||||||||||||||||||
| 400 | 960 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_parameters: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 401 | # defer to (the overridden) Plack::Request->body_parameters | ||||||||||||||||||||||||||||||||||||||||
| 402 | 960 | ▶ | $self->{'body_parameters'} ||= $self->_decode( | ||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"body_parameters"} ||= $self->_decode($self->SUPER::body_parameters, "body parameters")
MC/DC0%0/2
$self->{"body_parameters"} ||= $self->_decode($self->SUPER::body_parameters, "body parameters")
$self->{"body_parameters"}
$self->_decode($self->SUPER::body_parameters, "body parameters")
Truth table66%2/3
A ||= B
A= $self->{"body_parameters"}B= $self->_decode($self->SUPER::body_parameters, "body parameters")
| |||||||||||||||||||||||||||||||||||||||||
| 403 | $self->SUPER::body_parameters(), | ||||||||||||||||||||||||||||||||||||||||
| 404 | 'body parameters', | ||||||||||||||||||||||||||||||||||||||||
| 405 | ); | ||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||
| 408 | sub parameters { | ||||||||||||||||||||||||||||||||||||||||
| 409 | 6 | ▶ | my ( $self, $type ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
parameters: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||
| 411 | # handle a specific case | ||||||||||||||||||||||||||||||||||||||||
| 412 | 6 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $attr = "${type}_parameters"; | |||||||||||||||||||||||||||||||||||||||
| 414 | 0 | return $self->$attr; | |||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||
| 417 | # merge together the *decoded* parameters | ||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | ▶ | $self->{'merged_parameters'} ||= do { | ||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"merged_parameters"} ||= do {
my $query = $self->query_parameters;
my $body = $self->body_parameters;
my $route = $self->route_parameters;
"Hash::MultiValue"->new(map($_->flatten, $query, $body, $route))
}
MC/DC0%0/2
$self->{"merged_parameters"} ||= do {
my $query = $self->query_parameters;
my $body = $self->body_parameters;
my $route = $self->route_parameters;
"Hash::MultiValue"->new(map($_->flatten, $query, $body, $route))
}
$self->{"merged_parameters"}
do {
my $query = $self->query_parameters;
my $body = $self->body_parameters;
my $route = $self->route_parameters;
"Hash::MultiValue"->new(map($_->flatten, $query, $body, $route))
}
Truth table66%2/3
A ||= B
A= $self->{"merged_parameters"}B= do {
my $query = $self->query_parameters;
my $body = $self->body_parameters;
my $route = $self->route_parameters;
"Hash::MultiValue"->new(map($_->flatten, $query, $body, $route))
}
| |||||||||||||||||||||||||||||||||||||||||
| 419 | 5 | my $query = $self->query_parameters; | |||||||||||||||||||||||||||||||||||||||
| 420 | 5 | my $body = $self->body_parameters; | |||||||||||||||||||||||||||||||||||||||
| 421 | 5 | my $route = $self->route_parameters; # not in Plack::Request | |||||||||||||||||||||||||||||||||||||||
| 422 | 5 | Hash::MultiValue->new( map $_->flatten, $query, $body, $route ); | |||||||||||||||||||||||||||||||||||||||
| 423 | }; | ||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||
| 426 | 3 | ▶ | sub captures { shift->params->{captures} || {} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
captures: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||
| 428 | 33 | ▶ | sub splat { @{ shift->params->{splat} || [] } } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
splat: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||
| 430 | # XXX: incompatible with Plack::Request | ||||||||||||||||||||||||||||||||||||||||
| 431 | 10 | ▶ | sub param { shift->params->{ $_[0] } } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
param: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||
| 433 | sub _decode { | ||||||||||||||||||||||||||||||||||||||||
| 434 | 25261 | ▶ | my ( $self, $h, $context ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||
| 435 | 25261 | ▶ | return if not defined $h; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||
| 437 | 25212 | ▶ | if ( !is_ref($h) && !utf8::is_utf8($h) ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
is_ref($h) || utf8::is_utf8($h)
MC/DC100%2/2
is_ref($h) || utf8::is_utf8($h)
is_ref($h)
utf8::is_utf8($h)
Truth table100%3/3
A || B
A= is_ref($h)B= utf8::is_utf8($h)
| |||||||||||||||||||||||||||||||||||||||||
| 438 | 21774 | return $self->_decode_bytes( $h, $context ); | |||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||
| 440 | elsif ( ref($h) eq 'Hash::MultiValue' ) { | ||||||||||||||||||||||||||||||||||||||||
| 441 | 877 | return Hash::MultiValue->from_mixed( | |||||||||||||||||||||||||||||||||||||||
| 442 | $self->_decode( $h->as_hashref_mixed, $context ) | ||||||||||||||||||||||||||||||||||||||||
| 443 | ); | ||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||
| 445 | elsif ( is_hashref($h) ) { | ||||||||||||||||||||||||||||||||||||||||
| 446 | 2429 | return { map scalar $self->_decode( $_, $context ), %{$h} }; | |||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||
| 448 | elsif ( is_arrayref($h) ) { | ||||||||||||||||||||||||||||||||||||||||
| 449 | 122 | return [ map $self->_decode( $_, $context ), @{$h} ]; | |||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||
| 452 | 10 | return $h; | |||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||
| 455 | sub _decode_bytes { | ||||||||||||||||||||||||||||||||||||||||
| 456 | 23940 | ▶ | my ( $self, $bytes, $context ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_bytes: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||
| 458 | # If PSGI already gave us characters, avoid re-decoding. | ||||||||||||||||||||||||||||||||||||||||
| 459 | 23940 | ▶ | return $bytes if utf8::is_utf8($bytes); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 460 | 23940 | ▶ | return $bytes if $bytes !~ /[\x80-\xFF]/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||
| 462 | 39 | ▶ | return __decode($bytes) if __valid($bytes); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 463 | 5 | return $self->_invalid_utf8( $bytes, $context ); | |||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||
| 466 | sub _invalid_utf8 { | ||||||||||||||||||||||||||||||||||||||||
| 467 | 5 | ▶ | my ( $self, $bytes, $context ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_invalid_utf8: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||
| 468 | 5 | my $strict = $self->{_strict_utf8}; | |||||||||||||||||||||||||||||||||||||||
| 469 | 5 | ▶ | my $where = $context || 'input'; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$context || 'input'
MC/DC0%0/1
$context || 'input'
$context
Truth table50%1/2
A
A= $context
| |||||||||||||||||||||||||||||||||||||||||
| 470 | 5 | my $msg = "Invalid UTF-8 in $where"; | |||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||
| 472 | 5 | ▶ | $strict | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 473 | and Carp::croak($msg); | ||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | ▶ | if ( my $logger = $self->env->{'psgix.logger'} ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | $logger->({ | |||||||||||||||||||||||||||||||||||||||
| 477 | level => 'warning', | ||||||||||||||||||||||||||||||||||||||||
| 478 | message => "$msg; leaving bytes unchanged", | ||||||||||||||||||||||||||||||||||||||||
| 479 | }); | ||||||||||||||||||||||||||||||||||||||||
| 480 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 481 | 2 | Carp::carp("$msg; leaving bytes unchanged"); | |||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||
| 484 | 3 | return $bytes; | |||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||
| 487 | sub is_ajax { | ||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ajax: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | return 0 unless defined $self->headers; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | return 0 unless defined $self->header('X-Requested-With'); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | return 0 if $self->header('X-Requested-With') ne 'XMLHttpRequest'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||
| 496 | # XXX incompatible with Plack::Request | ||||||||||||||||||||||||||||||||||||||||
| 497 | # context-aware accessor for uploads | ||||||||||||||||||||||||||||||||||||||||
| 498 | sub upload { | ||||||||||||||||||||||||||||||||||||||||
| 499 | 21 | ▶ | my ( $self, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 500 | 21 | my $res = $self->{uploads}{$name}; | |||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||
| 502 | 21 | ▶ | return $res unless wantarray; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 503 | 9 | ▶ | return () unless defined $res; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 504 | 6 | ▶ | return ( is_arrayref($res) ) ? @$res : $res; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||
| 507 | sub _build_params { | ||||||||||||||||||||||||||||||||||||||||
| 508 | 781 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_params: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||
| 510 | # params may have been populated by before filters | ||||||||||||||||||||||||||||||||||||||||
| 511 | # _before_ we get there, so we have to save it first | ||||||||||||||||||||||||||||||||||||||||
| 512 | 781 | ▶ | my $previous = $self->_has_params ? $self->_params : {}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||
| 514 | # now parse environment params... | ||||||||||||||||||||||||||||||||||||||||
| 515 | 781 | my $get_params = $self->_parse_get_params(); | |||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||
| 517 | # and merge everything | ||||||||||||||||||||||||||||||||||||||||
| 518 | $self->{_params} = { | ||||||||||||||||||||||||||||||||||||||||
| 519 | 780 | ▶ | map +( is_hashref($_) ? %{$_} : () ), | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 520 | $previous, | ||||||||||||||||||||||||||||||||||||||||
| 521 | $get_params, | ||||||||||||||||||||||||||||||||||||||||
| 522 | $self->_body_params, | ||||||||||||||||||||||||||||||||||||||||
| 523 | $self->_route_params, | ||||||||||||||||||||||||||||||||||||||||
| 524 | }; | ||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||
| 528 | sub _url_decode { | ||||||||||||||||||||||||||||||||||||||||
| 529 | 76 | ▶ | my ( $self, $encoded ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_url_decode: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 530 | 76 | ▶ | return URL::Encode::XS::url_decode($encoded) if $XS_URL_DECODE; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 531 | 44 | my $clean = $encoded; | |||||||||||||||||||||||||||||||||||||||
| 532 | 44 | $clean =~ tr/\+/ /; | |||||||||||||||||||||||||||||||||||||||
| 533 | 44 | $clean =~ s/%([a-fA-F0-9]{2})/pack "H2", $1/eg; | |||||||||||||||||||||||||||||||||||||||
| 534 | 44 | return $clean; | |||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||
| 537 | sub _parse_get_params { | ||||||||||||||||||||||||||||||||||||||||
| 538 | 781 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_get_params: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||
| 539 | 781 | ▶ | return $self->_query_params if defined $self->{_query_params}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||
| 541 | 731 | my $query_params = {}; | |||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||
| 543 | 731 | my $source = $self->env->{QUERY_STRING}; | |||||||||||||||||||||||||||||||||||||||
| 544 | 731 | ▶ | return if !defined $source || $source eq ''; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $source or $source eq ""
MC/DC100%2/2
not defined $source or $source eq ""
not defined $source
$source eq ""
Truth table100%3/3
not(A) or B
A= not defined $sourceB= $source eq ""
| |||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||
| 546 | 46 | ▶ | if ($XS_PARSE_QUERY_STRING) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 547 | 35 | ▶ | $self->_set_query_params( | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
CGI::Deurl::XS::parse_query_string($source) || {}
MC/DC0%0/1
CGI::Deurl::XS::parse_query_string($source) || {}
CGI::Deurl::XS::parse_query_string($source)
Truth table50%1/2
A
A= CGI::Deurl::XS::parse_query_string($source)
| |||||||||||||||||||||||||||||||||||||||||
| 548 | CGI::Deurl::XS::parse_query_string($source) || {} | ||||||||||||||||||||||||||||||||||||||||
| 549 | ); | ||||||||||||||||||||||||||||||||||||||||
| 550 | 34 | return $self->_query_params; | |||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||
| 553 | 11 | foreach my $token ( split /[&;]/, $source ) { | |||||||||||||||||||||||||||||||||||||||
| 554 | 38 | my ( $key, $val ) = split( /=/, $token ); | |||||||||||||||||||||||||||||||||||||||
| 555 | 38 | ▶ | next unless defined $key; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 556 | 38 | ▶ | $val = ( defined $val ) ? $val : ''; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 557 | 38 | $key = $self->_url_decode($key); | |||||||||||||||||||||||||||||||||||||||
| 558 | 38 | $val = $self->_url_decode($val); | |||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||
| 560 | # looking for multi-value params | ||||||||||||||||||||||||||||||||||||||||
| 561 | 38 | ▶ | if ( exists $query_params->{$key} ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 562 | 7 | my $prev_val = $query_params->{$key}; | |||||||||||||||||||||||||||||||||||||||
| 563 | 7 | ▶ | if ( is_arrayref($prev_val) ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 564 | 2 | push @{ $query_params->{$key} }, $val; | |||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||
| 566 | else { | ||||||||||||||||||||||||||||||||||||||||
| 567 | 5 | $query_params->{$key} = [ $prev_val, $val ]; | |||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||
| 571 | # simple value param (first time we see it) | ||||||||||||||||||||||||||||||||||||||||
| 572 | else { | ||||||||||||||||||||||||||||||||||||||||
| 573 | 31 | $query_params->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||
| 576 | 11 | $self->_set_query_params( $query_params ); | |||||||||||||||||||||||||||||||||||||||
| 577 | 11 | return $self->_query_params; | |||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||
| 580 | sub _build_uploads { | ||||||||||||||||||||||||||||||||||||||||
| 581 | 973 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_uploads: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||
| 583 | # parse body and build body params | ||||||||||||||||||||||||||||||||||||||||
| 584 | 973 | my $body_params = $self->_body_params; | |||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||
| 586 | 972 | my $uploads = $self->SUPER::uploads; | |||||||||||||||||||||||||||||||||||||||
| 587 | 972 | my %uploads; | |||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||
| 589 | 972 | for my $name ( keys %$uploads ) { | |||||||||||||||||||||||||||||||||||||||
| 590 | my @uploads = map Dancer2::Core::Request::Upload->new( | ||||||||||||||||||||||||||||||||||||||||
| 591 | # For back-compatibility, we use a HashRef of headers | ||||||||||||||||||||||||||||||||||||||||
| 592 | 22 | headers => {@{$_->{headers}->psgi_flatten_without_sort}}, | |||||||||||||||||||||||||||||||||||||||
| 593 | tempname => $_->{tempname}, | ||||||||||||||||||||||||||||||||||||||||
| 594 | size => $_->{size}, | ||||||||||||||||||||||||||||||||||||||||
| 595 | 16 | filename => $self->_decode( $_->{filename}, 'upload filename' ), | |||||||||||||||||||||||||||||||||||||||
| 596 | ), $uploads->get_all($name); | ||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||
| 598 | 16 | ▶ | $uploads{$name} = @uploads > 1 ? \@uploads : $uploads[0]; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||
| 600 | # support access to the filename as a normal param | ||||||||||||||||||||||||||||||||||||||||
| 601 | 16 | my @filenames = map $_->{'filename'}, @uploads; | |||||||||||||||||||||||||||||||||||||||
| 602 | 16 | ▶ | $self->{_body_params}{$name} = | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 603 | @filenames > 1 ? \@filenames : $filenames[0]; | ||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||
| 606 | 972 | $self->{uploads} = \%uploads; | |||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||
| 609 | # XXX: incompatible with Plack::Request | ||||||||||||||||||||||||||||||||||||||||
| 610 | 757 | ▶ | sub cookies { $_[0]->{'cookies'} ||= $_[0]->_build_cookies } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
cookies: called CC=2 SCAR=7.2
Pod
documented
Condition66%2/3
$_[0]{"cookies"} ||= $_[0]->_build_cookies
MC/DC0%0/2
$_[0]{"cookies"} ||= $_[0]->_build_cookies
$_[0]{"cookies"}
$_[0]->_build_cookies
Truth table66%2/3
A ||= B
A= $_[0]{"cookies"}B= $_[0]->_build_cookies
| |||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||
| 612 | sub _build_cookies { | ||||||||||||||||||||||||||||||||||||||||
| 613 | 640 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_cookies: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||
| 614 | 640 | my $cookies = {}; | |||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||
| 616 | 640 | my $http_cookie = $self->header('Cookie'); | |||||||||||||||||||||||||||||||||||||||
| 617 | 640 | ▶ | return $cookies unless defined $http_cookie; # nothing to do | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||
| 619 | 70 | ▶ | if ( $XS_HTTP_COOKIES ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | $cookies = HTTP::XSCookies::crush_cookie($http_cookie); | |||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||
| 622 | else { | ||||||||||||||||||||||||||||||||||||||||
| 623 | # handle via Plack::Request | ||||||||||||||||||||||||||||||||||||||||
| 624 | 70 | $cookies = $self->SUPER::cookies(); | |||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||
| 627 | # convert to objects | ||||||||||||||||||||||||||||||||||||||||
| 628 | 70 | ▶ | while (my ($name, $value) = each %{$cookies}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 629 | 73 | ▶ | $cookies->{$name} = Dancer2::Core::Cookie->new( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 630 | name => $name, | ||||||||||||||||||||||||||||||||||||||||
| 631 | # HTTP::XSCookies v0.17+ will do the split and return an arrayref | ||||||||||||||||||||||||||||||||||||||||
| 632 | value => is_arrayref($value) ? $value : [split '&', $value ] | ||||||||||||||||||||||||||||||||||||||||
| 633 | ); | ||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||
| 635 | 70 | return $cookies; | |||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||
| 638 | # poor man's clone | ||||||||||||||||||||||||||||||||||||||||
| 639 | sub _shallow_clone { | ||||||||||||||||||||||||||||||||||||||||
| 640 | 60 | ▶ | my ($self, $params, $options) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shallow_clone: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||
| 642 | # shallow clone $env; we don't want to alter the existing one | ||||||||||||||||||||||||||||||||||||||||
| 643 | # in $self, then merge any overridden values | ||||||||||||||||||||||||||||||||||||||||
| 644 | 60 | ▶ | my $env = { %{ $self->env }, %{ $options || {} } }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||
| 646 | 60 | my $new_request = __PACKAGE__->new( | |||||||||||||||||||||||||||||||||||||||
| 647 | env => $env, | ||||||||||||||||||||||||||||||||||||||||
| 648 | body_params => {}, | ||||||||||||||||||||||||||||||||||||||||
| 649 | ); | ||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||
| 651 | # Clone and merge query params | ||||||||||||||||||||||||||||||||||||||||
| 652 | 60 | my $new_params = $self->params; | |||||||||||||||||||||||||||||||||||||||
| 653 | 60 | ▶ | $new_request->{_query_params} = { %{ $self->{_query_params} || {} } }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 654 | 60 | $new_request->{_strict_utf8} = $self->{_strict_utf8}; | |||||||||||||||||||||||||||||||||||||||
| 655 | 60 | $new_request->{query_parameters} = $self->query_parameters->clone; | |||||||||||||||||||||||||||||||||||||||
| 656 | 60 | ▶ | for my $key ( keys %{ $params || {} } ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 657 | 12 | my $value = $params->{$key}; | |||||||||||||||||||||||||||||||||||||||
| 658 | 12 | $new_params->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||
| 659 | 12 | $new_request->{_query_params}->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||
| 660 | 12 | $new_request->{query_parameters}->add( $key => $value ); | |||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||
| 663 | # Copy params (these are already decoded) | ||||||||||||||||||||||||||||||||||||||||
| 664 | 60 | $new_request->{_params} = $new_params; | |||||||||||||||||||||||||||||||||||||||
| 665 | 60 | $new_request->{_body_params} = $self->{_body_params}; | |||||||||||||||||||||||||||||||||||||||
| 666 | 60 | $new_request->{_route_params} = $self->{_route_params}; | |||||||||||||||||||||||||||||||||||||||
| 667 | 60 | $new_request->{headers} = $self->headers; | |||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||
| 669 | # Copy remaining settings | ||||||||||||||||||||||||||||||||||||||||
| 670 | 60 | $new_request->{is_behind_proxy} = $self->{is_behind_proxy}; | |||||||||||||||||||||||||||||||||||||||
| 671 | 60 | $new_request->{vars} = $self->{vars}; | |||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||
| 673 | # Clone any existing decoded & cached body params. (GH#1116 GH#1269) | ||||||||||||||||||||||||||||||||||||||||
| 674 | 60 | $new_request->{'body_parameters'} = $self->body_parameters->clone; | |||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||
| 676 | # Delete merged HMV parameters, allowing them to be reconstructed on first use. | ||||||||||||||||||||||||||||||||||||||||
| 677 | 60 | delete $new_request->{'merged_parameters'}; | |||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||
| 679 | 60 | return $new_request; | |||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||
| 683 | sub _set_route { | ||||||||||||||||||||||||||||||||||||||||
| 684 | 742 | ▶ | my ( $self, $route ) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_route: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 685 | 742 | $self->{'route'} = $route; | |||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||
| 688 | 6 | ▶ | sub route { $_[0]->{'route'} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
route: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||
| 690 | sub body_data { | ||||||||||||||||||||||||||||||||||||||||
| 691 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_data: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 692 | 2 | ▶ | return $self->data if $self->serializer; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 693 | 1 | $self->_body_params; | |||||||||||||||||||||||||||||||||||||||
| 694 | 1 | ▶ | return $self->{_body_params} if keys %{ $self->{_body_params} }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 695 | 1 | return $self->body; | |||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||
| 698 | 187 | 1; | |||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||
| 700 | __END__ | ||||||||||||||||||||||||||||||||||||||||