lib/Dancer/Request.pm

filter: Statementstmt 95.5% 344 / 360 Branchbran 78.8% 112 / 142 Conditioncond 81.1% 73 / 90 MC/DCmcdc 58.7% 27 / 46 Subroutinesub 97.1% 69 / 71 Podpod 100% 37 / 37 totaltotal 88.7% 662 / 746 CC 112 SCAR 17.3
CC
112
Cov
89%
params
13.5
scheme
10.1
new_for_request
10.0
CRAP 5.7
« lib/Dancer/Renderer.pm ↑ Summary lib/Dancer/Cookie.pm »
1 package Dancer::Request;
2 207 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: interface for accessing incoming requests
4 207 $Dancer::Request::VERSION = '1.3522';
5 207 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 207 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 207 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 207 ▶use base 'Dancer::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 207 ▶use Dancer::Config 'setting';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 207 ▶use Dancer::Request::Upload;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 207 ▶use Dancer::SharedData;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 207 ▶use Dancer::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 207 ▶use Dancer::Exception qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 207 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 207 ▶use HTTP::Body;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 207 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 207 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 207 my @http_env_keys = (
22 'user_agent', 'accept_language', 'accept_charset',
23 'accept_encoding', 'keep_alive', 'connection', 'accept',
24 'accept_type', 'referer', #'host', managed manually
25 );
26 207 my $count = 0;
27  
28 207 __PACKAGE__->attributes(
29  
30 # query
31 'env', 'path', 'method',
32 'content_type', 'content_length',
33 'id',
34 'uploads', 'headers', 'path_info',
35 'ajax', 'is_forward',
36 @http_env_keys,
37 );
38  
39 615 ▶sub new {
Subroutine new: called CC=2 SCAR=8.4
Pod documented
40 615 my ($self, @args) = @_;
41 615 ▶ if (@args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1) 0 615 615
42 0 @args = ('env' => $args[0]);
43 0 Dancer::Deprecation->deprecated(
44 fatal => 1,
45 feature => 'Calling Dancer::Request->new($env)',
46 version => 1.3059,
47 reason => 'Please use Dancer::Request->new( env => $env ) instead',
48 );
49 }
50 615 $self->SUPER::new(@args);
51 }
52  
53 # aliases
54 1 ▶sub agent { $_[0]->user_agent }
Subroutine agent: called CC=1 SCAR=0.0
Pod documented
55 21 ▶sub remote_address { $_[0]->address }
Subroutine remote_address: called CC=1 SCAR=0.0
Pod documented
56 1 ▶sub forwarded_for_address { $_[0]->env->{'X_FORWARDED_FOR'} || $_[0]->env->{'HTTP_X_FORWARDED_FOR'} }
Subroutine forwarded_for_address: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->env->{"X_FORWARDED_FOR"} or $_[0]->env->{"HTTP_X_FORWARDED_FOR"} 1 0 1
57 21 ▶sub address {
Subroutine address: called CC=2 SCAR=7.6
Pod documented
58 setting('behind_proxy')
59 ? $_[0]->forwarded_for_address()
60 : $_[0]->env->{REMOTE_ADDR}
61 21 ▶}
Branch: 1 branch
BranchTrueFalseTotal
setting('behind_proxy') ? : 0 21 21
62 34 ▶sub host {
Subroutine host: called CC=6 SCAR=18.7
Pod documented
63 34 ▶ if (@_==2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 0 34 34
64 0 $_[0]->{host} = $_[1];
65 } else {
66 34 my $host;
67 34 ▶ $host = ($_[0]->env->{X_FORWARDED_HOST} || $_[0]->env->{HTTP_X_FORWARDED_HOST}) if setting('behind_proxy');
Branch: 1 branch
BranchTrueFalseTotal
if setting("behind_proxy") 5 29 34
Condition33%1/3
$_[0]->env->{'X_FORWARDED_HOST'} || $_[0]->env->{'HTTP_X_FORWARDED_HOST'}
l!l&&r!l&&!r
500
MC/DC0%0/2
$_[0]->env->{'X_FORWARDED_HOST'} || $_[0]->env->{'HTTP_X_FORWARDED_HOST'}
$_[0]->env->{'X_FORWARDED_HOST'} $_[0]->env->{'HTTP_X_FORWARDED_HOST'}
Truth table33%1/3
A || B
A= $_[0]->env->{'X_FORWARDED_HOST'}B= $_[0]->env->{'HTTP_X_FORWARDED_HOST'}
ABresult
1X1
011
000
68 34 ▶ $host || $_[0]->{host} || $_[0]->env->{HTTP_HOST};
Branch: 1 branch
BranchTrueFalseTotal
$host or $_[0]{"host"} or $_[0]->env->{"HTTP_HOST"} 22 12 34
Condition100%3/3
$host or $_[0]{"host"}
l!l&&r!l&&!r
51712
MC/DC100%2/2
$host or $_[0]{"host"}
$host $_[0]{"host"}
Truth table100%3/3
A or B
A= $hostB= $_[0]{"host"}
ABresult
1X1
011
000
69 }
70 }
71 0 ▶sub remote_host { $_[0]->env->{REMOTE_HOST} }
Subroutine remote_host: not called CC=1 SCAR=6.9
Pod documented
72 1 ▶sub protocol { $_[0]->env->{SERVER_PROTOCOL} }
Subroutine protocol: called CC=1 SCAR=0.0
Pod documented
73 1 ▶sub port { $_[0]->env->{SERVER_PORT} }
Subroutine port: called CC=1 SCAR=0.0
Pod documented
74 625 ▶sub request_uri { $_[0]->env->{REQUEST_URI} }
Subroutine request_uri: called CC=1 SCAR=0.0
Pod documented
75 1 ▶sub user { $_[0]->env->{REMOTE_USER} }
Subroutine user: called CC=1 SCAR=0.0
Pod documented
76 626 ▶sub script_name { $_[0]->env->{SCRIPT_NAME} }
Subroutine script_name: called CC=1 SCAR=0.0
Pod documented
77 1 ▶sub request_base { $_[0]->env->{REQUEST_BASE} || $_[0]->env->{HTTP_REQUEST_BASE} }
Subroutine request_base: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->env->{"REQUEST_BASE"} or $_[0]->env->{"HTTP_REQUEST_BASE"} 1 0 1
78 33 ▶sub scheme {
Subroutine scheme: called CC=10 SCAR=23.1
Pod documented
79 33 my $scheme;
80 33 ▶ if (setting('behind_proxy')) {
Branch: 1 branch
BranchTrueFalseTotal
if (setting("behind_proxy")) 5 28 33
81 # PSGI specs say that X_FORWARDED_PROTO will
82 # be converted into HTTP_X_FORWARDED_PROTO
83 # but Dancer::Test doesn't use PSGI (for now)
84 $scheme = $_[0]->env->{'HTTP_X_FORWARDED_PROTO'}
85 || $_[0]->env->{'X_FORWARDED_PROTOCOL'}
86 || $_[0]->env->{'HTTP_X_FORWARDED_PROTOCOL'}
87 || $_[0]->env->{'HTTP_FORWARDED_PROTO'}
88 5 ▶ || $_[0]->env->{'X_FORWARDED_PROTO'}
Condition85%12/14
$_[0]->env->{'HTTP_X_FORWARDED_PROTO'} || $_[0]->env->{'X_FORWARDED_PROTOCOL'} || $_[0]->env->{'HTTP_X_FORWARDED_PROTOCOL'} || $_[0]->env->{'HTTP_FORWARDED_PROTO'} || $_[0]->env->{'X_FORWARDED_PROTO'} || ''
l!l
41
$_[0]->env->{"HTTP_X_FORWARDED_PROTO"} or $_[0]->env->{"X_FORWARDED_PROTOCOL"} or $_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"} or $_[0]->env->{"HTTP_FORWARDED_PROTO"} or $_[0]->env->{"X_FORWARDED_PROTO"}
l!l&&r!l&&!r
311
$_[0]->env->{"HTTP_X_FORWARDED_PROTO"} or $_[0]->env->{"X_FORWARDED_PROTOCOL"} or $_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"} or $_[0]->env->{"HTTP_FORWARDED_PROTO"}
l!l&&r!l&&!r
212
$_[0]->env->{"HTTP_X_FORWARDED_PROTO"} or $_[0]->env->{"X_FORWARDED_PROTOCOL"} or $_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"}
l!l&&r!l&&!r
203
$_[0]->env->{"HTTP_X_FORWARDED_PROTO"} or $_[0]->env->{"X_FORWARDED_PROTOCOL"}
l!l&&r!l&&!r
023
MC/DC60%3/5
$_[0]->env->{'HTTP_X_FORWARDED_PROTO'} || $_[0]->env->{'X_FORWARDED_PROTOCOL'} || $_[0]->env->{'HTTP_X_FORWARDED_PROTOCOL'} || $_[0]->env->{'HTTP_FORWARDED_PROTO'} || $_[0]->env->{'X_FORWARDED_PROTO'} || ''
$_[0]->env->{"HTTP_X_FORWARDED_PROTO"} $_[0]->env->{"X_FORWARDED_PROTOCOL"} $_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"} $_[0]->env->{"HTTP_FORWARDED_PROTO"} $_[0]->env->{"X_FORWARDED_PROTO"}
Truth table66%4/6
A or B or C or D or E
A= $_[0]->env->{"HTTP_X_FORWARDED_PROTO"}B= $_[0]->env->{"X_FORWARDED_PROTOCOL"}C= $_[0]->env->{"HTTP_X_FORWARDED_PROTOCOL"}D= $_[0]->env->{"HTTP_FORWARDED_PROTO"}E= $_[0]->env->{"X_FORWARDED_PROTO"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
89 || ""
90 }
91 return $scheme
92 || $_[0]->env->{'psgi.url_scheme'}
93 33 ▶ || $_[0]->env->{'PSGI.URL_SCHEME'}
Condition87%7/8
$scheme || $_[0]->env->{'psgi.url_scheme'} || $_[0]->env->{'PSGI.URL_SCHEME'} || ''
l!l
321
$scheme or $_[0]->env->{"psgi.url_scheme"} or $_[0]->env->{"PSGI.URL_SCHEME"}
l!l&&r!l&&!r
3201
$scheme or $_[0]->env->{"psgi.url_scheme"}
l!l&&r!l&&!r
4281
MC/DC66%2/3
$scheme || $_[0]->env->{'psgi.url_scheme'} || $_[0]->env->{'PSGI.URL_SCHEME'} || ''
$scheme $_[0]->env->{"psgi.url_scheme"} $_[0]->env->{"PSGI.URL_SCHEME"}
Truth table75%3/4
A or B or C
A= $schemeB= $_[0]->env->{"psgi.url_scheme"}C= $_[0]->env->{"PSGI.URL_SCHEME"}
ABCresult
1XX1
01X1
0011
0000
94 || "";
95 }
96 1 ▶sub secure { $_[0]->scheme eq 'https' }
Subroutine secure: called CC=1 SCAR=0.0
Pod documented
97 3 ▶sub uri { $_[0]->request_uri }
Subroutine uri: called CC=1 SCAR=0.0
Pod documented
98  
99 20 ▶sub is_head { $_[0]->{method} eq 'HEAD' }
Subroutine is_head: called CC=1 SCAR=0.0
Pod documented
100 10 ▶sub is_post { $_[0]->{method} eq 'POST' }
Subroutine is_post: called CC=1 SCAR=0.0
Pod documented
101 2 ▶sub is_get { $_[0]->{method} eq 'GET' }
Subroutine is_get: called CC=1 SCAR=0.0
Pod documented
102 15 ▶sub is_put { $_[0]->{method} eq 'PUT' }
Subroutine is_put: called CC=1 SCAR=0.0
Pod documented
103 2 ▶sub is_delete { $_[0]->{method} eq 'DELETE' }
Subroutine is_delete: called CC=1 SCAR=0.0
Pod documented
104 1 ▶sub is_patch { $_[0]->{method} eq 'PATCH' }
Subroutine is_patch: called CC=1 SCAR=0.0
Pod documented
105 7 ▶sub header { $_[0]->{headers}->header($_[1]) }
Subroutine header: called CC=1 SCAR=0.0
Pod documented
106  
107 # We used to store the whole raw unparsed body; this was a big problem for large
108 # file uploads (Issue 1129).
109 # The original fix was to stop doing so, and replace the accessor with one that
110 # would read it out of the temp file returned by HTTP::Body->body - but that
111 # doesn't work for e.g. parsed form submissions, only certain types.
112 # So, back to the older way - we may have a request body squirreled away
113 # in memory if the config included the raw_request_body_in_ram boolean
114 17 ▶sub body { $_[0]->{body} }
Subroutine body: called CC=1 SCAR=0.0
Pod documented
115  
116 # public interface compat with CGI.pm objects
117 1 ▶sub request_method { method(@_) }
Subroutine request_method: called CC=1 SCAR=0.0
Pod documented
118 2 ▶sub Vars { params(@_) }
Subroutine Vars: called CC=1 SCAR=0.0
Pod documented
119 619 ▶sub input_handle { $_[0]->env->{'psgi.input'} || $_[0]->env->{'PSGI.INPUT'} }
Subroutine input_handle: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->env->{"psgi.input"} or $_[0]->env->{"PSGI.INPUT"} 52 567 619
120  
121 615 ▶sub init {
Subroutine init: called CC=9 SCAR=22.1
Pod documented
122 615 my ($self) = @_;
123  
124 615 ▶ $self->{env} ||= {};
Condition50%1/2
$self->{"env"} ||= {}
l!l
6150
MC/DC0%0/1
$self->{"env"} ||= {}
$self->{"env"}
Truth table50%1/2
A
A= $self->{"env"}
Aresult
11
00
125 615 $self->{path} = undef;
126 615 $self->{method} = undef;
127 615 $self->{params} = {};
128 615 ▶ $self->{is_forward} ||= 0;
Condition100%2/2
$self->{"is_forward"} ||= 0
l!l
16599
MC/DC100%1/1
$self->{"is_forward"} ||= 0
$self->{"is_forward"}
Truth table100%2/2
A
A= $self->{"is_forward"}
Aresult
11
00
129 615 ▶ $self->{content_length} = $self->env->{CONTENT_LENGTH} || 0;
Condition100%2/2
$self->env->{'CONTENT_LENGTH'} || 0
l!l
22593
MC/DC100%1/1
$self->env->{'CONTENT_LENGTH'} || 0
$self->env->{'CONTENT_LENGTH'}
Truth table100%2/2
A
A= $self->env->{'CONTENT_LENGTH'}
Aresult
11
00
130 615 ▶ $self->{content_type} = $self->env->{CONTENT_TYPE} || '';
Condition100%2/2
$self->env->{'CONTENT_TYPE'} || ''
l!l
31584
MC/DC100%1/1
$self->env->{'CONTENT_TYPE'} || ''
$self->env->{'CONTENT_TYPE'}
Truth table100%2/2
A
A= $self->env->{'CONTENT_TYPE'}
Aresult
11
00
131 615 $self->{id} = ++$count;
132 615 $self->{_chunk_size} = 4096;
133 615 $self->{_read_position} = 0;
134 615 $self->{_body_params} = undef;
135 615 $self->{_query_params} = undef;
136 615 $self->{_route_params} = {};
137  
138 615 $self->_build_headers();
139 615 $self->_build_request_env();
140 615 ▶ $self->_build_path() unless $self->path;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->path 615 0 615
141 615 ▶ $self->_build_path_info() unless $self->path_info;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->path_info 615 0 615
142 615 ▶ $self->_build_method() unless $self->method;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->method 615 0 615
143  
144 $self->{_http_body}
145 615 = HTTP::Body->new($self->content_type, $self->content_length);
146 615 $self->{_http_body}->cleanup(1);
147 615 $self->{body} = ''; # default, because we might not store it now.
148 615 $self->_build_params();
149 615 ▶ $self->_build_uploads unless $self->uploads;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->uploads 615 0 615
150 615 $self->{ajax} = $self->is_ajax;
151  
152 615 return $self;
153 }
154  
155 1 ▶sub to_string {
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
156 1 my ($self) = @_;
157 1 return "[#" . $self->id . "] " . $self->method . " " . $self->path;
158 }
159  
160 # helper for building a request object by hand
161 # with the given method, path, params, body and headers.
162 571 ▶sub new_for_request {
Subroutine new_for_request: called CC=10 SCAR=23.1
Pod documented
163 571 my ($class, $method, $uri, $params, $body, $headers, $extra_env) = @_;
164 571 ▶ $params ||= {};
Condition100%2/2
$params ||= {}
l!l
13558
MC/DC100%1/1
$params ||= {}
$params
Truth table100%2/2
A
A= $params
Aresult
11
00
165 571 ▶ $extra_env ||= {};
Condition100%2/2
$extra_env ||= {}
l!l
50071
MC/DC100%1/1
$extra_env ||= {}
$extra_env
Truth table100%2/2
A
A= $extra_env
Aresult
11
00
166 571 $method = uc($method);
167  
168 571 my ( $path, $query_string ) = ( $uri =~ /([^?]*)(?:\?(.*))?/s ); #from HTTP::Server::Simple
169  
170 my $env = {
171 %ENV,
172 571 ▶ %{$extra_env},
Condition100%5/5
$query_string || $ENV{'QUERY_STRING'} || ''
l!l
10561
$query_string or $ENV{"QUERY_STRING"}
l!l&&r!l&&!r
82561
MC/DC100%2/2
$query_string || $ENV{'QUERY_STRING'} || ''
$query_string $ENV{"QUERY_STRING"}
Truth table100%3/3
A or B
A= $query_stringB= $ENV{"QUERY_STRING"}
ABresult
1X1
011
000
173 PATH_INFO => $path,
174 571 QUERY_STRING => $query_string || $ENV{QUERY_STRING} || '',
175 REQUEST_METHOD => $method
176 };
177 571 ▶ $env->{CONTENT_LENGTH} = defined($body) ? length($body) : 0 if !exists $env->{CONTENT_LENGTH};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $env->{"CONTENT_LENGTH"} 543 28 571
defined $body ? : 1 542 543
178 571 my $req = $class->new(env => $env);
179 571 $req->{params} = {%{$req->{params}}, %{$params}};
180 571 $req->_build_params();
181 571 $req->{_query_params} = $req->{params};
182 571 my $store_raw_body = setting('raw_request_body_in_ram');
183 571 ▶ $store_raw_body = defined $store_raw_body ? $store_raw_body : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $store_raw_body ? : 0 571 571
184 571 ▶ if ($store_raw_body) {
Branch: 1 branch
BranchTrueFalseTotal
if ($store_raw_body) 571 0 571
185 571 $req->{body} = $body;
186 }
187 571 ▶ $req->{headers} = $headers || HTTP::Headers->new;
Condition66%2/3
$headers || 'HTTP::Headers'->new
l!l&&r!l&&!r
500710
MC/DC0%0/2
$headers || 'HTTP::Headers'->new
$headers 'HTTP::Headers'->new
Truth table66%2/3
A || B
A= $headersB= 'HTTP::Headers'->new
ABresult
1X1
011
000
188  
189 571 return $req;
190 }
191  
192 #Create a new request which is a clone of the current one, apart
193 #from the path location, which points instead to the new location
194 16 ▶sub forward {
Subroutine forward: called CC=8 SCAR=20.9
Pod documented
195 16 my ($class, $request, $to_data) = @_;
196  
197 16 my $env = $request->env;
198 16 $env->{PATH_INFO} = $to_data->{to_url};
199  
200 16 my $new_request = $class->new(env => $env, is_forward => 1);
201 my $new_params = _merge_params(scalar($request->params),
202 16 ▶ $to_data->{params} || {});
Condition100%2/2
$to_data->{'params'} || {}
l!l
412
MC/DC100%1/1
$to_data->{'params'} || {}
$to_data->{'params'}
Truth table100%2/2
A
A= $to_data->{'params'}
Aresult
11
00
203  
204 16 ▶ if (exists($to_data->{options}{method})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $to_data->{"options"}{"method"}) 2 14 16
205 2 ▶ die unless _valid_method($to_data->{options}{method});
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_method($to_data->{"options"}{"method"}) 0 2 2
206 2 $new_request->{method} = uc $to_data->{options}{method};
207 }
208  
209 16 $new_request->{params} = $new_params;
210 16 $new_request->{_body_params} = $request->{_body_params};
211 16 $new_request->{_query_params} = $request->{_query_params};
212 16 $new_request->{_route_params} = $request->{_route_params};
213 16 $new_request->{_params_are_decoded} = 1;
214 16 $new_request->{headers} = $request->headers;
215  
216 16 ▶ if( my $session = Dancer::Session->engine
Branch: 1 branch
BranchTrueFalseTotal
if (my $session = "Dancer::Session"->engine && "Dancer::Session"->get_current_session) 15 1 16
Condition66%2/3
'Dancer::Session'->engine && 'Dancer::Session'->get_current_session
!ll&&!rl&&r
1015
MC/DC50%1/2
'Dancer::Session'->engine && 'Dancer::Session'->get_current_session
'Dancer::Session'->engine 'Dancer::Session'->get_current_session
Truth table66%2/3
A && B
A= 'Dancer::Session'->engineB= 'Dancer::Session'->get_current_session
ABresult
0X0
100
111
217 && Dancer::Session->get_current_session ) {
218 15 my $name = $session->session_name;
219  
220 # make sure that COOKIE is populated
221 15 ▶ $new_request->{env}{COOKIE} ||= $new_request->{env}{HTTP_COOKIE};
Condition33%1/3
$new_request->{"env"}{"COOKIE"} ||= $new_request->{"env"}{"HTTP_COOKIE"}
l!l&&r!l&&!r
0015
MC/DC0%0/2
$new_request->{"env"}{"COOKIE"} ||= $new_request->{"env"}{"HTTP_COOKIE"}
$new_request->{"env"}{"COOKIE"} $new_request->{"env"}{"HTTP_COOKIE"}
Truth table33%1/3
A ||= B
A= $new_request->{"env"}{"COOKIE"}B= $new_request->{"env"}{"HTTP_COOKIE"}
ABresult
1X1
011
000
222  
223 207 ▶ no warnings; # COOKIE can be undef
Subroutine BEGIN: called CC=1 SCAR=0.0
224 15 ▶ unless ( $new_request->{env}{COOKIE} =~ /$name\s*=/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_request->{"env"}{"COOKIE"} =~ /$name\s*=/) 15 0 15
225 $new_request->{env}{COOKIE} = join ';',
226 30 grep { $_ }
227 $new_request->{env}{COOKIE},
228 15 join '=', $name, Dancer::Session->get_current_session->id;
229 }
230 }
231  
232 16 $new_request->{uploads} = $request->uploads;
233  
234 16 return $new_request;
235 }
236  
237 2 ▶sub _valid_method {
Subroutine _valid_method: called CC=1 SCAR=0.0
238 2 my $method = shift;
239 2 return $method =~ /^(?:head|post|get|put|delete)$/i;
240 }
241  
242 16 ▶sub _merge_params {
Subroutine _merge_params: called CC=3 SCAR=11.1
243 16 my ($params, $to_add) = @_;
244  
245 16 ▶ die unless ref $to_add eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $to_add eq "HASH" 0 16 16
246 16 for my $key (keys %$to_add) {
247 4 $params->{$key} = $to_add->{$key};
248 }
249 16 return $params;
250 }
251  
252 29 ▶sub base {
Subroutine base: called CC=1 SCAR=0.0
Pod documented
253 29 my $self = shift;
254 29 my $uri = $self->_common_uri;
255  
256 29 return $uri->canonical;
257 }
258  
259 32 ▶sub _common_uri {
Subroutine _common_uri: called CC=8 SCAR=20.8
260 32 my $self = shift;
261  
262 32 ▶ my $path = $self->env->{SCRIPT_NAME} || '';
Condition100%2/2
$self->env->{'SCRIPT_NAME'} || ''
l!l
1121
MC/DC100%1/1
$self->env->{'SCRIPT_NAME'} || ''
$self->env->{'SCRIPT_NAME'}
Truth table100%2/2
A
A= $self->env->{'SCRIPT_NAME'}
Aresult
11
00
263 32 my $port = $self->env->{SERVER_PORT};
264 32 my $server = $self->env->{SERVER_NAME};
265 32 my $host = $self->host;
266 32 my $scheme = $self->scheme;
267  
268 32 my $uri = URI->new;
269 32 $uri->scheme($scheme);
270 32 ▶ $uri->authority($host || "$server:$port");
Condition100%2/2
$host || "${server}:$port"
l!l
2111
MC/DC100%1/1
$host || "${server}:$port"
$host
Truth table100%2/2
A
A= $host
Aresult
11
00
271 32 ▶ if (setting('behind_proxy')) {
Branch: 1 branch
BranchTrueFalseTotal
if (setting('behind_proxy')) { } 5 27 32
272 5 ▶ my $request_base = $self->env->{REQUEST_BASE} || $self->env->{HTTP_REQUEST_BASE} || '';
Condition80%4/5
$self->env->{'REQUEST_BASE'} || $self->env->{'HTTP_REQUEST_BASE'} || ''
l!l
14
$self->env->{"REQUEST_BASE"} or $self->env->{"HTTP_REQUEST_BASE"}
l!l&&r!l&&!r
014
MC/DC50%1/2
$self->env->{'REQUEST_BASE'} || $self->env->{'HTTP_REQUEST_BASE'} || ''
$self->env->{"REQUEST_BASE"} $self->env->{"HTTP_REQUEST_BASE"}
Truth table66%2/3
A or B
A= $self->env->{"REQUEST_BASE"}B= $self->env->{"HTTP_REQUEST_BASE"}
ABresult
1X1
011
000
273 5 ▶ $uri->path($request_base . $path || '/');
Condition100%2/2
$request_base . $path || '/'
l!l
14
MC/DC100%1/1
$request_base . $path || '/'
$request_base . $path
Truth table100%2/2
A
A= $request_base . $path
Aresult
11
00
274 }
275 else {
276 27 ▶ $uri->path($path || '/');
Condition100%2/2
$path || '/'
l!l
1116
MC/DC100%1/1
$path || '/'
$path
Truth table100%2/2
A
A= $path
Aresult
11
00
277 }
278  
279 32 return $uri;
280 }
281  
282 3 ▶sub uri_base {
Subroutine uri_base: called CC=2 SCAR=6.9
Pod documented
283 3 my $self = shift;
284 3 my $uri = $self->_common_uri;
285 3 my $canon = $uri->canonical;
286  
287 3 ▶ if ( $uri->path eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->path eq "/") 2 1 3
288 2 $canon =~ s{/$}{};
289 }
290  
291 3 return $canon;
292 }
293  
294 26 ▶sub uri_for {
Subroutine uri_for: called CC=3 SCAR=11.0
Pod documented
295 26 my ($self, $part, $params, $dont_escape) = @_;
296 26 my $uri = $self->base;
297  
298 # Make sure there's exactly one slash between the base and the new part
299 26 my $base = $uri->path;
300 26 $base =~ s|/$||;
301 26 $part =~ s|^/||;
302 26 $uri->path("$base/$part");
303  
304 26 ▶ $uri->query_form($params) if $params;
Branch: 1 branch
BranchTrueFalseTotal
if $params 20 6 26
305  
306 26 ▶ return $dont_escape ? uri_unescape($uri->canonical) : $uri->canonical;
Branch: 1 branch
BranchTrueFalseTotal
$dont_escape ? : 20 6 26
307 }
308  
309 436 ▶sub params {
Subroutine params: called CC=11 SCAR=26.0
Pod documented
310 436 my ($self, $source) = @_;
311  
312 436 my @caller = caller;
313  
314 436 ▶ if (not $self->{_params_are_decoded}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_params_are_decoded"}) 289 147 436
315 289 $self->{params} = _decode($self->{params});
316 289 $self->{_body_params} = _decode($self->{_body_params});
317 289 $self->{_query_params} = _decode($self->{_query_params});
318 289 $self->{_route_params} = _decode($self->{_route_params});
319 289 $self->{_params_are_decoded} = 1;
320 }
321  
322 436 ▶ return %{$self->{params}} if wantarray && @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray and @_ == 1 15 421 436
Condition100%3/3
wantarray and @_ == 1
!ll&&!rl&&r
419215
MC/DC100%2/2
wantarray and @_ == 1
wantarray @_ == 1
Truth table100%3/3
A and B
A= wantarrayB= @_ == 1
ABresult
0X0
100
111
323 421 ▶ return $self->{params} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 402 19 421
324  
325 19 ▶ if ($source eq 'query') {
Branch: 2 branches
BranchTrueFalseTotal
if ($source eq 'query') { } 4 15 19
elsif ($source eq 'body') { } 15 0 15
326 4 ▶ return %{$self->{_query_params}} if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 2 2 4
327 2 return $self->{_query_params};
328 }
329 elsif ($source eq 'body') {
330 0 ▶ return %{$self->{_body_params}} if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 15 15
331 15 return $self->{_body_params};
332 }
333 0 ▶ if ($source eq 'route') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source eq 'route') { } 0 0 0
334 0 ▶ return %{$self->{_route_params}} if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
335 0 return $self->{_route_params};
336 }
337 else {
338 0 raise core_request => "Unknown source params \"$source\".";
339 }
340 }
341  
342 2542 ▶sub _decode {
Subroutine _decode: called CC=7 SCAR=19.5
343 2542 my ($h) = @_;
344 2542 ▶ return if not defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 12 2530 2542
345  
346 2530 ▶ if (!ref($h) && !utf8::is_utf8($h)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $h or utf8::is_utf8($h)) 622 1908 2530
Condition100%3/3
ref $h or utf8::is_utf8($h)
l!l&&r!l&&!r
188028622
MC/DC100%2/2
ref $h or utf8::is_utf8($h)
ref $h utf8::is_utf8($h)
Truth table100%3/3
A or B
A= ref $hB= utf8::is_utf8($h)
ABresult
1X1
011
000
347 622 return decode('UTF-8', $h);
348 }
349  
350 1908 ▶ if (ref($h) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $h eq "HASH") 1797 111 1908
351 1797 ▶ while (my ($k, $v) = each(%$h)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$h) 631 1797 2428
352 631 $h->{$k} = _decode($v);
353 }
354 1797 return $h;
355 }
356  
357 111 ▶ if (ref($h) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $h eq "ARRAY") 83 28 111
358 83 return [ map { _decode($_) } @$h ];
359 }
360  
361 28 return $h;
362 }
363  
364 618 ▶sub is_ajax {
Subroutine is_ajax: called CC=6 SCAR=18.0
Pod documented
365 618 my $self = shift;
366  
367 # when using Plack::Builder headers are not set
368 # so we're checking if it's actually there with PSGI plain headers
369 618 ▶ if ( defined $self->{x_requested_with} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"x_requested_with"}) 2 616 618
370 2 ▶ if ( $self->{x_requested_with} eq "XMLHttpRequest" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"x_requested_with"} eq "XMLHttpRequest") 2 0 2
371 2 return 1;
372 }
373 }
374  
375 616 ▶ return 0 unless defined $self->headers;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->headers 612 4 616
376 4 ▶ return 0 unless defined $self->header('X-Requested-With');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->header("X-Requested-With") 3 1 4
377 1 ▶ return 0 if $self->header('X-Requested-With') ne 'XMLHttpRequest';
Branch: 1 branch
BranchTrueFalseTotal
if $self->header("X-Requested-With") ne "XMLHttpRequest" 0 1 1
378 1 return 1;
379 }
380  
381 # context-aware accessor for uploads
382 8 ▶sub upload {
Subroutine upload: called CC=4 SCAR=13.9
Pod documented
383 8 my ($self, $name) = @_;
384 8 my $res = $self->{uploads}{$name};
385  
386 8 ▶ return $res unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 5 3 8
387 3 ▶ return () unless defined $res;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 1 2 3
388 2 ▶ return (ref($res) eq 'ARRAY') ? @$res : $res;
Branch: 1 branch
BranchTrueFalseTotal
ref $res eq 'ARRAY' ? : 1 1 2
389 }
390  
391 # Some Dancer's core components sometimes need to alter
392 # the parsed request params, these protected accessors are provided
393 # for this purpose
394 651 ▶sub _set_route_params {
Subroutine _set_route_params: called CC=1 SCAR=0.0
395 651 my ($self, $params) = @_;
396 651 $self->{_route_params} = $params;
397 651 $self->_build_params();
398 }
399  
400 8 ▶sub _set_body_params {
Subroutine _set_body_params: called CC=1 SCAR=0.0
401 8 my ($self, $params) = @_;
402 8 $self->{_body_params} = $params;
403 8 $self->_build_params();
404 }
405  
406 0 ▶sub _set_query_params {
Subroutine _set_query_params: not called CC=1 SCAR=6.9
407 0 my ($self, $params) = @_;
408 0 $self->{_query_params} = $params;
409 0 $self->_build_params();
410 }
411  
412 615 ▶sub _build_request_env {
Subroutine _build_request_env: called CC=1 SCAR=0.0
413 615 my ($self) = @_;
414  
415 # Don't refactor that, it's called whenever a request object is needed, that
416 # means at least once per request. If refactored in a loop, this will cost 4
417 # times more than the following static map.
418 615 my $env = $self->env;
419 615 $self->{user_agent} = $env->{HTTP_USER_AGENT};
420 615 $self->{host} = $env->{HTTP_HOST};
421 615 $self->{accept_language} = $env->{HTTP_ACCEPT_LANGUAGE};
422 615 $self->{accept_charset} = $env->{HTTP_ACCEPT_CHARSET};
423 615 $self->{accept_encoding} = $env->{HTTP_ACCEPT_ENCODING};
424 615 $self->{keep_alive} = $env->{HTTP_KEEP_ALIVE};
425 615 $self->{connection} = $env->{HTTP_CONNECTION};
426 615 $self->{accept} = $env->{HTTP_ACCEPT};
427 615 $self->{accept_type} = $env->{HTTP_ACCEPT_TYPE};
428 615 $self->{referer} = $env->{HTTP_REFERER};
429 615 $self->{x_requested_with} = $env->{HTTP_X_REQUESTED_WITH};
430 }
431  
432 615 ▶sub _build_headers {
Subroutine _build_headers: called CC=1 SCAR=0.0
433 615 my ($self) = @_;
434 615 $self->{headers} = Dancer::SharedData->headers;
435 }
436  
437 2460 ▶sub _build_params {
Subroutine _build_params: called CC=3 SCAR=11.0
438 2460 my ($self) = @_;
439  
440 # params may have been populated by before filters
441 # _before_ we get there, so we have to save it first
442 2460 my $previous = $self->{params};
443  
444 # now parse environment params...
445 2460 $self->_parse_get_params();
446 2460 ▶ if ($self->is_forward) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_forward) { } 47 2413 2460
447 47 ▶ $self->{_body_params} ||= {};
Condition100%2/2
$self->{"_body_params"} ||= {}
l!l
3116
MC/DC100%1/1
$self->{"_body_params"} ||= {}
$self->{"_body_params"}
Truth table100%2/2
A
A= $self->{"_body_params"}
Aresult
11
00
448 } else {
449 2413 $self->_parse_post_params();
450 }
451  
452 # and merge everything
453 $self->{params} = {
454 2460 %$previous, %{$self->{_query_params}},
455 2460 %{$self->{_route_params}}, %{$self->{_body_params}},
456 };
457  
458 }
459  
460 # Written from PSGI specs:
461 # http://search.cpan.org/dist/PSGI/PSGI.pod
462 615 ▶sub _build_path {
Subroutine _build_path: called CC=6 SCAR=18.0
463 615 my ($self) = @_;
464 615 my $path = "";
465  
466 615 ▶ $path .= $self->script_name if defined $self->script_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->script_name 11 604 615
467 615 ▶ $path .= $self->env->{PATH_INFO} if defined $self->env->{PATH_INFO};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->env->{"PATH_INFO"} 604 11 615
468  
469 # fallback to REQUEST_URI if nothing found
470 # we have to decode it, according to PSGI specs.
471 615 ▶ if (defined $self->request_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->request_uri) 530 85 615
472 530 ▶ $path ||= $self->_url_decode($self->request_uri);
Condition66%2/3
$path ||= $self->_url_decode($self->request_uri)
l!l&&r!l&&!r
52640
MC/DC0%0/2
$path ||= $self->_url_decode($self->request_uri)
$path $self->_url_decode($self->request_uri)
Truth table66%2/3
A ||= B
A= $pathB= $self->_url_decode($self->request_uri)
ABresult
1X1
011
000
473 }
474  
475 615 ▶ raise core_request => "Cannot resolve path" if not $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 615 615
476 615 $self->{path} = $path;
477 }
478  
479 615 ▶sub _build_path_info {
Subroutine _build_path_info: called CC=3 SCAR=11.0
480 615 my ($self) = @_;
481 615 my $info = $self->env->{PATH_INFO};
482 615 ▶ if (defined $info) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info) { } 604 11 615
483  
484 # Empty path info will be interpreted as "root".
485 604 ▶ $info ||= '/';
Condition50%1/2
$info ||= "/"
l!l
6040
MC/DC0%0/1
$info ||= "/"
$info
Truth table50%1/2
A
A= $info
Aresult
11
00
486 }
487 else {
488 11 $info = $self->path;
489 }
490 615 $self->{path_info} = $info;
491 }
492  
493 615 ▶sub _build_method {
Subroutine _build_method: called CC=2 SCAR=8.1
494 615 my ($self) = @_;
495 $self->{method} = $self->env->{REQUEST_METHOD}
496 615 ▶ || $self->{request}->request_method();
Condition33%1/3
$self->env->{'REQUEST_METHOD'} || $self->{'request'}->request_method
l!l&&r!l&&!r
61500
MC/DC0%0/2
$self->env->{'REQUEST_METHOD'} || $self->{'request'}->request_method
$self->env->{'REQUEST_METHOD'} $self->{'request'}->request_method
Truth table33%1/3
A || B
A= $self->env->{'REQUEST_METHOD'}B= $self->{'request'}->request_method
ABresult
1X1
011
000
497 }
498  
499 92 ▶sub _url_decode {
Subroutine _url_decode: called CC=1 SCAR=0.0
500 92 my ($self, $encoded) = @_;
501 92 my $clean = $encoded;
502 92 $clean =~ tr/\+/ /;
503 92 $clean =~ s/%([a-fA-F0-9]{2})/pack "H2", $1/eg;
504 92 return $clean;
505 }
506  
507 2413 ▶sub _parse_post_params {
Subroutine _parse_post_params: called CC=2 SCAR=6.9
508 2413 my ($self) = @_;
509 2413 ▶ return $self->{_body_params} if defined $self->{_body_params};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_body_params"} 1814 599 2413
510  
511 599 $self->_read_to_end();
512 599 $self->{_body_params} = $self->{_http_body}->param;
513 }
514  
515 2460 ▶sub _parse_get_params {
Subroutine _parse_get_params: called CC=9 SCAR=22.8
516 2460 my ($self) = @_;
517 2460 ▶ return $self->{_query_params} if defined $self->{_query_params};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_query_params"} 1845 615 2460
518 615 $self->{_query_params} = {};
519  
520 615 ▶ my $source = $self->env->{QUERY_STRING} || '';
Condition100%2/2
$self->env->{'QUERY_STRING'} || ''
l!l
21594
MC/DC100%1/1
$self->env->{'QUERY_STRING'} || ''
$self->env->{'QUERY_STRING'}
Truth table100%2/2
A
A= $self->env->{'QUERY_STRING'}
Aresult
11
00
521 615 foreach my $token (split /[&;]/, $source) {
522 44 my ($key, $val) = split(/=/, $token, 2);
523 44 ▶ next unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 44 44
524 44 ▶ $val = (defined $val) ? $val : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 44 0 44
525 44 $key = $self->_url_decode($key);
526 44 $val = $self->_url_decode($val);
527  
528 # looking for multi-value params
529 44 ▶ if (exists $self->{_query_params}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_query_params'}{$key}) { } 4 40 44
530 4 my $prev_val = $self->{_query_params}{$key};
531 4 ▶ if (ref($prev_val) && ref($prev_val) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $prev_val and ref $prev_val eq 'ARRAY') { } 0 4 4
Condition33%1/3
ref $prev_val and ref $prev_val eq "ARRAY"
!ll&&!rl&&r
400
MC/DC0%0/2
ref $prev_val and ref $prev_val eq "ARRAY"
ref $prev_val ref $prev_val eq "ARRAY"
Truth table33%1/3
A and B
A= ref $prev_valB= ref $prev_val eq "ARRAY"
ABresult
0X0
100
111
532 0 push @{$self->{_query_params}{$key}}, $val;
533 }
534 else {
535 4 $self->{_query_params}{$key} = [$prev_val, $val];
536 }
537 }
538  
539 # simple value param (first time we see it)
540 else {
541 40 $self->{_query_params}{$key} = $val;
542 }
543 }
544 615 return $self->{_query_params};
545 }
546  
547 599 ▶sub _read_to_end {
Subroutine _read_to_end: called CC=6 SCAR=18.0
548 599 my $self = shift;
549
550 599 ▶ return unless $self->_has_something_to_read;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_something_to_read 567 32 599
551  
552 32 ▶ if ( $self->content_length > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->content_length > 0) 20 12 32
553 20 my $body = '';
554  
555 20 my $store_raw_body = setting('raw_request_body_in_ram');
556 20 ▶ $store_raw_body = defined $store_raw_body ? $store_raw_body : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $store_raw_body ? : 0 20 20
557  
558 20 ▶ while ( my $buffer = $self->_read ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $buffer = $self->_read) 20 20 40
559 20 $self->{_http_body}->add($buffer);
560  
561 # Only keep a copy of the raw request body in RAM if the user has
562 # asked us to
563
564 20 ▶ if ($store_raw_body) {
Branch: 1 branch
BranchTrueFalseTotal
if ($store_raw_body) 20 0 20
565 20 $self->{body} .= $buffer;
566 }
567 }
568  
569 }
570  
571 32 return $self->{_http_body};
572 }
573  
574 599 ▶sub _has_something_to_read {
Subroutine _has_something_to_read: called CC=1 SCAR=0.0
575 599 defined $_[0]->input_handle;
576 }
577  
578 # taken from Miyagawa's Plack::Request::BodyParser
579 40 ▶sub _read {
Subroutine _read: called CC=4 SCAR=14.1
580 40 my ($self,) = @_;
581 40 my $remaining = $self->content_length - $self->{_read_position};
582 40 my $maxlength = $self->{_chunk_size};
583  
584 40 ▶ return if ($remaining <= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $remaining <= 0 20 20 40
585  
586 20 ▶ my $readlen = ($remaining > $maxlength) ? $maxlength : $remaining;
Branch: 1 branch
BranchTrueFalseTotal
$remaining > $maxlength ? : 0 20 20
587 20 my $buffer;
588 my $rc;
589  
590 20 $rc = $self->input_handle->read($buffer, $readlen);
591  
592 20 ▶ if (defined $rc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rc) { } 20 0 20
593 20 $self->{_read_position} += $rc;
594 20 return $buffer;
595 }
596 else {
597 0 raise core_request => "Unknown error reading input: $!";
598 }
599 }
600  
601 # Taken gently from Plack::Request, thanks to Plack authors.
602 615 ▶sub _build_uploads {
Subroutine _build_uploads: called CC=6 SCAR=17.9
603 615 my ($self) = @_;
604  
605 615 my $uploads = _decode($self->{_http_body}->upload);
606 615 my %uploads;
607  
608 615 for my $name (keys %{$uploads}) {
609 9 my $files = $uploads->{$name};
610 9 ▶ $files = ref $files eq 'ARRAY' ? $files : [$files];
Branch: 1 branch
BranchTrueFalseTotal
ref $files eq 'ARRAY' ? : 2 7 9
611  
612 9 my @uploads;
613 9 for my $upload (@{$files}) {
614 push(
615 @uploads,
616 Dancer::Request::Upload->new(
617 headers => $upload->{headers},
618 tempname => $upload->{tempname},
619 size => $upload->{size},
620 filename => $upload->{filename},
621 )
622 11 );
623 }
624 9 ▶ $uploads{$name} = @uploads > 1 ? \@uploads : $uploads[0];
Branch: 1 branch
BranchTrueFalseTotal
@uploads > 1 ? : 2 7 9
625  
626 # support access to the filename as a normal param
627 9 my @filenames = map { $_->{filename} } @uploads;
628 9 ▶ $self->{_body_params}{$name} =
Branch: 1 branch
BranchTrueFalseTotal
@filenames > 1 ? : 2 7 9
629 @filenames > 1 ? \@filenames : $filenames[0];
630 }
631  
632 615 $self->{uploads} = \%uploads;
633 615 $self->_build_params();
634 }
635  
636 207 1;
637  
638 __END__
« lib/Dancer/Renderer.pm ↑ Summary lib/Dancer/Cookie.pm »