blib/lib/YATT/Lite/WebMVC0/Connection.pm

filter: Statementstmt 79.4% 390 / 491 Branchbran 63.4% 184 / 290 Conditioncond 55.6% 98 / 176 MC/DCmcdc 29.0% 29 / 100 Subroutinesub 81.8% 63 / 77 Podpod 62.5% 35 / 56 totaltotal 67.1% 799 / 1190 CC 223 SCAR 26.4
CC
223
Cov
70%
param
54.7
multi_param
49.4
delete_param
42.0
CRAP 14.0
« blib/lib/YATT/Lite/LRXML/AltTree.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/DirApp.pm »
1 package YATT::Lite::WebMVC0::Connection; sub PROP () {__PACKAGE__}
2 71 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 71 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 71 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 71 ▶use base qw(YATT::Lite::Connection);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 use YATT::Lite::MFields
8 71 ▶(qw/cgi
Subroutine BEGIN: called CC=1 SCAR=0.0
9 is_psgi hmv
10 parameters
11  
12 site_prefix
13  
14 no_nested_query
15  
16 mkquery_with_body_params
17  
18 no_unicode_params
19  
20 _dir_config_cache
21 _site_config_is_examined
22  
23 _sigil_type_item
24  
25 _current_user
26  
27 _htdebug_cache
28 71 /);
29 71 ▶use YATT::Lite::Util qw(globref url_encode nonempty empty rootname lexpand);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 71 ▶use YATT::Lite::PSGIEnv;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 71 ▶use YATT::Lite::Util::CGICompat;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 #----------------------------------------
35  
36 71 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=19.0
37 # print STDERR join("\n", sort(keys our %FIELDS)), "\n";
38  
39 71 foreach my $name (qw(raw_body uploads upload)) {
40 213 ▶ *{globref(PROP, $name)} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
41 4 my PROP $prop = (my $glob = shift)->prop;
42 4 ▶ unless ($prop->{is_psgi}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prop->{"is_psgi"}) 0 4 4
43 0 croak "Connection method $name is PSGI mode only!"
44 }
45 4 $prop->{cgi}->$name(@_);
46 213 };
47 }
48  
49 71 foreach my $name (qw(url_param)) {
50 71 ▶ *{globref(PROP, $name)} = sub {
Subroutine __ANON__: not called CC=1 SCAR=2.6
51 0 my PROP $prop = (my $glob = shift)->prop;
52 0 $prop->{cgi}->$name(@_);
53 71 };
54 }
55  
56 71 foreach my $item ([referer => 'HTTP_REFERER']
57 , map([lc($_) => uc($_)]
58 , qw/REMOTE_ADDR
59 REQUEST_METHOD
60 SCRIPT_NAME
61 PATH_INFO
62 QUERY_STRING
63 SERVER_NAME
64 SERVER_PORT
65 SERVER_PROTOCOL
66 CONTENT_LENGTH
67 CONTENT_TYPE
68 /)
69 ) {
70 781 my ($method, $env) = @$item;
71 781 ▶ *{globref(PROP, $method)} = sub {
Subroutine __ANON__: called CC=6 SCAR=27.7
72 3 my PROP $prop = (my $glob = shift)->prop;
73 3 my ($default) = @_;
74 3 ▶ if ($prop->{env}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($prop->{'env'}) { } 3 0 3
elsif ($prop->{'cgi'} and my $sub = $prop->{'cgi'}->can($method)) { } 0 0 0
75 3 ▶ $prop->{env}->{$env} // $default;
Condition33%1/3
$prop->{"env"}{$env} // $default
l!l&&r!l&&!r
300
MC/DC0%0/2
$prop->{"env"}{$env} // $default
$prop->{"env"}{$env} $default
Truth table33%1/3
A // B
A= $prop->{"env"}{$env}B= $default
ABresult
1X1
011
000
76 ▶ } elsif ($prop->{cgi} and my $sub = $prop->{cgi}->can($method)) {
Condition0%0/3
$prop->{"cgi"} and my $sub = $prop->{"cgi"}->can($method)
!ll&&!rl&&r
000
MC/DC0%0/2
$prop->{"cgi"} and my $sub = $prop->{"cgi"}->can($method)
$prop->{"cgi"} my $sub = $prop->{"cgi"}->can($method)
Truth table0%0/3
A and B
A= $prop->{"cgi"}B= my $sub = $prop->{"cgi"}->can($method)
ABresult
0X0
100
111
77 0 ▶ $sub->($prop->{cgi}) // $default;
Condition0%0/3
&$sub($prop->{"cgi"}) // $default
l!l&&r!l&&!r
000
MC/DC0%0/2
&$sub($prop->{"cgi"}) // $default
&$sub($prop->{"cgi"}) $default
Truth table0%0/3
A // B
A= &$sub($prop->{"cgi"})B= $default
ABresult
1X1
011
000
78 } else {
79 0 $default;
80 }
81 781 };
82 }
83  
84 71 foreach my $name (qw(file subpath parameters request_file)) {
85 284 ▶ *{globref(PROP, $name)} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
86 6 my PROP $prop = (my $glob = shift)->prop;
87 6 $prop->{$name};
88 284 };
89 }
90 }
91  
92 #========================================
93  
94 460 ▶sub param {
Subroutine param: called CC=12 SCAR=40.0
Pod documented
95 460 my PROP $prop = (my $glob = shift)->prop;
96 460 ▶ if (my $ixh = $prop->{parameters}) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $ixh = $prop->{'parameters'}) { } 460 0 460
elsif (my $hmv = $prop->{'hmv'}) { } 0 0 0
elsif (my $cgi = $prop->{'cgi'}) { } 0 0 0
97 460 ▶ return keys %$ixh unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 396 64 460
98 64 ▶ defined (my $key = shift)
Branch: 1 branch
BranchTrueFalseTotal
defined(my $key = shift()) or croak("undefined key!") 64 0 64
99 or croak "undefined key!";
100 64 ▶ $key =~ s/\[\]\z// if not $prop->{no_nested_query};
Branch: 1 branch
BranchTrueFalseTotal
unless $prop->{"no_nested_query"} 64 0 64
101 64 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 64 64
102 0 ▶ if (@_ >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2) { } 0 0 0
103 0 $ixh->{$key} = [@_]
104 } else {
105 0 $ixh->{$key} = shift;
106 }
107 } else {
108 # If parameters is enabled, value is returned AS-IS.
109 64 $ixh->{$key};
110 }
111 } elsif (my $hmv = $prop->{hmv}) {
112 0 ▶ return $hmv->keys unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
113 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
114 0 ▶ return wantarray ? $hmv->get_all($_[0]) : $hmv->get($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
115 } else {
116 0 $hmv->add(@_);
117 0 return $glob;
118 }
119 } elsif (my $cgi = $prop->{cgi}) {
120 0 return $cgi->param(@_);
121 } else {
122 0 croak "Neither Hash::MultiValue nor CGI is found in connection!";
123 }
124 }
125  
126 # Annoying multi_param support.
127 117 ▶sub multi_param {
Subroutine multi_param: called CC=10 SCAR=39.0
Pod documented
128 117 my PROP $prop = (my $glob = shift)->prop;
129 117 ▶ if (my $ixh = $prop->{parameters}) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $ixh = $prop->{'parameters'}) { } 117 0 117
elsif (my $hmv = $prop->{'hmv'} // do { $prop->{'is_psgi'} and $prop->{'cgi'}->parameters }) { } 0 0 0
elsif (my $cgi = $prop->{'cgi'}) { } 0 0 0
130 117 ▶ return keys %$ixh unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 117 117
131 117 ▶ defined (my $key = shift)
Branch: 1 branch
BranchTrueFalseTotal
defined(my $key = shift()) or croak("undefined key!") 117 0 117
132 or croak "undefined key!";
133 # If parameters is enabled, value is returned AS-IS.
134 117 $ixh->{$key};
135  
136 ▶ } elsif (my $hmv = ($prop->{hmv} // do {
Condition0%0/3
$prop->{"hmv"} // do { $prop->{"is_psgi"} and $prop->{"cgi"}->parameters }
l!l&&r!l&&!r
000
MC/DC0%0/2
$prop->{"hmv"} // do { $prop->{"is_psgi"} and $prop->{"cgi"}->parameters }
$prop->{"hmv"} do { $prop->{"is_psgi"} and $prop->{"cgi"}->parameters }
Truth table0%0/3
A // B
A= $prop->{"hmv"}B= do { $prop->{"is_psgi"} and $prop->{"cgi"}->parameters }
ABresult
1X1
011
000
137 $prop->{is_psgi} && $prop->{cgi}->parameters
138 0 ▶ })) {
Condition0%0/3
$prop->{'is_psgi'} && $prop->{'cgi'}->parameters
!ll&&!rl&&r
000
MC/DC0%0/2
$prop->{'is_psgi'} && $prop->{'cgi'}->parameters
$prop->{'is_psgi'} $prop->{'cgi'}->parameters
Truth table0%0/3
A && B
A= $prop->{'is_psgi'}B= $prop->{'cgi'}->parameters
ABresult
0X0
100
111
139 0 ▶ return $hmv->keys unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
140 0 ▶ return wantarray ? $hmv->get_all($_[0]) : $hmv->get($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
141 } elsif (my $cgi = $prop->{cgi}) {
142 0 return $cgi->multi_param(@_);
143 } else {
144 0 croak "Neither Hash::MultiValue nor CGI is found in connection!";
145 }
146 }
147  
148 #========================================
149  
150 399 ▶sub sigil_type_item {
Subroutine sigil_type_item: called CC=2 SCAR=7.1
Pod undocumented
151 399 my PROP $prop = (my $glob = shift)->prop;
152  
153 399 ▶ @{$prop->{_sigil_type_item} // []};
Condition50%1/2
$prop->{"_sigil_type_item"} // []
l!l
3990
MC/DC0%0/1
$prop->{"_sigil_type_item"} // []
$prop->{"_sigil_type_item"}
Truth table50%1/2
A
A= $prop->{"_sigil_type_item"}
Aresult
11
00
154 }
155  
156 546 ▶sub collect_request_sigil_by {
Subroutine collect_request_sigil_by: called CC=5 SCAR=16.1
Pod undocumented
157 546 my ($glob, $cutter, @list) = @_;
158 546 my %dict;
159 546 foreach my $name (grep {defined} @list) {
160 282 ▶ my ($sigil, $word) = $name =~ /^([~!])(\1|\w*)$/
Branch: 1 branch
BranchTrueFalseTotal
() = $name =~ /^([~!])(\1|\w*)$/ or next 66 216 282
161 or next;
162 66 ▶ defined (my $value = $cutter->($name))
Branch: 1 branch
BranchTrueFalseTotal
defined(my $value = &$cutter($name)) or next 66 0 66
163 or next;
164 66 push @{$dict{$sigil}}, do {
165 66 ▶ if ($sigil eq $word) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sigil eq $word) { } 52 14 66
166 52 $value;
167 } else {
168 14 $word;
169 }
170 };
171 };
172 546 \%dict;
173 }
174  
175 965 ▶sub has_content {
Subroutine has_content: called CC=4 SCAR=13.9
Pod undocumented
176 965 my PROP $prop = (my $glob = shift)->prop;
177 my Env $env = $prop->{env}
178 965 ▶ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::WebMVC0::Connection::Env $env = $prop->{"env"} or return 0 964 1 965
179 964 ▶ ($env->{CONTENT_TYPE} and defined $env->{CONTENT_LENGTH}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$env->{'CONTENT_TYPE'} && defined $env->{'CONTENT_LENGTH'} ? : 56 908 964
Condition66%2/3
$env->{"CONTENT_TYPE"} and defined $env->{"CONTENT_LENGTH"}
!ll&&!rl&&r
908056
MC/DC50%1/2
$env->{"CONTENT_TYPE"} and defined $env->{"CONTENT_LENGTH"}
$env->{"CONTENT_TYPE"} defined $env->{"CONTENT_LENGTH"}
Truth table66%2/3
A and B
A= $env->{"CONTENT_TYPE"}B= defined $env->{"CONTENT_LENGTH"}
ABresult
0X0
100
111
180 }
181  
182 484 ▶sub parse_request_sigil_psgi {
Subroutine parse_request_sigil_psgi: called CC=3 SCAR=11.0
Pod undocumented
183 484 my PROP $prop = (my $glob = shift)->prop;
184 484 my ($req) = @_;
185  
186 484 ▶ if ($glob->has_content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($glob->has_content) { } 24 460 484
187 24 $prop->{_sigil_type_item} = do {
188 24 my @bodyParams = $glob->extract_sigil_from_hmv($req->body_parameters);
189 22 my @queryParams = $glob->extract_sigil_from_hmv($req->query_parameters);
190 22 ▶ if (@bodyParams) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bodyParams) { } 3 19 22
191 \@bodyParams
192 3 } else {
193 \@queryParams
194 19 }
195 };
196 } else {
197 460 $glob->parse_request_sigil_hmv($req->parameters);
198 }
199 }
200  
201 484 ▶sub parse_request_sigil_hmv {
Subroutine parse_request_sigil_hmv: called CC=2 SCAR=6.9
Pod undocumented
202 484 my PROP $prop = (my $glob = shift)->prop;
203 484 my ($hmvOrRawHash) = @_;
204 484 ▶ my $hmv = ref $hmvOrRawHash eq 'HASH' ? Hash::MultiValue->new(%$hmvOrRawHash)
Branch: 1 branch
BranchTrueFalseTotal
ref $hmvOrRawHash eq 'HASH' ? : 5 479 484
205 : $hmvOrRawHash;
206 484 $prop->{_sigil_type_item} = [$glob->extract_sigil_from_hmv($hmv)];
207 }
208  
209 530 ▶sub extract_sigil_from_hmv {
Subroutine extract_sigil_from_hmv: called CC=1 SCAR=0.0
Pod undocumented
210 530 my ($glob, $hmv) = @_;
211  
212 my $sigilsDict = $glob->collect_request_sigil_by(
213 66 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
214 66 my $value = $hmv->{$_[0]};
215 66 $hmv->remove($_[0]);
216 66 $value;
217 530 }, $hmv->keys);
218 530 $glob->validate_request_sigils_dict($sigilsDict);
219 }
220  
221 16 ▶sub parse_request_sigil_cgi {
Subroutine parse_request_sigil_cgi: called CC=1 SCAR=0.8
Pod undocumented
222 16 my PROP $prop = (my $glob = shift)->prop;
223 16 my ($cgi) = @_;
224 my $sigilsDict = $glob->collect_request_sigil_by(
225 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
226 0 my $value = $cgi->param($_[0]);
227 0 $cgi->delete($_[0]);
228 0 $value;
229 16 }, $cgi->param());
230 $prop->{_sigil_type_item}
231 16 = [$glob->validate_request_sigils_dict($sigilsDict)];
232 }
233  
234 546 ▶sub validate_request_sigils_dict {
Subroutine validate_request_sigils_dict: called CC=11 SCAR=24.5
Pod undocumented
235 546 my PROP $prop = (my $glob = shift)->prop;
236 546 my ($sigilsDict) = @_;
237  
238 546 my ($subpage, $action);
239 546 ▶ if (my $names = $sigilsDict->{'~'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $names = $sigilsDict->{"~"}) 50 496 546
240 50 ▶ if (@$names >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$names >= 2) 0 50 50
241 0 $glob->error("Multiple subpage sigils in request!: %s"
242 , join(", ", @$names));
243 }
244 50 $subpage = $names->[0];
245 }
246 546 ▶ if (my $names = $sigilsDict->{'!'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $names = $sigilsDict->{"!"}) 16 530 546
247 16 ▶ if (@$names >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$names >= 2) 0 16 16
248 0 $glob->error("Multiple action sigils in request!: %s"
249 , join(", ", @$names));
250 }
251 16 $action = $names->[0];
252 }
253 546 ▶ if (defined $subpage and defined $action) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $subpage and defined $action) { } 0 546 546
elsif (defined $subpage) { } 50 496 546
elsif (defined $action) { } 16 480 496
Condition66%2/3
defined $subpage and defined $action
!ll&&!rl&&r
496500
MC/DC0%0/2
defined $subpage and defined $action
defined $subpage defined $action
Truth table66%2/3
A and B
A= defined $subpageB= defined $action
ABresult
0X0
100
111
254 # XXX: Reserved for future use.
255 0 $glob->error("Can't use subpage and action at one time: %s vs %s"
256 , $subpage, $action);
257 } elsif (defined $subpage) {
258 50 ▶ unless ($subpage =~ m{^\w*\z}a) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subpage =~ /^\w*\z/a) 9 41 50
259 9 $glob->error(+{http_status_code => 400}, "Invalid subpage: %s",
260 YATT::Lite::Util::escape($subpage));
261 }
262 41 (page => $subpage);
263 } elsif (defined $action) {
264 16 ▶ unless ($action =~ m{^\w*\z}a) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action =~ /^\w*\z/a) 8 8 16
265 8 $glob->error(+{http_status_code => 400}, "Invalid action: %s",
266 YATT::Lite::Util::escape($action));
267 }
268 8 (action => $action);
269 } else {
270 480 ();
271 }
272 }
273  
274 #========================================
275  
276 10 ▶sub queryobj {
Subroutine queryobj: called CC=3 SCAR=11.7
Pod documented
277 10 my PROP $prop = (my $glob = shift)->prop;
278 10 ▶ $prop->{parameters} || $prop->{hmv} || $prop->{cgi};
Branch: 1 branch
BranchTrueFalseTotal
$prop->{"parameters"} or $prop->{"hmv"} or $prop->{"cgi"} 10 0 10
Condition66%2/3
$prop->{"parameters"} or $prop->{"hmv"}
l!l&&r!l&&!r
640
MC/DC0%0/2
$prop->{"parameters"} or $prop->{"hmv"}
$prop->{"parameters"} $prop->{"hmv"}
Truth table66%2/3
A or B
A= $prop->{"parameters"}B= $prop->{"hmv"}
ABresult
1X1
011
000
279 }
280  
281 # GH-259: For url reproduction (mkquery($CON), current_path($CON)...),
282 # requests with a body should reproduce QUERY_STRING-derived params only.
283 # Note: query_parameters below is the sigil-stripped, request-cached
284 # Hash::MultiValue (see extract_sigil_from_hmv).
285 # Set mkquery_with_body_params to restore the old merged behavior.
286 19 ▶sub queryobj_for_mkquery {
Subroutine queryobj_for_mkquery: called CC=6 SCAR=18.0
Pod undocumented
287 19 my PROP $prop = (my $glob = shift)->prop;
288 19 ▶ if (not $prop->{mkquery_with_body_params}
Branch: 1 branch
BranchTrueFalseTotal
if (not $prop->{'mkquery_with_body_params'} || $prop->{'hmv'} and $prop->{'is_psgi'} and $prop->{'cgi'} and $glob->has_content) { } 9 10 19
Condition83%10/12
not $prop->{"mkquery_with_body_params"} || $prop->{"hmv"} and $prop->{"is_psgi"} and $prop->{"cgi"} and $glob->has_content
!ll&&!rl&&r
829
not $prop->{"mkquery_with_body_params"} || $prop->{"hmv"} and $prop->{"is_psgi"} and $prop->{"cgi"}
!ll&&!rl&&r
8011
not $prop->{"mkquery_with_body_params"} || $prop->{"hmv"} and $prop->{"is_psgi"}
!ll&&!rl&&r
8011
$prop->{'mkquery_with_body_params'} || $prop->{'hmv'}
l!l&&r!l&&!r
4411
MC/DC60%3/5
not $prop->{"mkquery_with_body_params"} || $prop->{"hmv"} and $prop->{"is_psgi"} and $prop->{"cgi"} and $glob->has_content
$prop->{'mkquery_with_body_params'} $prop->{'hmv'} $prop->{"is_psgi"} $prop->{"cgi"} $glob->has_content
Truth table66%4/6
not(A || B) and C and D and E
A= $prop->{'mkquery_with_body_params'}B= $prop->{'hmv'}C= $prop->{"is_psgi"}D= $prop->{"cgi"}E= $glob->has_content
ABCDEresult
1XXXX0
01XXX0
000XX0
0010X0
001100
001111
289 and not $prop->{hmv}
290 and $prop->{is_psgi} and $prop->{cgi}
291 and $glob->has_content) {
292 9 $prop->{cgi}->query_parameters;
293 } else {
294 10 $glob->queryobj;
295 }
296 }
297  
298 0 ▶sub param_exists {
Subroutine param_exists: not called CC=1 SCAR=6.9
Pod documented
299 0 my ($glob, $name) = @_;
300 0 exists $glob->as_hash->{$name};
301 }
302  
303 4 ▶sub as_hash {
Subroutine as_hash: called CC=4 SCAR=22.3
Pod documented
304 4 my PROP $prop = (my $glob = shift)->prop;
305 4 ▶ $prop->{parameters} // $prop->{hmv} // do {
Condition33%2/6
($prop->{"parameters"} // $prop->{"hmv"}) // do { if ($prop->{"is_psgi"}) { $prop->{"cgi"}->parameters; } else { $prop->{"cgi"}->Vars; } }
l!l&&r!l&&!r
400
$prop->{"parameters"} // $prop->{"hmv"}
l!l&&r!l&&!r
400
MC/DC0%0/3
($prop->{"parameters"} // $prop->{"hmv"}) // do { if ($prop->{"is_psgi"}) { $prop->{"cgi"}->parameters; } else { $prop->{"cgi"}->Vars; } }
$prop->{"parameters"} $prop->{"hmv"} do { if ($prop->{"is_psgi"}) { $prop->{"cgi"}->parameters; } else { $prop->{"cgi"}->Vars; } }
Truth table25%1/4
A // B // C
A= $prop->{"parameters"}B= $prop->{"hmv"}C= do { if ($prop->{"is_psgi"}) { $prop->{"cgi"}->parameters; } else { $prop->{"cgi"}->Vars; } }
ABCresult
1XX1
01X1
0011
0000
306 0 ▶ if ($prop->{is_psgi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop->{'is_psgi'}) { } 0 0 0
307 $prop->{cgi}->parameters
308 0 } else {
309 $prop->{cgi}->Vars
310 0 }
311 };
312 }
313  
314 71 *remove_param = *delete_param; *remove_param = *delete_param;
315 0 ▶sub delete_param {
Subroutine delete_param: not called CC=6 SCAR=37.4
Pod documented
316 0 my PROP $prop = (my $glob = shift)->prop;
317 0 my ($key) = @_;
318 0 ▶ unless (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key) 0 0 0
319 0 croak "Undefined key!";
320 }
321 0 ▶ if (my $dict = $prop->{parameters}) {
Branch: 4 branches
BranchTrueFalseTotal
if (my $dict = $prop->{'parameters'}) { } 0 0 0
elsif ($dict = $prop->{'hmv'}) { } 0 0 0
elsif (($dict = $prop->{'cgi'})->can('parameters')) { } 0 0 0
elsif ($dict->can('delete')) { } 0 0 0
322 # For nested_query (array_param)
323 0 delete $dict->{$key};
324 } elsif ($dict = $prop->{hmv}) {
325 # For direct Hash::MultiValue.
326 0 $dict->remove($key);
327 } elsif (($dict = $prop->{cgi})->can("parameters")) {
328 # For Plack::Request
329 0 $dict->parameters->remove($key);
330 } elsif ($dict->can("delete")) {
331 # For CGI family.
332 0 $dict->delete($key);
333 } else {
334 0 croak "No queryobj found!";
335 }
336 }
337  
338 #========================================
339  
340 683 ▶sub after_create {
Subroutine after_create: called CC=3 SCAR=11.0
Pod undocumented
341 683 my PROP $prop = (my $glob = shift)->prop;
342 683 $glob->SUPER::after_create();
343  
344 # If cgi is empty and parameters is given,
345 # request sigils are collected via parse_request_sigil_hmv.
346 #
347 683 ▶ if (not $prop->{cgi} and $prop->{parameters}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $prop->{"cgi"} and $prop->{"parameters"}) 24 659 683
Condition100%3/3
not $prop->{"cgi"} and $prop->{"parameters"}
!ll&&!rl&&r
15450524
MC/DC100%2/2
not $prop->{"cgi"} and $prop->{"parameters"}
not $prop->{"cgi"} $prop->{"parameters"}
Truth table100%3/3
not(A) and B
A= not $prop->{"cgi"}B= $prop->{"parameters"}
ABresult
0X0
100
111
348 24 $glob->parse_request_sigil_hmv($prop->{parameters});
349 }
350 }
351  
352 631 ▶sub configure_cgi {
Subroutine configure_cgi: called CC=6 SCAR=18.0
Pod undocumented
353 631 my PROP $prop = (my $glob = shift)->prop;
354 631 $prop->{cgi} = my $cgi = shift;
355 631 ▶ return unless $glob->is_form_content_type($cgi->content_type);
Branch: 1 branch
BranchTrueFalseTotal
unless $glob->is_form_content_type($cgi->content_type) 0 631 631
356 631 ▶ return if $prop->{parameters};
Branch: 1 branch
BranchTrueFalseTotal
if $prop->{"parameters"} 131 500 631
357  
358 #
359 # parse_request_sigil should be called before parse_nested_query.
360 #
361 500 ▶ if ($prop->{is_psgi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop->{'is_psgi'}) { } 484 16 500
362 484 $glob->parse_request_sigil_psgi($cgi);
363 } else {
364 16 $glob->parse_request_sigil_cgi($cgi);
365 }
366  
367 483 ▶ unless ($prop->{no_nested_query}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prop->{"no_nested_query"}) 483 0 483
368 483 ▶ if ($prop->{is_psgi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop->{'is_psgi'}) { } 467 16 483
369 467 $glob->convert_array_param_psgi($cgi);
370 } else {
371 16 $glob->convert_array_param_cgi($cgi);
372 }
373 }
374 }
375  
376 631 ▶sub is_form_content_type {
Subroutine is_form_content_type: called CC=5 SCAR=16.1
Pod undocumented
377 631 my ($self, $real_ct) = @_;
378 631 ▶ return 1 if ($real_ct // '') eq '';
Branch: 1 branch
BranchTrueFalseTotal
if ($real_ct // "") eq "" 607 24 631
Condition100%2/2
$real_ct // ""
l!l
24607
MC/DC100%1/1
$real_ct // ""
$real_ct
Truth table100%2/2
A
A= $real_ct
Aresult
11
00
379 24 foreach my $check_ct ($self->form_content_types) {
380 46 ▶ return 1 if $real_ct =~ $check_ct;
Branch: 1 branch
BranchTrueFalseTotal
if $real_ct =~ /$check_ct/ 24 22 46
381 }
382 0 return 0;
383 }
384  
385 24 ▶sub form_content_types {
Subroutine form_content_types: called CC=1 SCAR=0.0
Pod undocumented
386 24 (qr(^multipart/form-data\s*(?:;|$))i
387 , qr(^application/x-www-form-urlencoded$)i);
388 }
389  
390 505 ▶sub parse_nested_query {
Subroutine parse_nested_query: called CC=2 SCAR=7.6
Pod undocumented
391 505 my PROP $prop = (my $glob = shift)->prop;
392 505 my ($obj_or_string) = @_;
393 YATT::Lite::Util::parse_nested_query
394 ($obj_or_string
395 , (!$prop->{no_unicode_params} && $prop->{encoding})
396 505 ▶ );
Condition33%1/3
!$prop->{'no_unicode_params'} && $prop->{'encoding'}
!ll&&!rl&&r
00505
MC/DC0%0/2
!$prop->{'no_unicode_params'} && $prop->{'encoding'}
!$prop->{'no_unicode_params'} $prop->{'encoding'}
Truth table33%1/3
not(A) && B
A= !$prop->{'no_unicode_params'}B= $prop->{'encoding'}
ABresult
0X0
100
111
397 }
398  
399 467 ▶sub convert_array_param_psgi {
Subroutine convert_array_param_psgi: called CC=4 SCAR=13.9
Pod undocumented
400 467 my PROP $prop = (my $glob = shift)->prop;
401 467 my ($req) = @_;
402 467 $prop->{parameters} = do {
403 467 ▶ if ($glob->has_content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($glob->has_content) { } 22 445 467
404 22 my $body = $glob->parse_nested_query([$req->body_parameters->flatten]);
405 22 my $qs = $glob->parse_nested_query([$req->query_parameters->flatten]);
406 22 foreach my $key (keys %$qs) {
407 11 ▶ if (exists $body->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $body->{$key}) 0 11 11
408 0 die $glob->error("Attempt to overwrite a POST parameter '%s'"
409 . " by the same one in QUERY_STRING"
410 , $key);
411 }
412 11 $body->{$key} = $qs->{$key};
413 }
414 22 $body;
415 } else {
416 445 $glob->parse_nested_query([$req->query_parameters->flatten]);
417 }
418 };
419 }
420  
421 16 ▶sub convert_array_param_cgi {
Subroutine convert_array_param_cgi: called CC=3 SCAR=11.4
Pod undocumented
422 16 my PROP $prop = (my $glob = shift)->prop;
423 16 my ($cgi) = @_;
424 16 ▶ return if ($cgi->content_type // "") eq "application/json";
Branch: 1 branch
BranchTrueFalseTotal
if ($cgi->content_type // "") eq "application/json" 0 16 16
Condition50%1/2
$cgi->content_type // ""
l!l
016
MC/DC0%0/1
$cgi->content_type // ""
$cgi->content_type
Truth table50%1/2
A
A= $cgi->content_type
Aresult
11
00
425 $prop->{parameters}
426 16 = $glob->parse_nested_query($cgi->query_string);
427 }
428  
429 # Location(path part of url) of overall SiteApp.
430 10 ▶sub site_location {
Subroutine site_location: called CC=1 SCAR=0.0
Pod documented
431 10 shift->site_prefix . '/';
432 }
433 71 *site_loc = *site_location; *site_loc = *site_location;
434 75 ▶sub site_prefix {
Subroutine site_prefix: called CC=3 SCAR=11.0
Pod documented
435 75 my PROP $prop = (my $glob = shift)->prop;
436 # Note: This is safe because site_prefix 0 is meaningless(I hope).
437 75 ▶ $prop->{site_prefix} || do {
Branch: 1 branch
BranchTrueFalseTotal
$prop->{"site_prefix"} or do { my YATT::Lite::WebMVC0::Connection::Env $env = $prop->{"env"}; $env->{"yatt.script_name"} // "" } 26 49 75
438 49 my Env $env = $prop->{env};
439 49 ▶ $env->{'yatt.script_name'} // ''
Condition50%1/2
$env->{"yatt.script_name"} // ""
l!l
490
MC/DC0%0/1
$env->{"yatt.script_name"} // ""
$env->{"yatt.script_name"}
Truth table50%1/2
A
A= $env->{"yatt.script_name"}
Aresult
11
00
440 }
441 }
442  
443 # Location of DirApp
444 6 ▶sub location {
Subroutine location: called CC=2 SCAR=7.1
Pod documented
445 6 my PROP $prop = (my $glob = shift)->prop;
446 6 ▶ (my $loc = ($prop->{location} // '')) =~ s,/*$,/,;
Condition50%1/2
$prop->{"location"} // ""
l!l
60
MC/DC0%0/1
$prop->{"location"} // ""
$prop->{"location"}
Truth table50%1/2
A
A= $prop->{"location"}
Aresult
11
00
447 6 $loc;
448 }
449  
450 16 ▶sub _invoke_or {
Subroutine _invoke_or: called CC=3 SCAR=13.3
451 16 my ($default, $obj, $method, @args) = @_;
452 16 ▶ if (defined $obj and my $sub = $obj->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj and my $sub = $obj->can($method)) { } 16 0 16
Condition33%1/3
defined $obj and my $sub = $obj->can($method)
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $obj and my $sub = $obj->can($method)
defined $obj my $sub = $obj->can($method)
Truth table33%1/3
A and B
A= defined $objB= my $sub = $obj->can($method)
ABresult
0X0
100
111
453 16 $sub->($obj, @args)
454 } else {
455 0 $default;
456 }
457 }
458  
459 # XXX: parameter の加減算も?
460 # XXX: 絶対 path/相対 path の選択?
461 # scheme
462 # authority
463 # path
464 # query
465 # fragment
466 31 ▶sub mkurl {
Subroutine mkurl: called CC=2 SCAR=6.9
Pod documented
467 31 my PROP $prop = (my $glob = shift)->prop;
468 31 my ($file, $param, %opts) = @_;
469  
470 31 my $path = $glob->mkpath($file, $opts{mapped_path});
471  
472 # XXX: /../ truncation
473 # XXX: If sep is '&', scalar ref quoting is required.
474 # XXX: connection should have default separator.
475 31 my $url = '';
476 31 ▶ $url .= $glob->mkprefix unless $opts{local};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"local"} 14 17 31
477 31 $url .= $path . $glob->mkquery($param, $opts{separator});
478 31 $url;
479 }
480  
481 31 ▶sub mkpath {
Subroutine mkpath: called CC=8 SCAR=20.9
Pod documented
482 31 my PROP $prop = (my $glob = shift)->prop;
483 31 my ($file, $used_mapped_path) = @_;
484  
485 31 my $req = do {
486 31 ▶ if ($used_mapped_path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($used_mapped_path) { } 13 18 31
487 # GH-251: mapped_path reproduces the url path of the request
488 # (mount prefix included, request_file based).
489 13 scalar $glob->mapped_path;
490 } else {
491 18 $glob->request_path;
492 }
493 };
494  
495 31 ▶ if (defined $file and $file =~ m!^/!) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and $file =~ m[^/]) { } 0 31 31
Condition66%2/3
defined $file and $file =~ m[^/]
!ll&&!rl&&r
14170
MC/DC0%0/2
defined $file and $file =~ m[^/]
defined $file $file =~ m[^/]
Truth table66%2/3
A and B
A= defined $fileB= $file =~ m[^/]
ABresult
0X0
100
111
496 0 $glob->site_prefix.$file;
497 } else {
498 31 my ($orig, $dir) = ('');
499 31 ▶ if (($dir = $req) =~ s{([^/]+)$ }{}x) {
Branch: 1 branch
BranchTrueFalseTotal
if (($dir = $req) =~ s[([^/]+)$ ][]x) 27 4 31
500 27 $orig = $1;
501 }
502 31 ▶ if (not defined $file or $file eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $file or $file eq '') { } 25 6 31
elsif ($file eq '.') { } 2 4 6
Condition100%3/3
not defined $file or $file eq ""
l!l&&r!l&&!r
14116
MC/DC100%2/2
not defined $file or $file eq ""
not defined $file $file eq ""
Truth table100%3/3
not(A) or B
A= not defined $fileB= $file eq ""
ABresult
1X1
011
000
503 25 $dir . $orig;
504 } elsif ($file eq '.') {
505 2 $dir
506 } else {
507 4 $dir . $file;
508 }
509 }
510 }
511  
512 22 ▶sub mkprefix {
Subroutine mkprefix: called CC=3 SCAR=11.0
Pod documented
513 22 my PROP $prop = (my $glob = shift)->prop;
514 22 my Env $env = $prop->{env};
515 my $scheme
516 = $env->{HTTP_X_FORWARDED_PROTO}
517 22 ▶ || $env->{'psgi.url_scheme'} || $prop->{cgi}->protocol;
Condition83%5/6
$env->{'HTTP_X_FORWARDED_PROTO'} || $env->{'psgi.url_scheme'} || $prop->{'cgi'}->protocol
l!l&&r!l&&!r
1480
$env->{"HTTP_X_FORWARDED_PROTO"} or $env->{"psgi.url_scheme"}
l!l&&r!l&&!r
2128
MC/DC0%0/3
$env->{'HTTP_X_FORWARDED_PROTO'} || $env->{'psgi.url_scheme'} || $prop->{'cgi'}->protocol
$env->{"HTTP_X_FORWARDED_PROTO"} $env->{"psgi.url_scheme"} $prop->{'cgi'}->protocol
Truth table75%3/4
A or B || C
A= $env->{"HTTP_X_FORWARDED_PROTO"}B= $env->{"psgi.url_scheme"}C= $prop->{'cgi'}->protocol
ABCresult
1XX1
01X1
0011
0000
518 22 my $host = $glob->mkhost($scheme);
519 22 $scheme . '://' . $host . join("", @_);
520 }
521  
522 #
523 # $CON->has_htdebug($name): per-request cache of
524 # $SYS->has_htdebug($name) (YATT::Lite::WebMVC0::SiteApp), which does an
525 # %ENV lookup and a stat() of $app_root/.htdebug_$name every time.
526 # escape() consults this for every reference it is asked to print, so
527 # the answer is computed at most once per connection and name.
528 #
529 19 ▶sub has_htdebug {
Subroutine has_htdebug: called CC=6 SCAR=18.2
Pod undocumented
530 19 my PROP $prop = (my $glob = shift)->prop;
531 19 my ($name) = @_;
532 19 ▶ my $cache = $prop->{_htdebug_cache} //= {};
Condition100%2/2
$prop->{"_htdebug_cache"} //= {}
l!l
217
MC/DC100%1/1
$prop->{"_htdebug_cache"} //= {}
$prop->{"_htdebug_cache"}
Truth table100%2/2
A
A= $prop->{"_htdebug_cache"}
Aresult
11
00
533 19 ▶ return $cache->{$name} if exists $cache->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache->{$name} 2 17 19
534 17 $cache->{$name} = do {
535 17 my $sys = $prop->{system};
536 17 ▶ ($sys and $sys->can('has_htdebug')) ? ($sys->has_htdebug($name) // 0) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sys && $sys->can('has_htdebug') ? : 17 0 17
Condition60%3/5
$sys and $sys->can("has_htdebug")
!ll&&!rl&&r
0017
$sys->has_htdebug($name) // 0
l!l
314
MC/DC0%0/2
$sys and $sys->can("has_htdebug")
$sys $sys->can("has_htdebug")
MC/DC100%1/1
$sys->has_htdebug($name) // 0
$sys->has_htdebug($name)
Truth table33%1/3
A and B
A= $sysB= $sys->can("has_htdebug")
ABresult
0X0
100
111
Truth table100%2/2
A
A= $sys->has_htdebug($name)
Aresult
11
00
537 };
538 }
539  
540 # True if this request came over TLS (see YATT::Lite::PSGIEnv::is_https).
541 7 ▶sub is_https {
Subroutine is_https: called CC=6 SCAR=30.5
Pod undocumented
542 7 my PROP $prop = (my $glob = shift)->prop;
543 7 ▶ if (my Env $env = $prop->{env}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my YATT::Lite::WebMVC0::Connection::Env $env = $prop->{'env'}) { } 7 0 7
elsif (my $cgi = $prop->{'cgi'}) { } 0 0 0
544 7 Env->is_https($env);
545 } elsif (my $cgi = $prop->{cgi}) {
546 0 ▶ ($cgi->can('protocol') and lc($cgi->protocol // '') eq 'https') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cgi->can('protocol') && lc($cgi->protocol // '') eq 'https' ? : 0 0 0
Condition0%0/5
$cgi->can("protocol") and lc($cgi->protocol // "") eq "https"
!ll&&!rl&&r
000
$cgi->protocol // ""
l!l
00
MC/DC0%0/2
$cgi->can("protocol") and lc($cgi->protocol // "") eq "https"
$cgi->can("protocol") $cgi->protocol
Truth table0%0/3
A and B
A= $cgi->can("protocol")B= $cgi->protocol
ABresult
0X0
100
111
547 } else {
548 0 0;
549 }
550 }
551  
552 0 ▶sub http_host_domain {
Subroutine http_host_domain: not called CC=2 SCAR=17.9
Pod undocumented
553 0 my PROP $prop = (my $glob = shift)->prop;
554 0 my Env $env = $prop->{env};
555 my $host = $env->{HTTP_HOST}
556 0 ▶ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $host = $env->{"HTTP_HOST"} or return undef 0 0 0
557 0 $host =~ s/:\d+$//;
558 0 $host;
559 }
560  
561 0 ▶sub server_name_or_localhost {
Subroutine server_name_or_localhost: not called CC=3 SCAR=24.8
Pod undocumented
562 0 my PROP $prop = (my $glob = shift)->prop;
563 0 my ($default) = @_;
564 0 my Env $env = $prop->{env};
565 0 ▶ $env->{SERVER_NAME} || ($default // 'localhost');
Branch: 1 branch
BranchTrueFalseTotal
$env->{"SERVER_NAME"} or $default // "localhost" 0 0 0
Condition0%0/5
$env->{'SERVER_NAME'} || ($default // 'localhost')
l!l&&r!l&&!r
000
$default // "localhost"
l!l
00
MC/DC0%0/2
$env->{'SERVER_NAME'} || ($default // 'localhost')
$env->{'SERVER_NAME'} $default
Truth table0%0/3
A || B
A= $env->{'SERVER_NAME'}B= $default
ABresult
1X1
011
000
566 }
567  
568 43 ▶sub mkhost {
Subroutine mkhost: called CC=10 SCAR=28.2
Pod documented
569 43 my PROP $prop = (my $glob = shift)->prop;
570 43 my ($scheme) = @_;
571 43 ▶ $scheme ||= 'http';
Condition100%2/2
$scheme ||= "http"
l!l
367
MC/DC100%1/1
$scheme ||= "http"
$scheme
Truth table100%2/2
A
A= $scheme
Aresult
11
00
572 43 my Env $env = $prop->{env};
573  
574 # XXX? Is this secure?
575 43 ▶ return $env->{HTTP_HOST} if nonempty($env->{HTTP_HOST});
Branch: 1 branch
BranchTrueFalseTotal
if nonempty($env->{"HTTP_HOST"}) 35 8 43
576  
577 my $base = $env->{SERVER_NAME}
578 8 ▶ // _invoke_or('localhost', $prop->{cgi}, 'server_name');
Condition33%1/3
$env->{"SERVER_NAME"} // _invoke_or("localhost", $prop->{"cgi"}, "server_name")
l!l&&r!l&&!r
080
MC/DC0%0/2
$env->{"SERVER_NAME"} // _invoke_or("localhost", $prop->{"cgi"}, "server_name")
$env->{"SERVER_NAME"} _invoke_or("localhost", $prop->{"cgi"}, "server_name")
Truth table33%1/3
A // B
A= $env->{"SERVER_NAME"}B= _invoke_or("localhost", $prop->{"cgi"}, "server_name")
ABresult
1X1
011
000
579 8 ▶ if (my $port = $env->{SERVER_PORT}
Branch: 1 branch
BranchTrueFalseTotal
if (my $port = $env->{"SERVER_PORT"} || _invoke_or(80, $prop->{"cgi"}, "server_port")) 8 0 8
Condition33%1/3
$env->{'SERVER_PORT'} || _invoke_or(80, $prop->{'cgi'}, 'server_port')
l!l&&r!l&&!r
080
MC/DC0%0/2
$env->{'SERVER_PORT'} || _invoke_or(80, $prop->{'cgi'}, 'server_port')
$env->{'SERVER_PORT'} _invoke_or(80, $prop->{'cgi'}, 'server_port')
Truth table33%1/3
A || B
A= $env->{'SERVER_PORT'}B= _invoke_or(80, $prop->{'cgi'}, 'server_port')
ABresult
1X1
011
000
580 || _invoke_or(80, $prop->{cgi}, 'server_port')) {
581 8 ▶ $base .= ":$port" unless ($scheme eq 'http' and $port == 80
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme eq "http" and $port == 80 or $scheme eq "https" and $port == 443 0 8 8
Condition22%2/9
$scheme eq "http" and $port == 80 or $scheme eq "https" and $port == 443
l!l&&r!l&&!r
800
$scheme eq "http" and $port == 80
!ll&&!rl&&r
008
$scheme eq "https" and $port == 443
!ll&&!rl&&r
000
MC/DC0%0/4
$scheme eq "http" and $port == 80 or $scheme eq "https" and $port == 443
$scheme eq "http" $port == 80 $scheme eq "https" $port == 443
Truth table14%1/7
A and B or C and D
A= $scheme eq "http"B= $port == 80C= $scheme eq "https"D= $port == 443
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
582 or $scheme eq 'https' and $port == 443);
583 }
584 8 $base;
585 }
586  
587 102 ▶sub mkquery {
Subroutine mkquery: called CC=19 SCAR=30.2
Pod documented
588 102 my ($self, $param, $sep) = @_;
589 102 ▶ $sep //= '&';
Condition50%1/2
$sep //= "&"
l!l
0102
MC/DC0%0/1
$sep //= "&"
$sep
Truth table50%1/2
A
A= $sep
Aresult
11
00
590  
591 102 my @enc_param;
592 102 my ($fkeys, $fgetall);
593 102 ▶ if (not defined $param or not ref $param) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $param and ref $param) 62 40 102
Condition100%3/3
defined $param and ref $param
!ll&&!rl&&r
511140
MC/DC100%2/2
defined $param and ref $param
defined $param ref $param
Truth table100%3/3
A and B
A= defined $paramB= ref $param
ABresult
0X0
100
111
594 62 ▶ return wantarray ? () : '';
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 62 62
595 # nop
596 }
597  
598 40 ▶ if (UNIVERSAL::isa($param, ref $self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($param, ref $self)) 19 21 40
599 # $CON->mkquery($CON) == $CON->mkquery($CON->queryobj_for_mkquery)
600 19 $param = $param->queryobj_for_mkquery;
601 }
602  
603 40 ▶ if (ref $param eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $param eq 'HASH') { } 9 31 40
elsif ($fkeys = UNIVERSAL::can($param, 'keys') and $fgetall = UNIVERSAL::can($param, 'get_all') or $fkeys = $fgetall = UNIVERSAL::can($param, 'param')) { } 13 18 31
elsif (ref $param eq 'ARRAY') { } 18 0 18
604 push @enc_param, $self->url_encode($_).'='.$self->url_encode($param->{$_})
605 9 for sort keys %$param;
606 ▶ } elsif ($fkeys = UNIVERSAL::can($param, 'keys')
Condition66%4/6
$fkeys = UNIVERSAL::can($param, "keys") and $fgetall = UNIVERSAL::can($param, "get_all") or $fkeys = $fgetall = UNIVERSAL::can($param, "param")
l!l&&r!l&&!r
13018
$fkeys = UNIVERSAL::can($param, "keys") and $fgetall = UNIVERSAL::can($param, "get_all")
!ll&&!rl&&r
18013
MC/DC33%1/3
$fkeys = UNIVERSAL::can($param, "keys") and $fgetall = UNIVERSAL::can($param, "get_all") or $fkeys = $fgetall = UNIVERSAL::can($param, "param")
$fkeys = UNIVERSAL::can($param, "keys") $fgetall = UNIVERSAL::can($param, "get_all") $fkeys = $fgetall = UNIVERSAL::can($param, "param")
Truth table40%2/5
A and B or C
A= $fkeys = UNIVERSAL::can($param, "keys")B= $fgetall = UNIVERSAL::can($param, "get_all")C= $fkeys = $fgetall = UNIVERSAL::can($param, "param")
ABCresult
11X1
0X11
1011
0X00
1000
607 and $fgetall = UNIVERSAL::can($param, 'get_all')
608 or ($fkeys = $fgetall = UNIVERSAL::can($param, 'param'))) {
609 13 foreach my $key (YATT::Lite::Util::unique($fkeys->($param))) {
610 18 my $enc = $self->url_encode($key);
611 push @enc_param, "$enc=".$self->url_encode($_)
612 18 for $fgetall->($param, $key);
613 }
614 } elsif (ref $param eq 'ARRAY') {
615 18 ▶ if (grep {not defined} @$param) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not defined $_;} @$param) 0 18 18
616 0 croak "Undef found in mkquery()! " . YATT::Lite::Util::terse_dump($param);
617 }
618 18 my @list = @$param;
619 18 ▶ while (my ($key, $value) = splice @list, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@list, 0, 2)) 19 18 37
620 19 push @enc_param, $self->url_encode($key).'='.$self->url_encode($value);
621 }
622 }
623  
624 40 ▶ unless (@enc_param) {
Branch: 1 branch
BranchTrueFalseTotal
if (@enc_param) { } 37 3 40
625 3 ▶ wantarray ? () : '';
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
626 } else {
627 37 ▶ wantarray ? @enc_param : '?'.join($sep, @enc_param);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 37 37
628 }
629 }
630  
631 # GH-251: Mount-prefix aware link builders.
632 # Naming follows the widespread "*_path = path only / *_url = absolute URL"
633 # convention. $query accepts only HASH/ARRAY ref or query object (like $CON).
634  
635 39 ▶sub site_path {
Subroutine site_path: called CC=5 SCAR=16.1
Pod documented
636 39 my ($glob, $path, $query) = splice @_, 0, 3;
637 39 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 38 39
638 1 croak "Too many arguments for site_path!"
639 . " (query parameters must be passed as one HASH/ARRAY ref)";
640 }
641 38 ▶ if (not defined $path or $path eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $path or $path eq '') { } 16 22 38
elsif (not $path =~ m[^/]) { } 1 21 22
Condition66%2/3
not defined $path or $path eq ""
l!l&&r!l&&!r
16022
MC/DC50%1/2
not defined $path or $path eq ""
not defined $path $path eq ""
Truth table66%2/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
642 16 $path = '/';
643 } elsif ($path !~ m{^/}) {
644 1 croak "site_path requires a '/'-leading path: $path";
645 }
646 37 $glob->site_prefix . $path . $glob->_query_string_of(site_path => $query);
647 }
648  
649 1 ▶sub site_url {
Subroutine site_url: called CC=1 SCAR=0.0
Pod documented
650 1 my $glob = shift;
651 1 $glob->mkprefix . $glob->site_path(@_);
652 }
653  
654 28 ▶sub current_path {
Subroutine current_path: called CC=2 SCAR=6.9
Pod documented
655 28 my ($glob, $query) = splice @_, 0, 2;
656 28 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 27 28
657 1 croak "Too many arguments for current_path!"
658 . " (query parameters must be passed as one HASH/ARRAY ref)";
659 }
660 27 $glob->request_path . $glob->_query_string_of(current_path => $query);
661 }
662  
663 1 ▶sub current_url {
Subroutine current_url: called CC=1 SCAR=0.0
Pod documented
664 1 my $glob = shift;
665 1 $glob->mkprefix . $glob->current_path(@_);
666 }
667  
668 64 ▶sub _query_string_of {
Subroutine _query_string_of: called CC=3 SCAR=11.0
669 64 my ($glob, $caller, $query) = @_;
670 64 ▶ if (defined $query and not ref $query) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query and not ref $query) 1 63 64
Condition100%3/3
defined $query and not ref $query
!ll&&!rl&&r
35281
MC/DC100%2/2
defined $query and not ref $query
defined $query not ref $query
Truth table100%3/3
A and not(B)
A= defined $queryB= not ref $query
ABresult
0X0
100
111
671 1 croak "query for $caller must be a HASH/ARRAY ref or query object: $query";
672 }
673 63 scalar $glob->mkquery($query);
674 }
675  
676 46 ▶sub dir_location {
Subroutine dir_location: called CC=3 SCAR=11.7
Pod documented
677 46 my PROP $prop = (my $glob = shift)->prop;
678 46 my Env $env = $prop->{env};
679 46 ▶ ($env->{'yatt.script_name'} // '').($prop->{location} // "/");
Condition50%2/4
$env->{"yatt.script_name"} // ""
l!l
460
$prop->{"location"} // "/"
l!l
460
MC/DC0%0/1
$env->{"yatt.script_name"} // ""
$env->{"yatt.script_name"}
MC/DC0%0/1
$prop->{"location"} // "/"
$prop->{"location"}
Truth table50%1/2
A
A= $env->{"yatt.script_name"}
Aresult
11
00
Truth table50%1/2
A
A= $prop->{"location"}
Aresult
11
00
680 }
681  
682 0 ▶sub file_page {
Subroutine file_page: not called CC=1 SCAR=6.9
Pod undocumented
683 0 my PROP $prop = (my $glob = shift)->prop;
684 0 my $fn = $prop->{file};
685 0 $fn =~ s/\.\w+\z//;
686 0 $fn;
687 }
688  
689 # The url path of the current page: dir_location + request_file.
690 # GH-251: Like mapped_path, this follows how the request spelled the
691 # file name (Apache content-negotiation model: the requested name is
692 # the base name; negotiation just appends extensions to it).
693 #
694 33 ▶sub file_location {
Subroutine file_location: called CC=4 SCAR=14.6
Pod documented
695 33 my PROP $prop = (my $glob = shift)->prop;
696 33 my Env $env = $prop->{env};
697 33 my $loc = $glob->dir_location;
698 33 ▶ if (defined (my $rf = $prop->{request_file})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $rf = $prop->{'request_file'})) { } 32 1 33
elsif (not $prop->{'is_index'} and my $fn = $prop->{'file'}) { } 1 0 1
699 32 $loc . $rf;
700 ▶ } elsif (not $prop->{is_index} and my $fn = $prop->{file}) {
Condition33%1/3
not $prop->{"is_index"} and my $fn = $prop->{"file"}
!ll&&!rl&&r
001
MC/DC0%0/2
not $prop->{"is_index"} and my $fn = $prop->{"file"}
not $prop->{"is_index"} my $fn = $prop->{"file"}
Truth table33%1/3
not(A) and B
A= not $prop->{"is_index"}B= my $fn = $prop->{"file"}
ABresult
0X0
100
111
701 # Fallback for old-style connections without request_file:
702 # trim the last extension ("foo.tar.yatt" => "foo.tar").
703 1 $fn =~ s/\.\w+\z//;
704 1 $loc . $fn;
705 } else {
706 0 $loc;
707 }
708 }
709  
710 # page_location: canonical form of file_location, based on the
711 # physical file name. Unlike file_location, this is NOT affected by
712 # how the request spelled the url.
713 # (page = spelling-independent identity, cf. is_current_page)
714 13 ▶sub page_location {
Subroutine page_location: called CC=3 SCAR=11.0
Pod documented
715 13 my PROP $prop = (my $glob = shift)->prop;
716 13 my $loc = $glob->dir_location;
717 13 ▶ if (not $prop->{is_index} and my $fn = $prop->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $prop->{"is_index"} and my $fn = $prop->{"file"}) 11 2 13
Condition66%2/3
not $prop->{"is_index"} and my $fn = $prop->{"file"}
!ll&&!rl&&r
2011
MC/DC50%1/2
not $prop->{"is_index"} and my $fn = $prop->{"file"}
not $prop->{"is_index"} my $fn = $prop->{"file"}
Truth table66%2/3
not(A) and B
A= not $prop->{"is_index"}B= my $fn = $prop->{"file"}
ABresult
0X0
100
111
718 11 $fn =~ s/\.\w+\z//;
719 11 $loc .= $fn;
720 }
721 13 $loc;
722 }
723  
724 # is_current_file($path): true when $path addresses the current page.
725 # $path is a site-rooted literal (same form as site_path's argument):
726 # canonical (/auth/login), physical (/auth/login.yatt), or directory
727 # form for index pages (/auth/). Mount prefix and request spelling
728 # do not affect the result. Subpath is ignored (cf. is_current_page).
729 6 ▶sub is_current_file {
Subroutine is_current_file: called CC=7 SCAR=19.6
Pod documented
730 6 my PROP $prop = (my $glob = shift)->prop;
731 6 my ($path) = @_;
732 6 ▶ return 0 unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 6 6
733 6 my $loc = $glob->location;
734 6 ▶ my $fn = $prop->{file} // '';
Condition50%1/2
$prop->{"file"} // ""
l!l
60
MC/DC0%0/1
$prop->{"file"} // ""
$prop->{"file"}
Truth table50%1/2
A
A= $prop->{"file"}
Aresult
11
00
735 6 (my $canon = $fn) =~ s/\.\w+\z//;
736 6 ▶ return 1 if $path eq $loc . $canon;
Branch: 1 branch
BranchTrueFalseTotal
if $path eq $loc . $canon 2 4 6
737 4 ▶ return 1 if $path eq $loc . $fn;
Branch: 1 branch
BranchTrueFalseTotal
if $path eq $loc . $fn 1 3 4
738 3 ▶ return 1 if $prop->{is_index} and $path eq $loc;
Branch: 1 branch
BranchTrueFalseTotal
if $prop->{"is_index"} and $path eq $loc 1 2 3
Condition66%2/3
$prop->{"is_index"} and $path eq $loc
!ll&&!rl&&r
201
MC/DC50%1/2
$prop->{"is_index"} and $path eq $loc
$prop->{"is_index"} $path eq $loc
Truth table66%2/3
A and B
A= $prop->{"is_index"}B= $path eq $loc
ABresult
0X0
100
111
739 2 0;
740 }
741  
742 576 ▶sub is_current_page {
Subroutine is_current_page: called CC=6 SCAR=18.0
Pod documented
743 576 my PROP $prop = (my $glob = shift)->prop;
744 576 my ($file, $page) = do {
745 576 ▶ @_ <= 1 ? (rootname($prop->{file}), $_[0]) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 1 ? : 576 0 576
746 };
747 576 ▶ rootname($prop->{file}) eq $file
Branch: 1 branch
BranchTrueFalseTotal
rootname($prop->{"file"}) eq $file or return 0 576 0 576
748 or return 0;
749 576 ▶ $page //= '';
Condition100%2/2
$page //= ""
l!l
48096
MC/DC100%1/1
$page //= ""
$page
Truth table100%2/2
A
A= $page
Aresult
11
00
750 576 $page =~ s{^/}{}; # Treat /foo as foo.
751 576 ▶ if (empty(my $subpath = $prop->{subpath})) {
Branch: 2 branches
BranchTrueFalseTotal
if (empty(my $subpath = $prop->{'subpath'})) { } 192 384 576
elsif ($page eq '') { } 128 256 384
752 192 $page eq '';
753 } elsif ($page eq '') {
754 128 0
755 } else {
756 256 $subpath =~ m{^/$page};
757 }
758 }
759  
760 # GH-251: mapped_path now reproduces the url path of the request:
761 # site_prefix + location + request_file + subpath. Since request_file
762 # keeps the file name part as it appeared in the request, extension
763 # is reproduced only when the request spelled it. For connections
764 # which lack request_file (old-style construction), falls back to
765 # the physical file name as before.
766 28 ▶sub mapped_path {
Subroutine mapped_path: called CC=7 SCAR=19.5
Pod documented
767 28 my PROP $prop = (my $glob = shift)->prop;
768 28 my @path = do {
769 28 ▶ my $loc = $prop->{location} // "/";
Condition100%2/2
$prop->{"location"} // "/"
l!l
262
MC/DC100%1/1
$prop->{"location"} // "/"
$prop->{"location"}
Truth table100%2/2
A
A= $prop->{"location"}
Aresult
11
00
770 28 ▶ $loc .= $prop->{request_file} // do {
Condition66%2/3
$prop->{"request_file"} // do { defined $prop->{"file"} && !$prop->{"is_index"} ? $prop->{"file"} : "" }
l!l&&r!l&&!r
18100
MC/DC0%0/2
$prop->{"request_file"} // do { defined $prop->{"file"} && !$prop->{"is_index"} ? $prop->{"file"} : "" }
$prop->{"request_file"} do { defined $prop->{"file"} && !$prop->{"is_index"} ? $prop->{"file"} : "" }
Truth table66%2/3
A // B
A= $prop->{"request_file"}B= do { defined $prop->{"file"} && !$prop->{"is_index"} ? $prop->{"file"} : "" }
ABresult
1X1
011
000
771 (defined $prop->{file} and not $prop->{is_index})
772 10 ▶ ? $prop->{file} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $prop->{'file'} && !$prop->{'is_index'} ? : 3 7 10
Condition100%3/3
defined $prop->{"file"} and not $prop->{"is_index"}
!ll&&!rl&&r
253
MC/DC100%2/2
defined $prop->{"file"} and not $prop->{"is_index"}
defined $prop->{"file"} not $prop->{"is_index"}
Truth table100%3/3
A and not(B)
A= defined $prop->{"file"}B= not $prop->{"is_index"}
ABresult
0X0
100
111
773 };
774 28 ($glob->site_prefix . $loc);
775 };
776 28 ▶ if (defined (my $sp = $prop->{subpath})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $sp = $prop->{"subpath"})) 26 2 28
777 26 $path[0] =~ s!/+\z!!;
778 26 $sp =~ s!^/*!/!;
779 26 push @path, $sp;
780 }
781 28 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 5 23 28
782 5 @path;
783 } else {
784 23 my $res = join "", @path;
785 23 $res =~ s!^/+!/!;
786 23 $res;
787 }
788 }
789  
790 46 ▶sub request_path {
Subroutine request_path: called CC=2 SCAR=6.9
Pod documented
791 46 ▶ (my $uri = shift->request_uri // '') =~ s/\?.*//;
Condition100%2/2
(shift())->request_uri // ""
l!l
451
MC/DC100%1/1
(shift())->request_uri // ""
(shift())->request_uri
Truth table100%2/2
A
A= (shift())->request_uri
Aresult
11
00
792 46 $uri;
793 }
794  
795 46 ▶sub request_uri {
Subroutine request_uri: called CC=4 SCAR=15.2
Pod documented
796 46 my PROP $prop = (my $glob = shift)->prop;
797 46 ▶ if (my Env $env = $prop->{env}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my YATT::Lite::WebMVC0::Connection::Env $env = $prop->{'env'}) { } 45 1 46
elsif ($prop->{'cgi'} and my $sub = $prop->{'cgi'}->can('request_uri')) { } 0 1 1
798 45 $env->{REQUEST_URI};
799 ▶ } elsif ($prop->{cgi}
Condition33%1/3
$prop->{"cgi"} and my $sub = $prop->{"cgi"}->can("request_uri")
!ll&&!rl&&r
100
MC/DC0%0/2
$prop->{"cgi"} and my $sub = $prop->{"cgi"}->can("request_uri")
$prop->{"cgi"} my $sub = $prop->{"cgi"}->can("request_uri")
Truth table33%1/3
A and B
A= $prop->{"cgi"}B= my $sub = $prop->{"cgi"}->can("request_uri")
ABresult
0X0
100
111
800 and my $sub = $prop->{cgi}->can('request_uri')) {
801 0 $sub->($prop->{cgi});
802 } else {
803 1 $ENV{REQUEST_URI};
804 }
805 }
806  
807 #========================================
808  
809 # True if $url, given as a plain string, stays on this origin:
810 # a path or relative reference, or an absolute http(s) url whose host
811 # equals mkhost. Written against how browsers parse Location:, not
812 # against RFC 3986 alone: for http(s), '\' is treated as '/', runs of
813 # slashes after the scheme collapse, and leading C0 controls / spaces
814 # are stripped before parsing. So "\\evil", "/\evil", "///evil",
815 # "http:\\evil" and " //evil" all mean evil.example to a browser and
816 # are rejected here.
817 78 ▶sub is_same_origin_redirect_url {
Subroutine is_same_origin_redirect_url: called CC=15 SCAR=27.1
Pod documented
818 78 my ($glob, $url) = @_;
819 78 ▶ return 0 unless defined $url and length $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and length $url 1 77 78
Condition66%2/3
defined $url and length $url
!ll&&!rl&&r
0177
MC/DC50%1/2
defined $url and length $url
defined $url length $url
Truth table66%2/3
A and B
A= defined $urlB= length $url
ABresult
0X0
100
111
820  
821 # Control chars (CR/LF would split the header) and whitespace.
822 77 ▶ return 0 if $url =~ /[\x00-\x20\x7f]/;
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ /[\x00-\x20\x7f]/ 12 65 77
823  
824 65 ▶ if ($url =~ m{^([A-Za-z][A-Za-z0-9+.-]*):(.*)\z}s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /^([A-Za-z][A-Za-z0-9+.-]*):(.*)\z/s) 28 37 65
825 # Has a scheme. Only http(s) to this very host is accepted.
826 28 my ($scheme, $rest) = (lc($1), $2);
827 28 ▶ return 0 unless $scheme eq 'http' or $scheme eq 'https';
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme eq "http" or $scheme eq "https" 4 24 28
Condition100%3/3
$scheme eq "http" or $scheme eq "https"
l!l&&r!l&&!r
2044
MC/DC100%2/2
$scheme eq "http" or $scheme eq "https"
$scheme eq "http" $scheme eq "https"
Truth table100%3/3
A or B
A= $scheme eq "http"B= $scheme eq "https"
ABresult
1X1
011
000
828 24 ▶ my ($host) = $rest =~ m{^//([^/?#\\]+)(?:[/?#]|\z)}
Branch: 1 branch
BranchTrueFalseTotal
my($host) = $rest =~ m(^//([^/?#\\]+)(?:[/?#]|\z)) or return 0 14 10 24
829 or return 0;
830 14 ▶ return lc($host) eq lc($glob->mkhost($scheme) // '') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
lc $host eq lc($glob->mkhost($scheme) // '') ? : 2 12 14
Condition50%1/2
$glob->mkhost($scheme) // ""
l!l
140
MC/DC0%0/1
$glob->mkhost($scheme) // ""
$glob->mkhost($scheme)
Truth table50%1/2
A
A= $glob->mkhost($scheme)
Aresult
11
00
831 }
832  
833 37 ▶ if ($url =~ m{^//([^/?#\\]+)(?:[/?#]|\z)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m(^//([^/?#\\]+)(?:[/?#]|\z))) 4 33 37
834 # Scheme-relative "//host/...": accepted only for this host.
835 4 ▶ return lc($1) eq lc($glob->mkhost // '') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
lc $1 eq lc($glob->mkhost // '') ? : 2 2 4
Condition50%1/2
$glob->mkhost // ""
l!l
40
MC/DC0%0/1
$glob->mkhost // ""
$glob->mkhost
Truth table50%1/2
A
A= $glob->mkhost
Aresult
11
00
836 }
837  
838 33 ▶ if ($url =~ m{^[/\\]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m(^[/\\])) 25 8 33
839 # A path. Exactly one leading '/', not followed by '/' or '\'.
840 25 ▶ return $url =~ m{^/(?![/\\])} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m(^/(?![/\\])) ? : 13 12 25
841 }
842  
843 # Relative reference ("./", "index?x=1", "?x=1", "#frag").
844 8 1;
845 }
846  
847 # GH-251: raise_redirect is the preferred name (raise_* family tells
848 # this never returns to the caller). redirect is kept for compatibility.
849 71 *raise_redirect = *redirect; *raise_redirect = *redirect;
850 83 ▶sub redirect {
Subroutine redirect: called CC=6 SCAR=18.4
Pod documented
851 83 my PROP $prop = (my $glob = shift)->prop;
852 83 ▶ croak "undefined url" unless @_ and defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and defined $_[0] 0 83 83
Condition33%1/3
@_ and defined $_[0]
!ll&&!rl&&r
0083
MC/DC0%0/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table33%1/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
853 83 my $url = do {
854 83 ▶ if (ref $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0]) { } 5 78 83
elsif ($glob->is_same_origin_redirect_url($_[0])) { } 25 53 78
855 # To do external redirect, $url should pass as SCALAR REF.
856 5 my $arg = shift;
857 # die "redirect url is not a scalar ref: $arg";
858 5 $$arg;
859 } elsif ($glob->is_same_origin_redirect_url($_[0])) {
860 25 shift;
861 } else {
862 53 die $glob->error_with_status(
863 400, "External redirect is not allowed: %s"
864 , YATT::Lite::Util::escape($_[0])
865 );
866 }
867 };
868 30 ▶ if ($prop->{_header_was_sent}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop->{"_header_was_sent"}++) 0 30 30
869 0 die "Can't redirect multiple times!";
870 }
871  
872 # Make sure session is flushed before redirection.
873 30 $glob->finalize_headers;
874  
875 30 ${$prop->{buffer}} = '';
876  
877 30 die [302, [Location => $url, $glob->list_header], []];
878 }
879  
880 #========================================
881 # Session support is delegated to 'system'.
882 # 'system' must implement session_{start,resume,flush,destroy}
883  
884 # To avoid confusion against $system->session_$verb,
885 # connection side interface is named ${verb}_session.
886  
887 45 ▶sub get_session {
Subroutine get_session: called CC=2 SCAR=6.9
Pod documented
888 45 my PROP $prop = (my $glob = shift)->prop;
889 # To avoid repeative false session tests.
890 45 ▶ if (exists $prop->{_session}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $prop->{'_session'}) { } 37 8 45
891 37 $prop->{_session};
892 } else {
893 8 $prop->{system}->session_resume($glob);
894 }
895 }
896  
897 0 ▶sub start_session {
Subroutine start_session: not called CC=2 SCAR=17.9
Pod documented
898 0 my PROP $prop = (my $glob = shift)->prop;
899 0 ▶ if (defined (my $sess = $prop->{_session})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $sess = $prop->{"_session"})) 0 0 0
900 0 die $glob->error("load_session is called twice! sid=%s", $sess->id);
901 }
902 0 $prop->{system}->session_start($glob, @_);
903 }
904  
905 0 ▶sub delete_session {
Subroutine delete_session: not called CC=1 SCAR=6.9
Pod documented
906 0 my PROP $prop = (my $glob = shift)->prop;
907 0 $prop->{system}->session_delete($glob);
908 }
909  
910 0 ▶sub flush_session {
Subroutine flush_session: not called CC=1 SCAR=6.9
Pod documented
911 0 my PROP $prop = (my $glob = shift)->prop;
912 0 $prop->{system}->session_flush($glob);
913 }
914  
915 #========================================
916  
917 0 ▶sub current_user {
Subroutine current_user: not called CC=5 SCAR=34.0
Pod documented
918 0 my PROP $prop = (my $glob = shift)->prop;
919 0 my $cu = do {
920 0 ▶ if (exists $prop->{_current_user}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $prop->{'_current_user'}) { } 0 0 0
elsif (defined $prop->{'system'}) { } 0 0 0
921 $prop->{_current_user}
922 0 } elsif (defined $prop->{system}) {
923 0 $prop->{_current_user} = $prop->{system}->load_current_user($glob);
924 } else {
925 0 $prop->{_current_user} = undef;
926 }
927 };
928  
929 0 ▶ return $cu unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
930 0 ▶ die $glob->error("current_user is empty") unless defined $cu;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cu 0 0 0
931 0 my $method = shift;
932  
933 0 $cu->$method(@_);
934 }
935  
936 #========================================
937  
938 71 ▶use YATT::Lite::RegexpNames; # For re_name, re_integer, ...
Subroutine BEGIN: called CC=1 SCAR=0.0
939  
940 2 ▶sub param_type {
Subroutine param_type: called CC=11 SCAR=27.4
Pod documented
941 2 my PROP $prop = (my $glob = shift)->prop;
942 2 ▶ my $name = shift // croak "Undefined name!";
Condition50%1/2
shift() // croak("Undefined name!")
l!l
20
MC/DC0%0/1
shift() // croak("Undefined name!")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
943 2 ▶ my $type = shift // croak "Undefined type!";
Condition50%1/2
shift() // croak("Undefined type!")
l!l
20
MC/DC0%0/1
shift() // croak("Undefined type!")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
944 2 my $diag = shift;
945 2 my $opts = shift;
946 2 ▶ my $pat = ref $type eq 'Regexp' ? $type : do {
Branch: 1 branch
BranchTrueFalseTotal
ref $type eq 'Regexp' ? : 0 2 2
947 2 ▶ my $pat_sub = $glob->can("re_$type")
Branch: 1 branch
BranchTrueFalseTotal
my $pat_sub = $glob->can("re_$type") or croak("Unknown type: $type") 2 0 2
948 or croak "Unknown type: $type";
949 2 $pat_sub->();
950 };
951  
952 2 my $value = $glob->param($name);
953  
954 2 ▶ if (defined $value && $value =~ $pat) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $value and $value =~ /$pat/) { } 0 2 2
elsif ($diag) { } 0 2 2
elsif (not defined $value) { } 1 1 2
Condition66%2/3
defined $value and $value =~ /$pat/
!ll&&!rl&&r
110
MC/DC0%0/2
defined $value and $value =~ /$pat/
defined $value $value =~ /$pat/
Truth table66%2/3
A and B
A= defined $valueB= $value =~ /$pat/
ABresult
0X0
100
111
955 0 return $&; # Also for taint check.
956 } elsif ($diag) {
957 0 ▶ die $glob->error_with_status
Branch: 1 branch
BranchTrueFalseTotal
ref $diag eq 'CODE' ? : 0 0 0
958 (400, (ref $diag eq 'CODE' ? $diag->($value) : $diag)
959 , $name, $value);
960 } elsif (not defined $value) {
961 1 ▶ return undef if $opts->{allow_undef};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"allow_undef"} 0 1 1
962 1 die $glob->error_with_status
963 (400, "Parameter '%s' is missing!", $name);
964 } else {
965 # Just for default message. Production code should provide $diag.
966 1 die $glob->error_with_status
967 (400, "Parameter '%s' must match %s!: '%s'"
968 , $name, $type, $value);
969 }
970 }
971  
972 #========================================
973  
974 4 ▶sub accept_language {
Subroutine accept_language: called CC=15 SCAR=35.8
Pod documented
975 4 my PROP $prop = (my $glob = shift)->prop;
976 4 my (%opts) = @_;
977 4 my $filter = delete $opts{filter};
978 4 my $detail = delete $opts{detail};
979 4 my $long = delete $opts{long};
980 4 ▶ if (keys %opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %opts) 0 4 4
981 0 die $glob->error("Unknown option for accept_language: %s"
982 , join ", ", keys %opts);
983 }
984  
985 4 my Env $env = $prop->{env};
986 my $langlist = $env->{HTTP_ACCEPT_LANGUAGE}
987 4 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
my $langlist = $env->{"HTTP_ACCEPT_LANGUAGE"} or return 4 0 4
988 my @langlist = sort {
989 12 $$b[-1] <=> $$a[-1]
990 } map {
991 4 my ($lang, $qual) = split /\s*;\s*q=/;
992 12 ▶ [$lang, $qual // 1]
Condition100%2/2
$qual // 1
l!l
84
MC/DC100%1/1
$qual // 1
$qual
Truth table100%2/2
A
A= $qual
Aresult
11
00
993 } split /\s*,\s*/, $langlist;
994  
995 4 ▶ if ($filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) 0 4 4
996 0 my $filtsub = do {
997 0 ▶ if (ref $filter eq 'CODE') {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $filter eq 'CODE') { } 0 0 0
elsif (ref $filter eq 'Regexp') { } 0 0 0
elsif (ref $filter eq 'HASH') { } 0 0 0
elsif (ref $filter eq 'ARRAY') { } 0 0 0
998 0 $filter
999 } elsif (ref $filter eq 'Regexp') {
1000 0 ▶ sub { grep {$$_[0] =~ $filter} @_ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1001 0 } elsif (ref $filter eq 'HASH') {
1002 0 ▶ sub { grep {$filter->{$$_[0]}} @_ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1003 0 } elsif (ref $filter eq 'ARRAY') {
1004 0 my $hash = +{map {$_ => 1} lexpand($filter)};
1005 0 ▶ sub { grep {$hash->{$$_[0]}} @_ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1006 0 } else {
1007 0 die $glob->error("Unknown filter type for accept_language");
1008 }
1009 };
1010 0 @langlist = $filtsub->(@langlist);
1011 }
1012  
1013 4 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) { } 1 3 4
1014 @langlist
1015 1 } else {
1016 3 ▶ if ($long) {
Branch: 1 branch
BranchTrueFalseTotal
if ($long) { } 1 2 3
1017 # en-US => en_US
1018 1 $$_[0] =~ s/-/_/g for @langlist;
1019 } else {
1020 # en-US => en
1021 2 $$_[0] =~ s/-.*// for @langlist;
1022 }
1023 3 my %dup;
1024 3 ▶ wantarray ? (map {$dup{$$_[0]}++ ? () : $$_[0]} @langlist)
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 2 1 3
$dup{$_->[0]}++ ? : 1 5 6
1025 : $langlist[0][0];
1026 }
1027 }
1028  
1029 71 1;
« blib/lib/YATT/Lite/LRXML/AltTree.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/DirApp.pm »