lib/WebDyne/Request/Fake.pm

filter: Statementstmt 50.0% 189 / 378 Branchbran 36.0% 44 / 122 Conditioncond 24.7% 23 / 93 MC/DCmcdc 1.8% 1 / 54 Subroutinesub 34.7% 41 / 118 Podpod 0.0% 0 / 57 totaltotal 36.2% 298 / 822 CC 102 SCAR 28.4
CC
102
Cov
43%
location
103.3
dir_config
56.9
notes
30.0
CRAP 17.1
« blib/lib/WebDyne/HTML/Tiny.pm ↑ Summary blib/lib/WebDyne/Request/Common.pm »
1  
2 #
3 # This file is part of WebDyne.
4 #
5 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
6 #
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 #
10 # Full license text is available at:
11 #
12 # <http://dev.perl.org/licenses/>
13 #
14  
15  
16 package WebDyne::Request::Fake;
17  
18  
19 # Compiler Pragma
20 #
21 5 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use vars qw($VERSION $AUTOLOAD %Package);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27 # External modules
28 #
29 5 ▶use Cwd qw(fastcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use HTTP::Status qw(status_message HTTP_OK HTTP_NOT_FOUND HTTP_FOUND);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use HTTP::Headers::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use HTTP::Negotiate qw(choose);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use HTTP::AcceptLanguage;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶use HTTP::Headers::Util qw(split_header_words);
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 5 ▶use File::Spec::Unix;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 5 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 5 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 5 ▶use WebDyne::Request::Common qw(handler_methods_all handler_methods_check);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 5 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44  
45 # Version information
46 #
47 5 $VERSION='3.029';
48  
49  
50 # Debug load
51 #
52 5 debug("Loading %s version $VERSION", __PACKAGE__);
53  
54  
55 # Run init code for utility accessors unless already done. Picked method() as arbitrary test
56 #
57 5 ▶&init() unless defined(&method);
Branch: 1 branch
BranchTrueFalseTotal
unless defined &WebDyne::Request::Fake::method 5 0 5
58  
59  
60 # All done. Positive return
61 #
62 5 1;
63  
64  
65 #==================================================================================================
66  
67  
68 5 ▶sub init {
Subroutine init: called CC=7 SCAR=29.3
Pod undocumented
69  
70  
71 # Do ENV filtering here
72 #
73 local %ENV=(
74 2 (map { $_=>$ENV{$_} } (
75 82 grep { defined($ENV{$_}) } (qw(
76 DOCUMENT_DEFAULT
77 DOCUMENT_ROOT
78 REQUEST_METHOD
79 REQUEST_URI
80 PATH_INFO
81 SCRIPT_NAME
82 QUERY_STRING
83 SERVER_PROTOCOL
84 SERVER_NAME
85 SERVER_PORT
86 REMOTE_ADDR
87 REMOTE_PORT
88 REMOTE_USER
89 AUTH_TYPE
90 HTTPS
91 APPL_MD_PATH
92 ),
93 172 (grep {/^WEBDYNE/i} keys %ENV), # Note not WEBDYNE_, just /WEBDYNE/i to allow for DirConfig type entries such as WebDyneHandler
94 172 (grep {/^HTTP_/i} keys %ENV),
95 5 (grep {/^CONTENT_/i} keys %ENV)
96 )))
97 );
98  
99  
100 # Setup pass through methods
101 #
102 my %method=(
103 0 ▶ accept_encoding => sub { shift()->headers_in('accept-encoding') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 0 ▶ accept_language => sub { shift()->headers_in('accept-language') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
105 0 ▶ accept => sub { shift()->headers_in('accept') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 16 ▶ args => sub { shift()->env->{'QUERY_STRING'} },
Subroutine __ANON__: called CC=1 SCAR=0.0
107 as_string => undef,
108 0 ▶ authority => sub { shift()->uri->authority },
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 0 ▶ authorization => sub { shift()->headers_in('authorization') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 ▶ auth_type => sub { shift()->{'env'}->{'AUTH_TYPE'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 base => 'base_url',
112 #base_url => sub { URI->new($_[0]->host . $_[0]->script_name()) },
113 0 ▶ base_url => sub { my $uri_or=shift()->uri->canonical->clone; $uri_or->path('/'), $uri_or->query(undef); $uri_or },
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 0 ▶ body_handle => sub { shift->{'input'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
115 body => undef,
116 0 ▶ cache_control => sub { shift()->headers_in('cache-control') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 0 ▶ charset => sub { my $content_type=shift()->content_type || return; (my @split=split_header_words($content_type)) || return; my %param=@{$split[0]}; return lc($param{'charset'}) },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
my(@split) = split_header_words($content_type) or return 0 0 0
Condition0%0/2
(shift())->content_type || (return)
l!l
00
MC/DC0%0/1
(shift())->content_type || (return)
(shift())->content_type
Truth table0%0/2
A
A= (shift())->content_type
Aresult
11
00
118 cleanup_register => undef,
119 0 ▶ client_address => sub { shift()->env->{'REMOTE_ADDR'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
120 content => 'body',
121 0 ▶ content_encoding => sub { shift()->headers_in('content-encoding') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 content_length => undef,
123 content_type => undef,
124 cookie => 'cookies',
125 cookies => undef,
126 custom_response => undef,
127 cwd => undef,
128 dir_config => undef,
129 document_root => undef,
130 26 ▶ env => sub { \%ENV },
Subroutine __ANON__: called CC=1 SCAR=0.0
131 0 ▶ etag => sub { shift()->headers_out('etag', @_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
132 filename => undef,
133 finalize => undef,
134 finfo => undef,
135 form_parameters => undef,
136 0 ▶ forwarded_for => sub { shift()->headers_in('x-forwarded-for') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
137 0 ▶ fragment => sub { shift()->uri->fragment },
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 handler => undef,
139 header => 'headers_in',
140 headers => 'headers_in',
141 header_only => undef,
142 headers_in => undef,
143 headers_out => undef,
144 0 ▶ hostname => sub { shift()->env->{'SERVER_NAME'} }, # Prob should be local host name
Subroutine __ANON__: not called CC=1 SCAR=6.9
145 #host => sub { shift()->uri->host if $_[0]->uri->authority },
146 0 ▶ host => sub { shift()->headers_in('host') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
147 0 ▶ https => sub { shift()->env->{'HTTPS'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
148 http_version => 'protocol',
149 id => undef,
150 0 ▶ if_modified_since => sub { shift()->headers_in('if-modified-since') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
151 0 ▶ if_none_match => sub { shift()->headers_in('if-none-match') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
152 0 ▶ input => sub { shift()->{'input'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
153 0 ▶ is_ajax => sub { (shift()->headers_in('x-requested-with') eq 'XMLHttpRequest') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
154 is_main => undef,
155 location => undef,
156 log_error => undef,
157 lookup_file => undef,
158 lookup_uri => undef,
159 main => undef,
160 0 ▶ media_type => sub { my $content_type=shift()->content_type || return; (my @split=split_header_words($content_type)) || return; return lc($split[0][0]) },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
my(@split) = split_header_words($content_type) or return 0 0 0
Condition0%0/2
(shift())->content_type || (return)
l!l
00
MC/DC0%0/1
(shift())->content_type || (return)
(shift())->content_type
Truth table0%0/2
A
A= (shift())->content_type
Aresult
11
00
161 8 ▶ method => sub { shift->env->{'REQUEST_METHOD'} || 'GET' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->env->{"REQUEST_METHOD"} or "GET" 0 8 8
162 mtime => undef,
163 multipart_parameters=> undef,
164 next => undef,
165 notes => undef,
166 0 ▶ origin => sub { shift()->headers_in('origin') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
167 output_filters => undef,
168 0 ▶ path_info => sub { shift->env->{'PATH_INFO'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
169 path_parameters => undef,
170 path => 'path_info',
171 pool => undef,
172 preferred_charset => undef,
173 preferred_encoding => undef,
174 preferred_language => undef,
175 preferred_media_type=> undef,
176 prev => undef,
177 print => undef,
178 0 ▶ protocol => sub { shift()->env->{'SERVER_PROTOCOL'} || 'HTTP/1.1' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->env->{"SERVER_PROTOCOL"} or "HTTP/1.1" 0 0 0
179 query_parameters => undef,
180 query_string => 'args',
181 redirect => undef,
182 0 ▶ referer => sub { shift()->headers_in('referer') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
183 register_cleanup => 'cleanup_register',
184 remote_address => 'client_address',
185 remote_host => 'client_address',
186 0 ▶ remote_port => sub { shift()->env->{'REMOTE_PORT'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
187 remote_user => 'user',
188 request_time => undef,
189 route => undef,
190 run => undef,
191 scheme => undef,
192 0 ▶ script_name => sub { shift()->env->{'SCRIPT_NAME'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
193 0 ▶ secure => sub { (shift()->https eq 'on') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
194 sendfile => undef,
195 send_http_header => undef,
196 0 ▶ server_name => sub { shift()->env->{'SERVER_NAME'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
197 0 ▶ server_port => sub { shift()->env->{'SERVER_PORT'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
198 session_id => undef,
199 session => undef,
200 set_handlers => undef,
201 status_line => undef,
202 status => undef,
203 0 ▶ unparsed_uri => sub { shift()->filename() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
204 uploads => undef,
205 #uri => sub { $_[0]->{'uri'} ||= URI->new($_[0]->filename()) },
206 uri => undef,
207 url => 'uri',
208 0 ▶ user_agent => sub { shift()->headers_in('user-agent') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
209 0 ▶ user => sub { shift()->env->{'REMOTE_USER'} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
210 5 write => undef,
211 err_html => undef,
212 DESTROY => undef
213
214 );
215  
216  
217 # Not really valid here but setup anyway
218 #
219 5 foreach my $handler (qw(req res)) {
220 0 ▶ *{$handler}=sub { return shift() };
Subroutine __ANON__: not called CC=1 SCAR=0.4
221 }
222  
223  
224 # Now setup abstraction methods. Slightly different than PSGI, PAGI, Apache so just do it here
225 #
226 5 my %method_check;
227 5 ▶ while (my ($method, $dispatch)=each %method) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %method) 535 5 540
228 535 $method_check{$method}++;
229 535 ▶ if (defined(*{sprintf('%s::%s', __PACKAGE__, $method)}{'CODE'})) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined *{sprintf '%s::%s', __PACKAGE__, $method;}{'CODE'}) { } 280 255 535
elsif (not defined $dispatch) { } 0 255 255
elsif (ref $dispatch eq 'CODE') { } 190 65 255
230 # Do nothing, defined here
231 #
232 280 ▶ warn("duplicate method for $method") if $dispatch;
Branch: 1 branch
BranchTrueFalseTotal
if $dispatch 0 280 280
233 280 debug("skip $method, defined in this package");
234
235 }
236 elsif (!defined($dispatch)) {
237 # Do nothing, will fall through
238 #
239 0 debug("skip $method, will inherit from Fake");
240 }
241 elsif (ref($dispatch) eq 'CODE') {
242 # Turn into method
243 #
244 190 debug("setting method: $method to code ref: $dispatch");
245 190 *{$method}=$dispatch;
246 }
247 else {
248 # Existing method
249 #
250 65 debug("setting method: $method to dispatch: $dispatch");
251 0 ▶ *{$method}=sub { shift()->$dispatch(@_) };
Subroutine __ANON__: not called CC=1 SCAR=0.4
252 }
253 }
254
255
256 # Done, do runtime check and return, will warn if we have missed anything
257 #
258 5 return handler_methods_check(__PACKAGE__, \%method_check);
259
260 }
261  
262  
263 1 ▶sub uri {
Subroutine uri: called CC=2 SCAR=9.2
Pod undocumented
264  
265 1 ▶ $_[0]->{'uri'} ||= URI->new($_[0]->filename())
Condition33%1/3
$_[0]{"uri"} ||= "URI"->new($_[0]->filename)
l!l&&r!l&&!r
010
MC/DC0%0/2
$_[0]{"uri"} ||= "URI"->new($_[0]->filename)
$_[0]{"uri"} "URI"->new($_[0]->filename)
Truth table33%1/3
A ||= B
A= $_[0]{"uri"}B= "URI"->new($_[0]->filename)
ABresult
1X1
011
000
266
267 }
268  
269  
270 0 ▶sub body {
Subroutine body: not called CC=3 SCAR=24.8
Pod undocumented
271  
272 0 my $r=shift();
273 0 ▶ return $r->{'body'} ||= do {
Condition0%0/3
$r->{"body"} ||= do { if (my $fh = $r->{"input"}) { seek $fh, 0, 0; local $/; readline $fh; } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$r->{"body"} ||= do { if (my $fh = $r->{"input"}) { seek $fh, 0, 0; local $/; readline $fh; } }
$r->{"body"} do { if (my $fh = $r->{"input"}) { seek $fh, 0, 0; local $/; readline $fh; } }
Truth table0%0/3
A ||= B
A= $r->{"body"}B= do { if (my $fh = $r->{"input"}) { seek $fh, 0, 0; local $/; readline $fh; } }
ABresult
1X1
011
000
274 0 ▶ if (my $fh=$r->{'input'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = $r->{"input"}) 0 0 0
275 0 seek($fh,0,0);
276 0 local $/;
277 <$fh>
278 0 }
279 };
280
281 }
282  
283  
284 0 ▶sub cookies {
Subroutine cookies: not called CC=2 SCAR=17.9
Pod undocumented
285  
286 0 my $r=shift();
287 0 require CGI::Simple::Cookie;
288 0 my %cookies=CGI::Simple::Cookie->parse(
289 $r->headers_in('cookie'));
290 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
291 0 $r->headers_out('set-cookie', CGI::Simple::Cookie->new(@_)->as_string());
292 }
293 0 return \%cookies;
294 }
295  
296  
297 11 ▶sub dir_config {
Subroutine dir_config: called CC=19 SCAR=40.4
Pod undocumented
298  
299
300 # Newer more comprehensive dir_config that pulls from WEBDYNE_CONF
301 #
302 11 my ($r, $key)=@_;
303 11 debug("r: $r, caller: %s", Dumper([caller(0)]));
304
305  
306 # Get hash ref from config file
307 #
308 11 my $constant_hr=$WEBDYNE_DIR_CONFIG;
309 11 debug('using constant_hr: %s', Dumper($constant_hr));
310  
311  
312 # Optionally load WEBDYNE_DIR_CONFIG from current dir
313 #
314 11 ▶ if ($WEBDYNE_DIR_CONFIG_CWD_LOAD) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WebDyne::Request::Fake::WEBDYNE_DIR_CONFIG_CWD_LOAD) 11 0 11
315
316  
317 # Yes, wanted. Get cwd, skip if already processed
318 #
319 11 my $cwd_dn=$r->cwd();
320 11 ▶ my $dir_config_hr=($Package{'_dir_config'}{$cwd_dn} ||= do {
Condition60%3/5
$WebDyne::Request::Fake::Package{"_dir_config"}{$cwd_dn} ||= do { my $webdyne_conf_fn = "File::Spec"->catfile($cwd_dn, sprintf('.%s', $WebDyne::Request::Fake::WEBDYNE_CONF_FN)); debug("fn: $webdyne_conf_fn"); if (-f $webdyne_conf_fn) { debug("found: $webdyne_conf_fn, reading"); my $webdyne_conf_hr = do $webdyne_conf_fn || warn("unable to read document root dir_config constant file, $!"); debug("webdyne_conf_hr: %s", Dumper($webdyne_conf_hr)); $webdyne_conf_hr->{"WebDyne::Constant"}{"WEBDYNE_DIR_CONFIG"}; } } || {}
l!l&&r!l&&!r
1010
do { my $webdyne_conf_fn = 'File::Spec'->catfile($cwd_dn, sprintf('.%s', $WebDyne::Request::Fake::WEBDYNE_CONF_FN)); debug("fn: $webdyne_conf_fn"); if (-f $webdyne_conf_fn) { debug("found: $webdyne_conf_fn, reading"); my $webdyne_conf_hr = do $webdyne_conf_fn || warn("unable to read document root dir_config constant file, $!"); debug('webdyne_conf_hr: %s', Dumper($webdyne_conf_hr)); $webdyne_conf_hr->{'WebDyne::Constant'}{'WEBDYNE_DIR_CONFIG'}; } } || {}
l!l
01
MC/DC0%0/2
$WebDyne::Request::Fake::Package{"_dir_config"}{$cwd_dn} ||= do { my $webdyne_conf_fn = "File::Spec"->catfile($cwd_dn, sprintf('.%s', $WebDyne::Request::Fake::WEBDYNE_CONF_FN)); debug("fn: $webdyne_conf_fn"); if (-f $webdyne_conf_fn) { debug("found: $webdyne_conf_fn, reading"); my $webdyne_conf_hr = do $webdyne_conf_fn || warn("unable to read document root dir_config constant file, $!"); debug("webdyne_conf_hr: %s", Dumper($webdyne_conf_hr)); $webdyne_conf_hr->{"WebDyne::Constant"}{"WEBDYNE_DIR_CONFIG"}; } } || {}
$WebDyne::Request::Fake::Package{"_dir_config"}{$cwd_dn} do { my $webdyne_conf_fn = 'File::Spec'->catfile($cwd_dn, sprintf('.%s', $WebDyne::Request::Fake::WEBDYNE_CONF_FN)); debug("fn: $webdyne_conf_fn"); if (-f $webdyne_conf_fn) { debug("found: $webdyne_conf_fn, reading"); my $webdyne_conf_hr = do $webdyne_conf_fn || warn("unable to read document root dir_config constant file, $!"); debug('webdyne_conf_hr: %s', Dumper($webdyne_conf_hr)); $webdyne_conf_hr->{'WebDyne::Constant'}{'WEBDYNE_DIR_CONFIG'}; } }
Truth table33%1/3
A ||= B
A= $WebDyne::Request::Fake::Package{"_dir_config"}{$cwd_dn}B= do { my $webdyne_conf_fn = 'File::Spec'->catfile($cwd_dn, sprintf('.%s', $WebDyne::Request::Fake::WEBDYNE_CONF_FN)); debug("fn: $webdyne_conf_fn"); if (-f $webdyne_conf_fn) { debug("found: $webdyne_conf_fn, reading"); my $webdyne_conf_hr = do $webdyne_conf_fn || warn("unable to read document root dir_config constant file, $!"); debug('webdyne_conf_hr: %s', Dumper($webdyne_conf_hr)); $webdyne_conf_hr->{'WebDyne::Constant'}{'WEBDYNE_DIR_CONFIG'}; } }
ABresult
1X1
011
000
321 1 my $webdyne_conf_fn=File::Spec->catfile($cwd_dn, sprintf('.%s', $WEBDYNE_CONF_FN));
322 1 debug("fn: $webdyne_conf_fn");
323 1 ▶ if (-f $webdyne_conf_fn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $webdyne_conf_fn) 0 1 1
324 0 debug("found: $webdyne_conf_fn, reading");
325 0 ▶ my $webdyne_conf_hr=do($webdyne_conf_fn) ||
Condition0%0/2
do $webdyne_conf_fn || warn("unable to read document root dir_config constant file, $!")
l!l
00
MC/DC0%0/1
do $webdyne_conf_fn || warn("unable to read document root dir_config constant file, $!")
do $webdyne_conf_fn
Truth table0%0/2
A
A= do $webdyne_conf_fn
Aresult
11
00
326 warn "unable to read document root dir_config constant file, $!";
327 0 debug('webdyne_conf_hr: %s', Dumper($webdyne_conf_hr));
328 0 $webdyne_conf_hr->{'WebDyne::Constant'}{'WEBDYNE_DIR_CONFIG'};
329 }} || {}
330 );
331 11 ▶ if (keys %{$dir_config_hr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$dir_config_hr;}) 0 11 11
332 $constant_hr={
333 0 %{$constant_hr},
334 0 %{$dir_config_hr}
335 }
336 }
337 }
338  
339  
340 # OK - heirarchy is this:
341 #
342 # If WEBDYNE_PSGI_DIR_CONFIG=$hr order of return
343 #
344 # $ENV{$key} # Wins everything
345 # $hr->{$servername}{$location}{$key}
346 # $hr->{$servername}{''}{$key}
347 # $hr->{$servername}{$key}
348 # $hr->{$location}{$key}
349 # $hr->{''}{$key}
350 # $hr->{$key}
351 #
352  
353 11 ▶ if ($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) { } 11 0 11
354
355 # Key specified, returning just that value
356 #
357 #if (exists $Dir_config_env{$key}) {
358 11 ▶ if (exists $ENV{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{$key}) { } 0 11 11
359
360 # $ENV{$key} # Wins everything
361 #
362 #debug('found $ENV{%s}, returning %s', $key, $Dir_config_env{$key});
363 0 debug('found $ENV{%s}, returning %s', $key, $ENV{$key});
364 #return $Dir_config_env{$key};
365 0 return $ENV{$key};
366
367 }
368 else {
369
370  
371 # Get location we are operating in
372 #
373 11 my $location=$r->location();
374 11 debug("in dir_config looking for key: $key at location: $location");
375
376
377 # Array of hashes we may need to look through
378 #
379 11 my @constant_hr=($constant_hr);
380  
381  
382 # Do we have $hr->{$servername}{$location} ?
383 #
384 11 ▶ if (my $server=($ENV{'WebDyneServer'} || $ENV{'HOSTNAME'} || $ENV{'SERVER_NAME'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $server = $ENV{"WebDyneServer"} || $ENV{"HOSTNAME"} || $ENV{"SERVER_NAME"}) 11 0 11
Condition33%2/6
$ENV{'WebDyneServer'} || $ENV{'HOSTNAME'} || $ENV{'SERVER_NAME'}
l!l&&r!l&&!r
1100
$ENV{"WebDyneServer"} or $ENV{"HOSTNAME"}
l!l&&r!l&&!r
0110
MC/DC0%0/3
$ENV{'WebDyneServer'} || $ENV{'HOSTNAME'} || $ENV{'SERVER_NAME'}
$ENV{"WebDyneServer"} $ENV{"HOSTNAME"} $ENV{'SERVER_NAME'}
Truth table25%1/4
A or B || C
A= $ENV{"WebDyneServer"}B= $ENV{"HOSTNAME"}C= $ENV{'SERVER_NAME'}
ABCresult
1XX1
01X1
0011
0000
385  
386 # Have $servername
387 #
388 11 debug("using server: $server");
389 11 ▶ if (exists $constant_hr->{$server}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $constant_hr->{$server}) 0 11 11
390
391 # Add to array of hashes we have to look at
392 #
393 0 unshift @constant_hr, (my $constant_server_hr=$constant_hr->{$server});
394 0 debug("pushing $constant_server_hr onto dir_config review stack: %s", Dumper($constant_server_hr));
395
396 }
397
398 }
399
400
401 # Now iterate across array, return on first match
402 #
403 11 foreach my $hr (@constant_hr) {
404 11 my %location;
405 11 foreach my $hr_key ($location, '') {
406 22 ▶ next if ($location{$location}++);
Branch: 1 branch
BranchTrueFalseTotal
if $location{$location}++ 11 11 22
407 11 debug("looking at hr: $hr, hr_key: $hr_key");
408 # Maybe $hr->{$location}{$key} or $hr->{''}{$key} ?
409 #
410 11 ▶ if (exists $constant_hr->{$hr_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $constant_hr->{$hr_key}) { } 0 11 11
411 0 debug("found hr: $hr, hr_key: $hr_key");
412 0 ▶ return $hr->{$hr_key}{$key} if exists($hr->{$hr_key}{$key});
Branch: 1 branch
BranchTrueFalseTotal
if exists $hr->{$hr_key}{$key} 0 0 0
413 }
414 else {
415 11 debug("no match on hr: $hr, hr_key: $hr_key");
416 }
417 }
418 # No - $hr->{$key} is last chance
419 #
420 11 ▶ if (exists $hr->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hr->{$key}) { } 0 11 11
421 0 debug("found hr: $hr, key: $key");
422 0 return $hr->{$key}
423 }
424 else {
425 11 debug("no match on hr: $hr, key: $key");
426 }
427 }
428
429 # Nothing found
430 #
431 11 debug("no key found for location: $location or any other match");
432 11 return undef;
433
434 }
435
436 }
437 else {
438  
439 # Return dump of whole thing with ENV vars taking precendence at top level. Scrub mixing in ENV at moment, exposes
440 # too many non WebDyne vars if called with dir_config(). Do properly with Plack::Middleware::AddEnv or similar later
441 #
442 #my %dir_config=(%{$constant_hr}, %Dir_config_env);
443 my %dir_config=(
444 0 %{$constant_hr},
445 0 (map { $_=>$ENV{$_} } grep {/^WEBDYNE_/i} keys %ENV),
446 0 (map { $_=>$ENV{$_} } grep {exists $ENV{$_} } keys %{$constant_hr})
447 #(map { $_=>$ENV{$_} } @{$WEBDYNE_PSGI_ENV_KEEP},
448 #%{$WEBDYNE_PSGI_ENV_SET}
449 );
450 0 return \%dir_config;
451 }
452  
453 }
454  
455  
456 51 ▶sub filename {
Subroutine filename: called CC=3 SCAR=11.4
Pod undocumented
457  
458 51 my $r=shift();
459 51 ▶ return undef unless defined $r->{'filename'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"filename"} 0 51 51
460  
461 # Store cwd as takes a fair bit of processing time.
462 51 ▶ File::Spec->rel2abs($r->{'filename'}, ($Package{'_cwd'} ||= fastcwd()));
Condition66%2/3
$WebDyne::Request::Fake::Package{"_cwd"} ||= fastcwd()
l!l&&r!l&&!r
4740
MC/DC0%0/2
$WebDyne::Request::Fake::Package{"_cwd"} ||= fastcwd()
$WebDyne::Request::Fake::Package{"_cwd"} fastcwd()
Truth table66%2/3
A ||= B
A= $WebDyne::Request::Fake::Package{"_cwd"}B= fastcwd()
ABresult
1X1
011
000
463  
464 }
465  
466  
467 32 ▶sub headers_in {
Subroutine headers_in: called CC=4 SCAR=17.9
Pod undocumented
468 32 my $r=shift();
469 32 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 32 0 32
470 32 ▶ return ($r->{'headers_in'} ||= HTTP::Headers::Fast->new())->header(@_);
Condition66%2/3
$r->{"headers_in"} ||= "HTTP::Headers::Fast"->new
l!l&&r!l&&!r
2480
MC/DC0%0/2
$r->{"headers_in"} ||= "HTTP::Headers::Fast"->new
$r->{"headers_in"} "HTTP::Headers::Fast"->new
Truth table66%2/3
A ||= B
A= $r->{"headers_in"}B= "HTTP::Headers::Fast"->new
ABresult
1X1
011
000
471 }
472 else {
473 0 ▶ return ($r->{'headers_in'} ||= HTTP::Headers::Fast->new());
Condition0%0/3
$r->{"headers_in"} ||= "HTTP::Headers::Fast"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$r->{"headers_in"} ||= "HTTP::Headers::Fast"->new
$r->{"headers_in"} "HTTP::Headers::Fast"->new
Truth table0%0/3
A ||= B
A= $r->{"headers_in"}B= "HTTP::Headers::Fast"->new
ABresult
1X1
011
000
474 }
475 }
476  
477  
478 64 ▶sub headers_out {
Subroutine headers_out: called CC=4 SCAR=14.0
Pod undocumented
479 64 my $r=shift();
480 64 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 52 12 64
481 52 ▶ return ($r->{'headers_out'} ||= HTTP::Headers::Fast->new())->header(@_);
Condition66%2/3
$r->{"headers_out"} ||= "HTTP::Headers::Fast"->new
l!l&&r!l&&!r
4480
MC/DC0%0/2
$r->{"headers_out"} ||= "HTTP::Headers::Fast"->new
$r->{"headers_out"} "HTTP::Headers::Fast"->new
Truth table66%2/3
A ||= B
A= $r->{"headers_out"}B= "HTTP::Headers::Fast"->new
ABresult
1X1
011
000
482 }
483 else {
484 12 ▶ return ($r->{'headers_out'} ||= HTTP::Headers::Fast->new());
Condition66%2/3
$r->{"headers_out"} ||= "HTTP::Headers::Fast"->new
l!l&&r!l&&!r
1020
MC/DC0%0/2
$r->{"headers_out"} ||= "HTTP::Headers::Fast"->new
$r->{"headers_out"} "HTTP::Headers::Fast"->new
Truth table66%2/3
A ||= B
A= $r->{"headers_out"}B= "HTTP::Headers::Fast"->new
ABresult
1X1
011
000
485 }
486 }
487  
488  
489 0 ▶sub is_main {
Subroutine is_main: not called CC=2 SCAR=17.9
Pod undocumented
490  
491 0 my $r=shift();
492 0 ▶ $r->{'main'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$r->{'main'} ? : 0 0 0
493  
494 }
495  
496  
497 0 ▶sub log_error {
Subroutine log_error: not called CC=2 SCAR=17.9
Pod undocumented
498  
499 0 my $r=shift();
500 0 ▶ warn(@_) unless !$r->{'warn'};
Branch: 1 branch
BranchTrueFalseTotal
unless not $r->{"warn"} 0 0 0
501  
502 }
503  
504  
505  
506 2 ▶sub lookup_file {
Subroutine lookup_file: called CC=4 SCAR=15.5
Pod undocumented
507  
508 2 my ($r, $fn)=@_;
509 2 debug("r: $r, fn: $fn");
510 2 my $r_child;
511 2 ▶ if ($fn!~WEBDYNE_PSP_EXT_RE) { # fastest
Branch: 1 branch
BranchTrueFalseTotal
if (not $fn =~ /(?^:\.psp$)/) { } 2 0 2
512  
513  
514 # Static file. The helper retains its historical PSGI name but does
515 # not require Plack.
516 #
517 2 debug('non psp file, passing to WebDyne::Request::PSGI::Static');
518 2 require WebDyne::Request::PSGI::Static;
519 2 ▶ $r_child=WebDyne::Request::PSGI::Static->new(filename => $fn, prev => $r, env=>$r->env()) ||
Condition50%1/2
'WebDyne::Request::PSGI::Static'->new('filename', $fn, 'prev', $r, 'env', $r->env) || (return err())
l!l
20
MC/DC0%0/1
'WebDyne::Request::PSGI::Static'->new('filename', $fn, 'prev', $r, 'env', $r->env) || (return err())
'WebDyne::Request::PSGI::Static'->new('filename', $fn, 'prev', $r, 'env', $r->env)
Truth table50%1/2
A
A= 'WebDyne::Request::PSGI::Static'->new('filename', $fn, 'prev', $r, 'env', $r->env)
Aresult
11
00
520 return err();
521  
522 }
523 else {
524  
525  
526 # Subrequest
527 #
528 0 debug('psp file, creating new request');
529 0 ▶ $r_child=ref($r)->new(filename => $fn, prev => $r) || return err();
Condition0%0/2
ref($r)->new('filename', $fn, 'prev', $r) || (return err())
l!l
00
MC/DC0%0/1
ref($r)->new('filename', $fn, 'prev', $r) || (return err())
ref($r)->new('filename', $fn, 'prev', $r)
Truth table0%0/2
A
A= ref($r)->new('filename', $fn, 'prev', $r)
Aresult
11
00
530  
531 }
532  
533 # Return child
534 #
535 2 debug("returning r_child: $r_child");
536 2 return $r_child;
537  
538 }
539  
540  
541 0 ▶sub lookup_uri {
Subroutine lookup_uri: not called CC=1 SCAR=6.9
Pod undocumented
542  
543 0 my ($r, $uri)=@_;
544 0 my $fn=File::Spec::Unix->catfile((File::Spec->splitpath($r->filename()))[1], $uri);
545 0 return $r->lookup_file($fn);
546  
547 }
548  
549  
550 8 ▶sub main {
Subroutine main: called CC=2 SCAR=7.2
Pod undocumented
551  
552 8 my $r=shift();
553 #@_ ? $r->{'main'}=shift() : $r->{'main'} || $r;
554 8 ▶ @_ ? $r->{'main'}=shift() : $r->{'main'};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 8 8
555  
556 }
557  
558  
559 13 ▶sub new {
Subroutine new: called CC=5 SCAR=20.9
Pod undocumented
560  
561  
562 # Instantiate new fake handler
563 #
564 13 my ($class, %r)=@_;
565 13 debug("$class, r:%s", Dumper(\%r));
566 13 my $r=bless(\%r, $class);
567  
568  
569 # Now move ENV into headers
570 #
571 13 foreach my $env ((grep {/^HTTP_/} keys %ENV), qw(CONTENT_TYPE CONTENT_LENGTH)) {
572 26 my $header=$env;
573 26 ▶ exists $ENV{$header} || next;
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{$header} or next 0 26 26
574 0 my $value=$ENV{$header};
575 0 $header=~s/^HTTP_//;
576 0 $header=~s/_/-/g;
577 0 debug("setting header: $header, value: $value");
578 0 $r->headers_in(lc($header), $value);
579 }
580
581
582 # If Headers in supplied as array or hash ref convert
583 #
584 13 ▶ if (ref($r{'headers_in'}) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $r{'headers_in'} eq 'ARRAY') { } 0 13 13
elsif (ref $r{'headers_in'} eq 'HASH') { } 0 13 13
585 0 $r{'headers_in'}=HTTP::Headers::Fast->new(@{$r->{'headers_in'}})
586 }
587 elsif (ref($r{'headers_in'}) eq 'HASH') {
588 0 $r{'headers_in'}=HTTP::Headers::Fast->new(%{$r->{'headers_in'}})
589 }
590
591
592 # Done
593 #
594 13 return $r;
595  
596 }
597  
598  
599 0 ▶sub notes {
Subroutine notes: not called CC=5 SCAR=34.0
Pod undocumented
600  
601 0 my ($r, $k, $v)=@_;
602 0 ▶ if (@_ == 3) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 3) { } 0 0 0
elsif (@_ == 2) { } 0 0 0
elsif (@_ == 1) { } 0 0 0
603 0 return $r->{'_notes'}{$k}=$v
604 }
605 elsif (@_ == 2) {
606 0 return $r->{'_notes'}{$k}
607 }
608 elsif (@_ == 1) {
609 0 ▶ return ($r->{'_notes'} ||= {});
Condition0%0/2
$r->{"_notes"} ||= {}
l!l
00
MC/DC0%0/1
$r->{"_notes"} ||= {}
$r->{"_notes"}
Truth table0%0/2
A
A= $r->{"_notes"}
Aresult
11
00
610 }
611 else {
612 0 return err('incorrect usage of %s notes object, r->notes(%s)', +__PACKAGE__, join(',', @_[1..$#_]));
613 }
614  
615 }
616  
617  
618  
619  
620 2 ▶sub prev {
Subroutine prev: called CC=2 SCAR=7.2
Pod undocumented
621  
622 2 my $r=shift();
623 2 ▶ @_ ? $r->{'prev'}=shift() : $r->{'prev'};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 2 2
624  
625 }
626  
627  
628 10 ▶sub print {
Subroutine print: called CC=3 SCAR=11.0
Pod undocumented
629  
630 10 my $r=shift();
631 10 ▶ my $fh=$r->{'select'} || \*STDOUT;
Condition50%1/2
$r->{'select'} || \*STDOUT
l!l
100
MC/DC0%0/1
$r->{'select'} || \*STDOUT
$r->{'select'}
Truth table50%1/2
A
A= $r->{'select'}
Aresult
11
00
632 10 debug("print fh: $fh");
633 10 ▶ CORE::print $fh ((ref($_[0]) eq 'SCALAR') ? ${$_[0]} : @_);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'SCALAR' ? : 6 4 10
634  
635 }
636  
637  
638 0 ▶sub cleanup_register {
Subroutine cleanup_register: not called CC=2 SCAR=17.9
Pod undocumented
639  
640 #my $r=shift();
641 0 my ($r, $cr)=@_;
642 0 ▶ push @{$r->{'register_cleanup'} ||= []}, $cr;
Condition0%0/2
$r->{"register_cleanup"} ||= []
l!l
00
MC/DC0%0/1
$r->{"register_cleanup"} ||= []
$r->{"register_cleanup"}
Truth table0%0/2
A
A= $r->{"register_cleanup"}
Aresult
11
00
643  
644 #my $ar=$r->{'register_cleanup'} ||= [];
645 #push @
646  
647 }
648  
649  
650  
651  
652 0 ▶sub pool {
Subroutine pool: not called CC=1 SCAR=6.9
Pod undocumented
653  
654 # Used by mod_perl2, usually for cleanup_register in the form of $r->pool->cleanup_register(), so just
655 # return $r and let the code then call cleanup_register
656 #
657 0 my $r=shift();
658  
659 }
660  
661  
662 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
663  
664 0 my ($r, $self)=@_;
665 0 debug("r: $r, self: $self");
666 0 ▶ (ref($self) || $self)->handler($r);
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
667 #(ref($self) ? $self : $self)->handler($r);
668  
669 }
670  
671  
672 22 ▶sub status {
Subroutine status: called CC=3 SCAR=11.0
Pod undocumented
673  
674 22 my $r=shift();
675 22 ▶ @_ ? $r->{'status'}=shift() : $r->{'status'} || HTTP_OK;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 20 22
Condition100%2/2
$r->{"status"} or 200
l!l
218
MC/DC100%1/1
$r->{"status"} or 200
$r->{"status"}
Truth table100%2/2
A
A= $r->{"status"}
Aresult
11
00
676  
677 }
678  
679  
680 0 ▶sub document_root {
Subroutine document_root: not called CC=4 SCAR=30.0
Pod undocumented
681  
682 0 my $r=shift();
683 0 ▶ @_ ? $r->{'document_root'}=shift() : $r->{'document_root'} || ($ENV{'DOCUMENT_ROOT'} || fastcwd());
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
Condition0%0/6
$r->{"document_root"} or ($ENV{"DOCUMENT_ROOT"} or fastcwd())
l!l&&r!l&&!r
000
$ENV{"DOCUMENT_ROOT"} or fastcwd()
l!l&&r!l&&!r
000
MC/DC0%0/3
$r->{"document_root"} or ($ENV{"DOCUMENT_ROOT"} or fastcwd())
$r->{"document_root"} $ENV{"DOCUMENT_ROOT"} fastcwd()
Truth table0%0/4
A or B or C
A= $r->{"document_root"}B= $ENV{"DOCUMENT_ROOT"}C= fastcwd()
ABCresult
1XX1
01X1
0011
0000
684
685 }
686  
687  
688 0 ▶sub output_filters {
Subroutine output_filters: not called CC=1 SCAR=0.0
Pod undocumented
689  
690 # Stub
691 }
692  
693  
694 27 ▶sub location {
Subroutine location: called CC=15 SCAR=46.4
Pod undocumented
695  
696  
697 # Equiv to Apache::RequestUtil->location;
698 #
699 27 my $r=shift();
700 27 debug("r: $r, caller: %s", Dumper([caller(0)]));
701 27 my $location;
702 27 my $constant_hr=$WEBDYNE_DIR_CONFIG;
703 27 my $constant_server_hr;
704 #if (my $server=$Dir_config_env{'WebDyneServer'} || $ENV{'SERVER_NAME'}) {
705 27 ▶ if (my $server=$ENV{'WebDyneServer'} || $ENV{'SERVER_NAME'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $server = $ENV{"WebDyneServer"} || $ENV{"SERVER_NAME"}) 0 27 27
Condition33%1/3
$ENV{'WebDyneServer'} || $ENV{'SERVER_NAME'}
l!l&&r!l&&!r
0027
MC/DC0%0/2
$ENV{'WebDyneServer'} || $ENV{'SERVER_NAME'}
$ENV{'WebDyneServer'} $ENV{'SERVER_NAME'}
Truth table33%1/3
A || B
A= $ENV{'WebDyneServer'}B= $ENV{'SERVER_NAME'}
ABresult
1X1
011
000
706 0 ▶ $constant_server_hr=$constant_hr->{$server} if exists($constant_hr->{$server})
Branch: 1 branch
BranchTrueFalseTotal
if exists $constant_hr->{$server} 0 0 0
707 }
708 #if ($Dir_config_env{'WebDyneLocation'} || $ENV{'APPL_MD_PATH'}) {
709 27 ▶ if ($location=$r->{'location'}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($location = $r->{'location'}) { } 0 27 27
elsif ($ENV{'WebDyneLocation'} or $ENV{'APPL_MD_PATH'}) { } 0 27 27
elsif (my $uri_path = join('', grep({$_;} @ENV{'SCRIPT_NAME', 'PATH_INFO'}))) { } 0 27 27
710 0 return $location;
711 }
712 ▶ elsif ($ENV{'WebDyneLocation'} || $ENV{'APPL_MD_PATH'}) {
Condition33%1/3
$ENV{"WebDyneLocation"} or $ENV{"APPL_MD_PATH"}
l!l&&r!l&&!r
0027
MC/DC0%0/2
$ENV{"WebDyneLocation"} or $ENV{"APPL_MD_PATH"}
$ENV{"WebDyneLocation"} $ENV{"APPL_MD_PATH"}
Truth table33%1/3
A or B
A= $ENV{"WebDyneLocation"}B= $ENV{"APPL_MD_PATH"}
ABresult
1X1
011
000
713  
714 # APPL_MD_PATH is IIS virtual dir. If that or a fixed location set use it.
715 #
716 #$location=$Dir_config_env{'WebDyneLocation'} || $ENV{'APPL_MD_PATH'};
717 0 ▶ $location=$ENV{'WebDyneLocation'} || $ENV{'APPL_MD_PATH'};
Condition0%0/3
$ENV{'WebDyneLocation'} || $ENV{'APPL_MD_PATH'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'WebDyneLocation'} || $ENV{'APPL_MD_PATH'}
$ENV{'WebDyneLocation'} $ENV{'APPL_MD_PATH'}
Truth table0%0/3
A || B
A= $ENV{'WebDyneLocation'}B= $ENV{'APPL_MD_PATH'}
ABresult
1X1
011
000
718 }
719 54 elsif (my $uri_path=join('', grep {$_} @ENV{qw(SCRIPT_NAME PATH_INFO)})) {
720
721 # Strip file name
722 #
723 0 $uri_path=~s{[^/]+\Q@{[WEBDYNE_PSP_EXT]}\E$}{}x; #\
724 0 debug("uri_path: $uri_path");
725 0 my @location=('/', grep {$_} File::Spec::Unix->splitdir($uri_path));
726
727 # Start iterating through directories
728 #
729 0 ▶ while ($location=File::Spec::Unix->catdir(@location)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location = "File::Spec::Unix"->catdir(@location)) 0 0 0
730 0 debug("location: $location");
731 0 ▶ last if exists($constant_hr->{$location}) || exists($constant_server_hr->{$location});
Branch: 1 branch
BranchTrueFalseTotal
if exists $constant_hr->{$location} or exists $constant_server_hr->{$location} 0 0 0
Condition0%0/3
exists $constant_hr->{$location} or exists $constant_server_hr->{$location}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $constant_hr->{$location} or exists $constant_server_hr->{$location}
exists $constant_hr->{$location} exists $constant_server_hr->{$location}
Truth table0%0/3
A or B
A= exists $constant_hr->{$location}B= exists $constant_server_hr->{$location}
ABresult
1X1
011
000
732 0 ▶ $location.='/' unless ($location eq '/');
Branch: 1 branch
BranchTrueFalseTotal
unless $location eq "/" 0 0 0
733 0 ▶ last if exists($constant_hr->{$location}) || exists($constant_server_hr->{$location});
Branch: 1 branch
BranchTrueFalseTotal
if exists $constant_hr->{$location} or exists $constant_server_hr->{$location} 0 0 0
Condition0%0/3
exists $constant_hr->{$location} or exists $constant_server_hr->{$location}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $constant_hr->{$location} or exists $constant_server_hr->{$location}
exists $constant_hr->{$location} exists $constant_server_hr->{$location}
Truth table0%0/3
A or B
A= exists $constant_hr->{$location}B= exists $constant_server_hr->{$location}
ABresult
1X1
011
000
734 0 pop @location;
735 }
736 }
737 else {
738
739 # Actually mod_perl spec says location blank if not positively given - don't default to '/'
740 #
741 #$location=File::Spec::Unix->rootdir();
742 }
743
744 #
745 #
746 27 return $location;
747  
748 }
749  
750  
751  
752 8 ▶sub header_only {
Subroutine header_only: called CC=1 SCAR=0.0
Pod undocumented
753  
754 # Stub
755 }
756  
757  
758 0 ▶sub set_handlers {
Subroutine set_handlers: not called CC=1 SCAR=0.0
Pod undocumented
759  
760 # Stub
761 }
762  
763  
764  
765  
766 10 ▶sub send_http_header {
Subroutine send_http_header: called CC=4 SCAR=24.6
Pod undocumented
767  
768 10 my $r=shift();
769 10 ▶ return unless $r->{'header'};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"header"} 10 0 10
770 0 ▶ my $fh=$r->{'select'} || \*STDOUT;
Condition0%0/2
$r->{'select'} || \*STDOUT
l!l
00
MC/DC0%0/1
$r->{'select'} || \*STDOUT
$r->{'select'}
Truth table0%0/2
A
A= $r->{'select'}
Aresult
11
00
771 0 CORE::printf $fh ("Status: %s\n", $r->status());
772 0 ▶ while (my ($header, $value)=each(%{$r->headers_out()})) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$r->headers_out;}) 0 0 0
773 0 CORE::print $fh ("$header: $value\n");
774 }
775 0 CORE::print $fh "\n";
776  
777 }
778  
779  
780 10 ▶sub content_type { # Was bi-directional but now only reads from response headers.
Subroutine content_type: called CC=2 SCAR=7.1
Pod undocumented
781  
782 10 my ($r, $content_type)=@_;
783 10 debug("r: $r, %s", Dumper(\@_));
784 #return ($content_type ? $r->headers_out('content-type', $content_type) : $r->headers_in('content-type'));
785 10 ▶ return ($content_type ? $r->headers_out('content-type', $content_type) : $r->headers_out('content-type'));
Branch: 1 branch
BranchTrueFalseTotal
$content_type ? : 10 0 10
786  
787 }
788  
789  
790 8 ▶sub content_length {
Subroutine content_length: called CC=2 SCAR=7.1
Pod undocumented
791  
792 8 my ($r, $content_length)=@_;
793 8 debug("r: $r, %s", Dumper(\@_));
794 8 ▶ return ($content_length ? $r->headers_out('content-length', $content_length) : $r->headers_in('content-length'));
Branch: 1 branch
BranchTrueFalseTotal
$content_length ? : 0 8 8
795  
796 }
797  
798  
799 0 ▶sub handler {
Subroutine handler: not called CC=3 SCAR=24.8
Pod undocumented
800  
801 # Replicate mod_perl handler function
802 #
803 0 my ($r, $handler)=@_;
804 0 ▶ return ($handler ? $r->{'handler'}=$handler : $r->{'handler'} ||= 'default-handler');
Branch: 1 branch
BranchTrueFalseTotal
$handler ? : 0 0 0
Condition0%0/2
$handler ? $r->{"handler"} = $handler : $r->{"handler"} ||= "default-handler"
l!l
00
MC/DC0%0/1
$handler ? $r->{"handler"} = $handler : $r->{"handler"} ||= "default-handler"
$handler ? $r->{"handler"} = $handler : $r->{"handler"}
Truth table0%0/2
A
A= $handler ? $r->{"handler"} = $handler : $r->{"handler"}
Aresult
11
00
805  
806 }
807  
808  
809 0 ▶sub custom_response {
Subroutine custom_response: not called CC=3 SCAR=24.8
Pod undocumented
810  
811 0 my ($r, $status)=(shift(), shift());
812 0 ▶ while ($r->prev) {$r=$r->prev}
Branch: 1 branch
BranchTrueFalseTotal
if ($r->prev) 0 0 0
813 0 debug("in custom response, status $status");
814 0 ▶ @_ ? $r->{'custom_response'}{$status}=shift() : $r->{'custom_response'}{$status};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
815  
816 }
817  
818  
819 11 ▶sub cwd {
Subroutine cwd: called CC=4 SCAR=15.0
Pod undocumented
820  
821 # Return cwd of current psp file
822 #
823 11 my $r=shift();
824 11 ▶ return $r->{'_cwd'} ||= do {
Condition66%2/3
$r->{"_cwd"} ||= do { debug("$r, fn: %s", $r->filename); my $fn = $r->filename; my $dn; if (-d ($dn = "File::Spec"->rel2abs($fn))) { debug("return existing dn: $dn"); $dn; } else { $dn = ("File::Spec"->splitpath($fn))[1] || fastcwd(); debug("return calculated dn: $dn"); $dn; } }
l!l&&r!l&&!r
380
MC/DC0%0/2
$r->{"_cwd"} ||= do { debug("$r, fn: %s", $r->filename); my $fn = $r->filename; my $dn; if (-d ($dn = "File::Spec"->rel2abs($fn))) { debug("return existing dn: $dn"); $dn; } else { $dn = ("File::Spec"->splitpath($fn))[1] || fastcwd(); debug("return calculated dn: $dn"); $dn; } }
$r->{"_cwd"} do { debug("$r, fn: %s", $r->filename); my $fn = $r->filename; my $dn; if (-d ($dn = "File::Spec"->rel2abs($fn))) { debug("return existing dn: $dn"); $dn; } else { $dn = ("File::Spec"->splitpath($fn))[1] || fastcwd(); debug("return calculated dn: $dn"); $dn; } }
Truth table66%2/3
A ||= B
A= $r->{"_cwd"}B= do { debug("$r, fn: %s", $r->filename); my $fn = $r->filename; my $dn; if (-d ($dn = "File::Spec"->rel2abs($fn))) { debug("return existing dn: $dn"); $dn; } else { $dn = ("File::Spec"->splitpath($fn))[1] || fastcwd(); debug("return calculated dn: $dn"); $dn; } }
ABresult
1X1
011
000
825 8 debug("$r, fn: %s", $r->filename());
826 8 my $fn=$r->filename();
827 8 my $dn;
828 8 ▶ unless (-d ($dn=File::Spec->rel2abs($fn))) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d ($dn = 'File::Spec'->rel2abs($fn))) { } 0 8 8
829 # Not a directory, must be file
830 #
831 8 ▶ $dn=(File::Spec->splitpath($fn))[1] || fastcwd();
Condition33%1/3
('File::Spec'->splitpath($fn))[1] || fastcwd()
l!l&&r!l&&!r
800
MC/DC0%0/2
('File::Spec'->splitpath($fn))[1] || fastcwd()
('File::Spec'->splitpath($fn))[1] fastcwd()
Truth table33%1/3
A || B
A= ('File::Spec'->splitpath($fn))[1]B= fastcwd()
ABresult
1X1
011
000
832 8 debug("return calculated dn: $dn");
833 8 $dn;
834 }
835 else {
836 0 debug("return existing dn: $dn");
837 0 $dn;
838 }
839
840 }
841  
842 }
843  
844  
845 # TO DO
846 #
847 0 ▶sub status_line {
Subroutine status_line: not called CC=1 SCAR=6.9
Pod undocumented
848  
849 0 my $r=shift();
850 0 return sprintf('%s %s',$r->status, status_message($r->status));
851
852 }
853  
854  
855 0 ▶sub write {
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
856  
857 # Just print for Fake, other handlers can map to native
858 #
859 0 return &print(@_);
860
861 }
862  
863  
864 0 ▶sub finalize {
Subroutine finalize: not called CC=1 SCAR=0.0
Pod undocumented
865  
866 # No op
867
868 }
869  
870  
871 0 ▶sub redirect {
Subroutine redirect: not called CC=1 SCAR=0.0
Pod undocumented
872  
873 # No op
874  
875 }
876  
877  
878  
879 0 ▶sub as_string {
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
880  
881 0 my $r=shift();
882 0 my @return;
883 0 push @return, join(' ', map {$r->$_} qw(method unparsed_uri protocol));
884 0 push @return, $r->headers_in->as_string();
885 0 push @return, undef; #Blank line between headers and body
886 0 push @return, $r->body();
887 0 return join("\n", grep {$_} @return);
888  
889 }
890  
891  
892 0 ▶sub mtime {
Subroutine mtime: not called CC=1 SCAR=6.9
Pod undocumented
893  
894 0 shift()->finfo->mtime();
895  
896 }
897  
898 0 ▶sub next {
Subroutine next: not called CC=1 SCAR=0.0
Pod undocumented
899  
900 }
901  
902  
903 0 ▶sub preferred_charset {
Subroutine preferred_charset: not called CC=1 SCAR=6.9
Pod undocumented
904  
905 0 return &preferred_media_type(@_);
906
907 }
908  
909 0 ▶sub preferred_encoding {
Subroutine preferred_encoding: not called CC=1 SCAR=6.9
Pod undocumented
910  
911 0 return &preferred_media_type(@_);
912
913 }
914  
915  
916 0 ▶sub preferred_language {
Subroutine preferred_language: not called CC=2 SCAR=17.9
Pod undocumented
917  
918 0 my ($r, $lang_ar, @param)=@_;
919 0 ▶ unless (ref($lang_ar) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $lang_ar eq "ARRAY") 0 0 0
920 0 $lang_ar=[$lang_ar, @param];
921 }
922 0 return HTTP::AcceptLanguage->new($r->accept_language())->match(@{$lang_ar});
923
924  
925 }
926  
927  
928 0 ▶sub preferred_media_type {
Subroutine preferred_media_type: not called CC=2 SCAR=17.9
Pod undocumented
929  
930 0 my ($r, $variant_ar, @param)=@_;
931 0 ▶ unless (ref($variant_ar) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $variant_ar eq "ARRAY") 0 0 0
932 0 $variant_ar=[map {[$_]} $variant_ar, @param];
933 }
934 0 return choose($variant_ar, $r->headers_in);
935  
936 }
937  
938  
939 0 ▶sub session {
Subroutine session: not called CC=1 SCAR=0.0
Pod undocumented
940  
941 }
942  
943 0 ▶sub session_id {
Subroutine session_id: not called CC=1 SCAR=0.0
Pod undocumented
944  
945 }
946  
947 0 ▶sub route {
Subroutine route: not called CC=1 SCAR=0.0
Pod undocumented
948  
949 }
950  
951 0 ▶sub path_parameters {
Subroutine path_parameters: not called CC=1 SCAR=0.0
Pod undocumented
952  
953 }
954  
955  
956 0 ▶sub sendfile {
Subroutine sendfile: not called CC=1 SCAR=0.0
Pod undocumented
957  
958 }
959  
960  
961 0 ▶sub finfo {
Subroutine finfo: not called CC=1 SCAR=6.9
Pod undocumented
962  
963 0 return stat(shift->filename());
964
965 }
966  
967 0 ▶sub form_parameters {
Subroutine form_parameters: not called CC=1 SCAR=0.0
Pod undocumented
968  
969 }
970  
971 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=0.0
Pod undocumented
972  
973 }
974  
975 0 ▶sub multipart_parameters {
Subroutine multipart_parameters: not called CC=1 SCAR=0.0
Pod undocumented
976  
977 }
978  
979 0 ▶sub query_parameters {
Subroutine query_parameters: not called CC=1 SCAR=0.2
Pod undocumented
980  
981 5 ▶ use Hash::MultiValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
982 0 return Hash::MultiValue->new(shift()->uri->query_form);
983  
984 }
985  
986 0 ▶sub request_time {
Subroutine request_time: not called CC=1 SCAR=0.0
Pod undocumented
987  
988 }
989  
990 0 ▶sub scheme {
Subroutine scheme: not called CC=1 SCAR=6.9
Pod undocumented
991  
992 0 return 'http',
993
994 }
995  
996  
997 0 ▶sub uploads {
Subroutine uploads: not called CC=1 SCAR=0.0
Pod undocumented
998  
999 }
1000  
1001  
1002 # Error handling, autoload
1003  
1004  
1005 0 ▶sub err_html {
Subroutine err_html: not called CC=4 SCAR=30.0
Pod undocumented
1006  
1007 # Very basic HTML error messages for file not found and similar
1008 #
1009 0 my ($r, $status, $error)=@_;
1010 0 require WebDyne::HTML::Tiny;
1011 0 ▶ my $html_or=WebDyne::HTML::Tiny->new( mode=>$WEBDYNE_HTML_TINY_MODE, r=>$r ) ||
Condition0%0/2
'WebDyne::HTML::Tiny'->new('mode', $WebDyne::Request::Fake::WEBDYNE_HTML_TINY_MODE, 'r', $r) || (return err())
l!l
00
MC/DC0%0/1
'WebDyne::HTML::Tiny'->new('mode', $WebDyne::Request::Fake::WEBDYNE_HTML_TINY_MODE, 'r', $r) || (return err())
'WebDyne::HTML::Tiny'->new('mode', $WebDyne::Request::Fake::WEBDYNE_HTML_TINY_MODE, 'r', $r)
Truth table0%0/2
A
A= 'WebDyne::HTML::Tiny'->new('mode', $WebDyne::Request::Fake::WEBDYNE_HTML_TINY_MODE, 'r', $r)
Aresult
11
00
1012 return err();
1013 #my $heading=sprintf("%s error - $error", ref($r) || __PACKAGE__);
1014 0 ▶ my $heading=sprintf("%s error.", ref($r) || __PACKAGE__);
Condition0%0/2
ref $r || __PACKAGE__
l!l
00
MC/DC0%0/1
ref $r || __PACKAGE__
ref $r
Truth table0%0/2
A
A= ref $r
Aresult
11
00
1015 0 ▶ my @body=(
Condition0%0/2
&status_message($status) || 'Unknown Error'
l!l
00
MC/DC0%0/1
&status_message($status) || 'Unknown Error'
&status_message($status)
Truth table0%0/2
A
A= &status_message($status)
Aresult
11
00
1016 $html_or->start_html(title=>"WebDyne Error: $status"),
1017 $html_or->h3($heading),
1018 $html_or->hr(),
1019 $html_or->em(status_message($status) || 'Unknown Error'), $html_or->br(), $html_or->br(),
1020 $html_or->pre(
1021 sprintf("The requested URI '%s' generated error:\n\n$error", $r->uri)
1022 ),
1023 $html_or->end_html()
1024 );
1025 0 return join('', @body);
1026  
1027 }
1028  
1029  
1030 0 ▶sub AUTOLOAD { #no subsort
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
1031  
1032 0 my ($r, $v)=@_;
1033 0 debug("$r AUTOLOAD: $AUTOLOAD, v: $v");
1034 0 ▶ my $k=($AUTOLOAD=~/([^:]+)$/) && $1;
Condition0%0/3
$WebDyne::Request::Fake::AUTOLOAD =~ /([^:]+)$/ && $1
!ll&&!rl&&r
000
MC/DC0%0/2
$WebDyne::Request::Fake::AUTOLOAD =~ /([^:]+)$/ && $1
$WebDyne::Request::Fake::AUTOLOAD =~ /([^:]+)$/ $1
Truth table0%0/3
A && B
A= $WebDyne::Request::Fake::AUTOLOAD =~ /([^:]+)$/B= $1
ABresult
0X0
100
111
1035 0 warn(sprintf("Unhandled '%s' method, using AUTOLOAD. Caller:%s", $k, Dumper([caller(0)])));
1036 0 ▶ $v ? $r->{$k}=$v : $r->{$k};
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
1037  
1038  
1039 }
1040  
1041  
1042 21 ▶sub DESTROY { #no subsort
Subroutine DESTROY: called CC=3 SCAR=15.7
1043  
1044 21 my $r=shift();
1045 21 debug("$r DESTROY");
1046 21 ▶ if (my $cr_ar=delete $r->{'register_cleanup'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cr_ar = delete $r->{'register_cleanup'}) { } 0 21 21
1047 0 debug('found cleanup code refs: %s', Dumper($cr_ar));
1048 0 foreach my $cr (grep {ref($_) eq 'CODE'} @{$cr_ar}) {
1049 0 debug("running code ref: $cr against r: $r");
1050 0 $cr->($r);
1051 }
1052 }
1053 else {
1054 21 debug('no cleanup code registered');
1055 }
1056  
1057 }
1058  
1059 __END__
« blib/lib/WebDyne/HTML/Tiny.pm ↑ Summary blib/lib/WebDyne/Request/Common.pm »