blib/lib/WebDyne/Request/Common.pm

filter: Statementstmt 67.7% 63 / 93 Branchbran 39.2% 11 / 28 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 3 totaltotal 60.2% 85 / 141 CC 19 SCAR 28.4
CC
19
Cov
60%
handler_methods_init
42.0
handler_methods_check
17.9
__ANON__
2.0
CRAP 17.1
« lib/WebDyne/Request/Fake.pm ↑ Summary lib/WebDyne/Request/Common.pm »
1 #
2 # This file is part of WebDyne.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package WebDyne::Request::Common;
14  
15  
16 # Compiler Pragma
17 #
18 32 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 32 ▶use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 32 ▶no warnings qw(uninitialized once);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23  
24 # External modules
25 #
26 32 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 32 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 32 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 32 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31  
32 # Exports
33 #
34 32 @EXPORT_OK=qw(handler_methods_all handler_methods_check handler_methods_init);
35  
36  
37 # Version information
38 #
39 32 $VERSION='3.029';
40  
41  
42 # Debug load
43 #
44 32 0 && debug("Loading %s version $VERSION", __PACKAGE__);
45  
46  
47 # All done. Positive return
48 #
49 32 1;
50  
51 #==================================================================================================
52  
53  
54 32 ▶sub handler_methods_all {
Subroutine handler_methods_all: called CC=1 SCAR=0.0
Pod undocumented
55  
56  
57 # Return list of methods that should be supported
58 #
59 32 my ($self, $type)=@_;
60
61  
62 # Read methods
63 #
64 32 my @method_all=(qw(
65 accept
66 accept_encoding
67 accept_language
68 args
69 as_string
70 authority
71 authorization
72 auth_type
73 base
74 base_url
75 body
76 body_handle
77 cache_control
78 charset
79 cleanup_register
80 client_address
81 content
82 content_encoding
83 content_length
84 content_type
85 cookie
86 cookies
87 custom_response
88 cwd
89 dir_config
90 document_root
91 env
92 etag
93 filename
94 finalize
95 finfo
96 form_parameters
97 forwarded_for
98 fragment
99 handler
100 header
101 headers
102 header_only
103 headers_in
104 headers_out
105 host
106 hostname
107 https
108 http_version
109 id
110 if_modified_since
111 if_none_match
112 input
113 is_ajax
114 is_main
115 location
116 log_error
117 lookup_file
118 lookup_uri
119 main
120 media_type
121 method
122 mtime
123 multipart_parameters
124 next
125 notes
126 origin
127 output_filters
128 path
129 path_info
130 path_parameters
131 pool
132 preferred_charset
133 preferred_encoding
134 preferred_language
135 preferred_media_type
136 prev
137 print
138 protocol
139 query_parameters
140 query_string
141 redirect
142 referer
143 register_cleanup
144 remote_address
145 remote_host
146 remote_port
147 remote_user
148 request_time
149 route
150 run
151 scheme
152 script_name
153 secure
154 sendfile
155 send_http_header
156 server_name
157 server_port
158 session
159 session_id
160 set_handlers
161 status
162 status_line
163 unparsed_uri
164 uploads
165 uri
166 url
167 user
168 user_agent
169 write
170 err_html
171 DESTROY
172 ));
173  
174 32 return \@method_all;
175
176 }
177
178  
179 32 ▶sub handler_methods_check {
Subroutine handler_methods_check: called CC=14 SCAR=28.9
Pod undocumented
180  
181  
182 # Check all methods have been defined in handler
183 #
184 32 my ($class, $method_hr)=@_;
185
186
187 # Make sure we don't have more methods defined here than we need
188 #
189 32 my %method_class=%{$method_hr};
190 32 my @method_package=grep { $_ eq lc($_) } grep { defined *{sprintf('%s::%s', $class, $_)}{'CODE'} } keys %{sprintf('%s::', $class)};
191 32 my %method_package=map { $_=>1 } @method_package;
192 32 map { delete $method_package{$_} } keys %method_class;
193 32 my @method_orphan;
194 32 foreach my $method (keys %method_package) {
195
196 # Skip new, init and any private methods that start with _
197 640 ▶ next if grep { $method eq $_ } qw(new init err_html res req sse ws);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$method eq $_;} "new", "init", "err_html", "res", "req", "sse", "ws" 128 512 640
198 # PAGI shares this scope utility with its application dispatcher.
199 512 ▶ next if $class eq 'WebDyne::Request::PAGI' && $method eq 'scope_path';
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "WebDyne::Request::PAGI" and $method eq "scope_path" 0 512 512
Condition33%1/3
$class eq "WebDyne::Request::PAGI" and $method eq "scope_path"
!ll&&!rl&&r
51200
MC/DC0%0/2
$class eq "WebDyne::Request::PAGI" and $method eq "scope_path"
$class eq "WebDyne::Request::PAGI" $method eq "scope_path"
Truth table33%1/3
A and B
A= $class eq "WebDyne::Request::PAGI"B= $method eq "scope_path"
ABresult
0X0
100
111
200 512 ▶ next if $method=~/^_/;;
Branch: 1 branch
BranchTrueFalseTotal
if $method =~ /^_/ 0 512 512
201
202 512 ▶ if (my $cr=*{sprintf('%s::%s', $class, $method)}{'CODE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cr = *{sprintf '%s::%s', $class, $method;}{"CODE"}) 512 0 512
203 512 ▶ if (my $gv=B::svref_2object($cr)->GV) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $gv = B::svref_2object($cr)->GV) 512 0 512
204 512 ▶ if ($gv->STASH->NAME eq $class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gv->STASH->NAME eq $class) 0 512 512
205 0 push @method_orphan, $method;
206 }
207 }
208 }
209 }
210 32 ▶ if (@method_orphan) {
Branch: 1 branch
BranchTrueFalseTotal
if (@method_orphan) 0 32 32
211 0 warn(sprintf("orphan methods in class: $class, %s", Dumper(\@method_orphan)));
212 #sleep 1;
213 }
214
215  
216 # Check we haven't missed any defining any methods
217 #
218 32 %method_class=%{$method_hr};
219 32 foreach my $method (sort @{&handler_methods_all}) {
220 3424 ▶ unless (defined(delete($method_class{$method}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined delete $method_class{$method}) 0 3424 3424
221 0 warn "missing method definition: $method in class: $class";
222 #sleep 1;
223 }
224 3424 ▶ unless ($class->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can($method)) 0 3424 3424
225 0 warn "missing method function: $method in class: $class";
226 #sleep 1;
227 }
228 }
229 32 ▶ if (keys(%method_class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %method_class) 0 32 32
230 0 warn(sprintf("extra methods in class: $class, %s", Dumper([keys %method_class])));
231 #sleep 1;
232 }
233 32 1;
234
235 }
236  
237  
238 0 ▶sub handler_methods_init {
Subroutine handler_methods_init: not called CC=6 SCAR=37.4
Pod undocumented
239  
240 0 my ($class, $handler, $method_hr)=@_;
241
242 0 my %method_check;
243 0 foreach my $method (sort keys %{$method_hr}) {
244 0 my $dispatch=$method_hr->{$method};
245 0 0 && debug("method: $method, dispatch: $dispatch");
246 0 $method_check{$method}++;
247 0 ▶ if (ref($dispatch) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $dispatch eq 'CODE') { } 0 0 0
elsif (not defined $dispatch) { } 0 0 0
248  
249 0 ▶ if (defined(*{sprintf('%s::%s', __PACKAGE__, $method)}{'CODE'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{sprintf '%s::%s', __PACKAGE__, $method;}{'CODE'}) { } 0 0 0
250 # Do nothing, defined here
251 #
252 0 0 && debug("skip $method, defined in this package");
253 }
254 else {
255 0 0 && debug("setting method: $method to code ref: $dispatch");
256 0 *{"${class}::${method}"}=$dispatch;
257 }
258  
259 }
260 elsif (!defined($dispatch)) {
261 # Do nothing, will fall through to Fake
262 #
263 0 0 && debug("skip $method, will inherit from Fake");
264 0 *{"${class}::${method}"}=\&{"WebDyne::Request::Fake::${method}"};
265 }
266 else {
267 # Class request method
268 #
269 0 0 && debug("setting method: $method to $handler: $dispatch");
270 0 ▶ if ($handler->can($dispatch)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler->can($dispatch)) { } 0 0 0
271 0 ▶ *{"${class}::${method}"}=sub { shift()->{'req'}->$dispatch(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
272 }
273 else {
274 0 die "unsupported request method: $dispatch";
275 }
276 }
277 }
278
279 0 return handler_methods_check($class, \%method_check);
280
281 }
282
283 32 1;
284 __END__
« lib/WebDyne/Request/Fake.pm ↑ Summary lib/WebDyne/Request/Common.pm »