| 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 | 5 | ▶ | use strict qw(vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use vars qw($VERSION @ISA @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | no warnings qw(uninitialized once); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # External modules | ||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||
| 26 | 5 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | use WebDyne::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | use B (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 5 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Exports | ||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||
| 34 | 5 | @EXPORT_OK=qw(handler_methods_all handler_methods_check handler_methods_init); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Version information | ||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||
| 39 | 5 | $VERSION='3.029'; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # Debug load | ||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||
| 44 | 5 | debug("Loading %s version $VERSION", __PACKAGE__); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # All done. Positive return | ||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||
| 49 | 5 | 1; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | #================================================================================================== | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 5 | ▶ | 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 | 5 | my ($self, $type)=@_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # Read methods | ||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||
| 64 | 5 | 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 | |||||||||||||||||||||||||||||
| 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 | 5 | return \@method_all; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 5 | ▶ | 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 | 5 | my ($class, $method_hr)=@_; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | # Make sure we don't have more methods defined here than we need | ||||||||||||||||||||||||||||
| 188 | # | ||||||||||||||||||||||||||||
| 189 | 5 | my %method_class=%{$method_hr}; | |||||||||||||||||||||||||||
| 190 | 5 | my @method_package=grep { $_ eq lc($_) } grep { defined *{sprintf('%s::%s', $class, $_)}{'CODE'} } keys %{sprintf('%s::', $class)}; | |||||||||||||||||||||||||||
| 191 | 5 | my %method_package=map { $_=>1 } @method_package; | |||||||||||||||||||||||||||
| 192 | 5 | map { delete $method_package{$_} } keys %method_class; | |||||||||||||||||||||||||||
| 193 | 5 | my @method_orphan; | |||||||||||||||||||||||||||
| 194 | 5 | foreach my $method (keys %method_package) { | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # Skip new, init and any private methods that start with _ | ||||||||||||||||||||||||||||
| 197 | 100 | ▶ | next if grep { $method eq $_ } qw(new init err_html res req sse ws); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | # PAGI shares this scope utility with its application dispatcher. | ||||||||||||||||||||||||||||
| 199 | 80 | ▶ | next if $class eq 'WebDyne::Request::PAGI' && $method eq 'scope_path'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class eq "WebDyne::Request::PAGI" and $method eq "scope_path"
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"
| |||||||||||||||||||||||||||||
| 200 | 80 | ▶ | next if $method=~/^_/;; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 80 | ▶ | if (my $cr=*{sprintf('%s::%s', $class, $method)}{'CODE'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 80 | ▶ | if (my $gv=B::svref_2object($cr)->GV) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 80 | ▶ | if ($gv->STASH->NAME eq $class) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 0 | push @method_orphan, $method; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 5 | ▶ | if (@method_orphan) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 5 | %method_class=%{$method_hr}; | |||||||||||||||||||||||||||
| 219 | 5 | foreach my $method (sort @{&handler_methods_all}) { | |||||||||||||||||||||||||||
| 220 | 535 | ▶ | unless (defined(delete($method_class{$method}))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | warn "missing method definition: $method in class: $class"; | |||||||||||||||||||||||||||
| 222 | #sleep 1; | ||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 535 | ▶ | unless ($class->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | warn "missing method function: $method in class: $class"; | |||||||||||||||||||||||||||
| 226 | #sleep 1; | ||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | 5 | ▶ | if (keys(%method_class)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | warn(sprintf("extra methods in class: $class, %s", Dumper([keys %method_class]))); | |||||||||||||||||||||||||||
| 231 | #sleep 1; | ||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 5 | 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 | debug("method: $method, dispatch: $dispatch"); | |||||||||||||||||||||||||||
| 246 | 0 | $method_check{$method}++; | |||||||||||||||||||||||||||
| 247 | 0 | ▶ | if (ref($dispatch) eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if (defined(*{sprintf('%s::%s', __PACKAGE__, $method)}{'CODE'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | # Do nothing, defined here | ||||||||||||||||||||||||||||
| 251 | # | ||||||||||||||||||||||||||||
| 252 | 0 | debug("skip $method, defined in this package"); | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | else { | ||||||||||||||||||||||||||||
| 255 | 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 | 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 | debug("setting method: $method to $handler: $dispatch"); | |||||||||||||||||||||||||||
| 270 | 0 | ▶ | if ($handler->can($dispatch)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 5 | 1; | |||||||||||||||||||||||||||
| 284 | __END__ | ||||||||||||||||||||||||||||