| 1 | package PAGI::Request; | ||||||||||||||||||||||||||||||
| 2 | 23 | $PAGI::Request::VERSION = '0.002002'; | |||||||||||||||||||||||||||||
| 3 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 23 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 23 | ▶ | use Hash::MultiValue; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 23 | ▶ | use PAGI::Headers (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 23 | ▶ | use Encode qw(decode FB_CROAK FB_DEFAULT LEAVE_SRC); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 23 | ▶ | use Cookie::Baker qw(crush_cookie); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 23 | ▶ | use MIME::Base64 qw(decode_base64); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 23 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 23 | ▶ | use JSON::MaybeXS qw(decode_json); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | 23 | ▶ | use Carp qw(croak carp); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 23 | ▶ | use PAGI::Request::MultiPartHandler; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 23 | ▶ | use PAGI::Request::Upload; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 23 | ▶ | use PAGI::Request::Negotiate; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use PAGI::Request::BodyStream; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | 110 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 19 | 110 | my ($class, $scope, $receive) = @_; | |||||||||||||||||||||||||||||
| 20 | 110 | return bless { | |||||||||||||||||||||||||||||
| 21 | scope => $scope, | ||||||||||||||||||||||||||||||
| 22 | receive => $receive, | ||||||||||||||||||||||||||||||
| 23 | }, $class; | ||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | # Basic properties from scope | ||||||||||||||||||||||||||||||
| 27 | 55 | ▶ | sub method { shift->{scope}{method} } | ||||||||||||||||||||||||||||
|
Subroutine
method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | sub path { shift->{scope}{path} } | ||||||||||||||||||||||||||||
|
Subroutine
path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub raw_path { my $s = shift; $s->{scope}{raw_path} // $s->{scope}{path} } | ||||||||||||||||||||||||||||
|
Subroutine
raw_path: called CC=2 SCAR=7.1
Pod
documented
Condition66%2/3
$s->{"scope"}{"raw_path"} // $s->{"scope"}{"path"}
MC/DC0%0/2
$s->{"scope"}{"raw_path"} // $s->{"scope"}{"path"}
$s->{"scope"}{"raw_path"}
$s->{"scope"}{"path"}
Truth table66%2/3
A // B
A= $s->{"scope"}{"raw_path"}B= $s->{"scope"}{"path"}
| |||||||||||||||||||||||||||||||
| 30 | 12 | ▶ | sub query_string { shift->{scope}{query_string} // '' } | ||||||||||||||||||||||||||||
|
Subroutine
query_string: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
+(shift())->{"scope"}{"query_string"} // ""
MC/DC100%1/1
+(shift())->{"scope"}{"query_string"} // ""
+(shift())->{"scope"}{"query_string"}
Truth table100%2/2
A
A= +(shift())->{"scope"}{"query_string"}
| |||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | sub scheme { shift->{scope}{scheme} // 'http' } | ||||||||||||||||||||||||||||
|
Subroutine
scheme: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
+(shift())->{"scope"}{"scheme"} // "http"
MC/DC100%1/1
+(shift())->{"scope"}{"scheme"} // "http"
+(shift())->{"scope"}{"scheme"}
Truth table100%2/2
A
A= +(shift())->{"scope"}{"scheme"}
| |||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | sub http_version { shift->{scope}{http_version} // '1.1' } | ||||||||||||||||||||||||||||
|
Subroutine
http_version: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
+(shift())->{"scope"}{"http_version"} // "1.1"
MC/DC100%1/1
+(shift())->{"scope"}{"http_version"} // "1.1"
+(shift())->{"scope"}{"http_version"}
Truth table100%2/2
A
A= +(shift())->{"scope"}{"http_version"}
| |||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub client { shift->{scope}{client} } | ||||||||||||||||||||||||||||
|
Subroutine
client: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | sub raw { shift->{scope} } | ||||||||||||||||||||||||||||
|
Subroutine
raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | # Internal: URL decode a string (handles + as space) | ||||||||||||||||||||||||||||||
| 37 | 40 | ▶ | sub _url_decode { | ||||||||||||||||||||||||||||
|
Subroutine
_url_decode: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||
| 38 | 40 | my ($str) = @_; | |||||||||||||||||||||||||||||
| 39 | 40 | ▶ | return '' unless defined $str; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 40 | 40 | $str =~ s/\+/ /g; | |||||||||||||||||||||||||||||
| 41 | 40 | $str =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge; | |||||||||||||||||||||||||||||
| 42 | 40 | return $str; | |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | # Internal: Decode UTF-8 with replacement or croak in strict mode | ||||||||||||||||||||||||||||||
| 46 | 41 | ▶ | sub _decode_utf8 { | ||||||||||||||||||||||||||||
|
Subroutine
_decode_utf8: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||
| 47 | 41 | my ($str, $strict) = @_; | |||||||||||||||||||||||||||||
| 48 | 41 | ▶ | return '' unless defined $str; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 49 | 41 | ▶ | my $flag = $strict ? FB_CROAK : FB_DEFAULT; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 50 | 41 | $flag |= LEAVE_SRC; | |||||||||||||||||||||||||||||
| 51 | 41 | return decode('UTF-8', $str, $flag); | |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | # Host from headers | ||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | sub host { | ||||||||||||||||||||||||||||
|
Subroutine
host: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 56 | 1 | my $self = shift; | |||||||||||||||||||||||||||||
| 57 | 1 | return $self->header('host'); | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | # Content-Type shortcut | ||||||||||||||||||||||||||||||
| 61 | 18 | ▶ | sub content_type { | ||||||||||||||||||||||||||||
|
Subroutine
content_type: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 62 | 18 | my $self = shift; | |||||||||||||||||||||||||||||
| 63 | 18 | ▶ | my $ct = $self->header('content-type') // ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$self->header("content-type") // ""
MC/DC0%0/1
$self->header("content-type") // ""
$self->header("content-type")
Truth table50%1/2
A
A= $self->header("content-type")
| |||||||||||||||||||||||||||||||
| 64 | # Strip parameters like charset | ||||||||||||||||||||||||||||||
| 65 | 18 | $ct =~ s/;.*//; | |||||||||||||||||||||||||||||
| 66 | 18 | return $ct; | |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | # Content-Length shortcut | ||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | sub content_length { | ||||||||||||||||||||||||||||
|
Subroutine
content_length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 71 | 4 | my $self = shift; | |||||||||||||||||||||||||||||
| 72 | 4 | return $self->header('content-length'); | |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | # Private cache: the source of truth for header lookups (built once per request). | ||||||||||||||||||||||||||||||
| 76 | 72 | ▶ | sub _header_snapshot { | ||||||||||||||||||||||||||||
|
Subroutine
_header_snapshot: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||
| 77 | 72 | my $self = shift; | |||||||||||||||||||||||||||||
| 78 | return $self->{scope}{'pagi.request.headers'} | ||||||||||||||||||||||||||||||
| 79 | 72 | ▶ | //= PAGI::Headers->new($self->{scope}{headers} // []); | ||||||||||||||||||||||||||||
|
Condition60%3/5
$self->{"scope"}{"pagi.request.headers"} //= "PAGI::Headers"->new($self->{"scope"}{"headers"} // [])
$self->{"scope"}{"headers"} // []
MC/DC0%0/2
$self->{"scope"}{"pagi.request.headers"} //= "PAGI::Headers"->new($self->{"scope"}{"headers"} // [])
$self->{"scope"}{"pagi.request.headers"}
"PAGI::Headers"->new($self->{"scope"}{"headers"} // [])
MC/DC0%0/1
$self->{"scope"}{"headers"} // []
$self->{"scope"}{"headers"}
Truth table66%2/3
A //= B
A= $self->{"scope"}{"pagi.request.headers"}B= "PAGI::Headers"->new($self->{"scope"}{"headers"} // [])
Truth table50%1/2
A
A= $self->{"scope"}{"headers"}
| |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | # Public: a PAGI::Headers snapshot of the inbound headers. Returns an independent | ||||||||||||||||||||||||||||||
| 83 | # CLONE so mutating it cannot poison later header()/content_type()/cookie lookups. | ||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | sub headers { return $_[0]->_header_snapshot->clone } | ||||||||||||||||||||||||||||
|
Subroutine
headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | # Single header lookup (case-insensitive, last value) | ||||||||||||||||||||||||||||||
| 87 | 56 | ▶ | sub header { return $_[0]->_header_snapshot->get($_[1]) } | ||||||||||||||||||||||||||||
|
Subroutine
header: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | # All values for a header | ||||||||||||||||||||||||||||||
| 90 | 13 | ▶ | sub header_all { return $_[0]->_header_snapshot->get_all($_[1]) } | ||||||||||||||||||||||||||||
|
Subroutine
header_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | # Query params as Hash::MultiValue (cached in scope) | ||||||||||||||||||||||||||||||
| 93 | # Options: strict => 1 (croak on invalid UTF-8), raw => 1 (skip UTF-8 decoding) | ||||||||||||||||||||||||||||||
| 94 | 15 | ▶ | sub query_params { | ||||||||||||||||||||||||||||
|
Subroutine
query_params: called CC=13 SCAR=27.3
Pod
documented
| |||||||||||||||||||||||||||||||
| 95 | 15 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 96 | 15 | ▶ | my $strict = delete $opts{strict} // 0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{"strict"} // 0
MC/DC0%0/1
delete $opts{"strict"} // 0
delete $opts{"strict"}
Truth table50%1/2
A
A= delete $opts{"strict"}
| |||||||||||||||||||||||||||||||
| 97 | 15 | ▶ | my $raw = delete $opts{raw} // 0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{"raw"} // 0
MC/DC0%0/1
delete $opts{"raw"} // 0
delete $opts{"raw"}
Truth table50%1/2
A
A= delete $opts{"raw"}
| |||||||||||||||||||||||||||||||
| 98 | 15 | ▶ | croak("Unknown options to query_params: " . join(', ', keys %opts)) if %opts; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | 15 | ▶ | my $cache_key = $raw ? 'pagi.request.query.raw' : ($strict ? 'pagi.request.query.strict' : 'pagi.request.query'); | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 101 | 15 | ▶ | return $self->{scope}{$cache_key} if $self->{scope}{$cache_key}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | 9 | my $qs = $self->query_string; | |||||||||||||||||||||||||||||
| 104 | 9 | my @pairs; | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | 9 | for my $part (split /[&;]/, $qs) { | |||||||||||||||||||||||||||||
| 107 | 14 | ▶ | next unless length $part; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 108 | 14 | my ($key, $val) = split /=/, $part, 2; | |||||||||||||||||||||||||||||
| 109 | 14 | ▶ | $key //= ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$key //= ""
MC/DC0%0/1
$key //= ""
$key
Truth table50%1/2
A
A= $key
| |||||||||||||||||||||||||||||||
| 110 | 14 | ▶ | $val //= ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$val //= ""
MC/DC0%0/1
$val //= ""
$val
Truth table50%1/2
A
A= $val
| |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||
| 112 | # URL decode (handles + as space) | ||||||||||||||||||||||||||||||
| 113 | 14 | my $key_decoded = _url_decode($key); | |||||||||||||||||||||||||||||
| 114 | 14 | my $val_decoded = _url_decode($val); | |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | # UTF-8 decode unless raw mode | ||||||||||||||||||||||||||||||
| 117 | 14 | ▶ | my $key_final = $raw ? $key_decoded : _decode_utf8($key_decoded, $strict); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 118 | 14 | ▶ | my $val_final = $raw ? $val_decoded : _decode_utf8($val_decoded, $strict); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | 14 | push @pairs, $key_final, $val_final; | |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | 9 | $self->{scope}{$cache_key} = Hash::MultiValue->new(@pairs); | |||||||||||||||||||||||||||||
| 124 | 9 | return $self->{scope}{$cache_key}; | |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | # Raw query params (no UTF-8 decoding) | ||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub raw_query_params { | ||||||||||||||||||||||||||||
|
Subroutine
raw_query_params: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 129 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 130 | 0 | return $self->query_params(raw => 1); | |||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | # Shortcut for single query param | ||||||||||||||||||||||||||||||
| 134 | 12 | ▶ | sub query_param { | ||||||||||||||||||||||||||||
|
Subroutine
query_param: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 135 | 12 | my ($self, $name, %opts) = @_; | |||||||||||||||||||||||||||||
| 136 | 12 | return $self->query_params(%opts)->get($name); | |||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | # DEPRECATED: Alias with warning | ||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub query { | ||||||||||||||||||||||||||||
|
Subroutine
query: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 142 | 0 | carp "query() is deprecated; use query_param() instead"; | |||||||||||||||||||||||||||||
| 143 | 0 | return $self->query_param(@_); | |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||
| 146 | # Raw single query param | ||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub raw_query_param { | ||||||||||||||||||||||||||||
|
Subroutine
raw_query_param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 148 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||
| 149 | 0 | return $self->query_param($name, raw => 1); | |||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||
| 152 | # DEPRECATED: Alias with warning | ||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub raw_query { | ||||||||||||||||||||||||||||
|
Subroutine
raw_query: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 154 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 155 | 0 | carp "raw_query() is deprecated; use raw_query_param() instead"; | |||||||||||||||||||||||||||||
| 156 | 0 | return $self->raw_query_param(@_); | |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||
| 159 | # All cookies as hashref (cached in scope) | ||||||||||||||||||||||||||||||
| 160 | 7 | ▶ | sub cookies { | ||||||||||||||||||||||||||||
|
Subroutine
cookies: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 161 | 7 | my $self = shift; | |||||||||||||||||||||||||||||
| 162 | 7 | ▶ | return $self->{scope}{'pagi.request.cookies'} if exists $self->{scope}{'pagi.request.cookies'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||
| 164 | 4 | ▶ | my $cookie_header = $self->header('cookie') // ''; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$self->header("cookie") // ""
MC/DC100%1/1
$self->header("cookie") // ""
$self->header("cookie")
Truth table100%2/2
A
A= $self->header("cookie")
| |||||||||||||||||||||||||||||||
| 165 | 4 | $self->{scope}{'pagi.request.cookies'} = crush_cookie($cookie_header); | |||||||||||||||||||||||||||||
| 166 | 4 | return $self->{scope}{'pagi.request.cookies'}; | |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||
| 169 | # Single cookie value | ||||||||||||||||||||||||||||||
| 170 | 5 | ▶ | sub cookie { | ||||||||||||||||||||||||||||
|
Subroutine
cookie: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 171 | 5 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||
| 172 | 5 | return $self->cookies->{$name}; | |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||
| 175 | # Method predicates | ||||||||||||||||||||||||||||||
| 176 | 9 | ▶ | sub is_get { uc(shift->method // '') eq 'GET' } | ||||||||||||||||||||||||||||
|
Subroutine
is_get: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
(shift())->method // ""
MC/DC0%0/1
(shift())->method // ""
(shift())->method
Truth table50%1/2
A
A= (shift())->method
| |||||||||||||||||||||||||||||||
| 177 | 9 | ▶ | sub is_post { uc(shift->method // '') eq 'POST' } | ||||||||||||||||||||||||||||
|
Subroutine
is_post: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
(shift())->method // ""
MC/DC0%0/1
(shift())->method // ""
(shift())->method
Truth table50%1/2
A
A= (shift())->method
| |||||||||||||||||||||||||||||||
| 178 | 7 | ▶ | sub is_put { uc(shift->method // '') eq 'PUT' } | ||||||||||||||||||||||||||||
|
Subroutine
is_put: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
(shift())->method // ""
MC/DC0%0/1
(shift())->method // ""
(shift())->method
Truth table50%1/2
A
A= (shift())->method
| |||||||||||||||||||||||||||||||
| 179 | 7 | ▶ | sub is_patch { uc(shift->method // '') eq 'PATCH' } | ||||||||||||||||||||||||||||
|
Subroutine
is_patch: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
(shift())->method // ""
MC/DC0%0/1
(shift())->method // ""
(shift())->method
Truth table50%1/2
A
A= (shift())->method
| |||||||||||||||||||||||||||||||
| 180 | 7 | ▶ | sub is_delete { uc(shift->method // '') eq 'DELETE' } | ||||||||||||||||||||||||||||
|
Subroutine
is_delete: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
(shift())->method // ""
MC/DC0%0/1
(shift())->method // ""
(shift())->method
Truth table50%1/2
A
A= (shift())->method
| |||||||||||||||||||||||||||||||
| 181 | 7 | ▶ | sub is_head { uc(shift->method // '') eq 'HEAD' } | ||||||||||||||||||||||||||||
|
Subroutine
is_head: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
(shift())->method // ""
MC/DC0%0/1
(shift())->method // ""
(shift())->method
Truth table50%1/2
A
A= (shift())->method
| |||||||||||||||||||||||||||||||
| 182 | 7 | ▶ | sub is_options { uc(shift->method // '') eq 'OPTIONS' } | ||||||||||||||||||||||||||||
|
Subroutine
is_options: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
(shift())->method // ""
MC/DC0%0/1
(shift())->method // ""
(shift())->method
Truth table50%1/2
A
A= (shift())->method
| |||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | # ============================================================================= | ||||||||||||||||||||||||||||||
| 185 | # Connection State Methods (PAGI spec 0.3) | ||||||||||||||||||||||||||||||
| 186 | # | ||||||||||||||||||||||||||||||
| 187 | # These methods provide non-destructive disconnect detection via the | ||||||||||||||||||||||||||||||
| 188 | # pagi.connection scope key, which is a PAGI::Server::ConnectionState object. | ||||||||||||||||||||||||||||||
| 189 | # ============================================================================= | ||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||
| 191 | # Get the connection state object | ||||||||||||||||||||||||||||||
| 192 | 5 | ▶ | sub connection { | ||||||||||||||||||||||||||||
|
Subroutine
connection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 193 | 5 | my $self = shift; | |||||||||||||||||||||||||||||
| 194 | 5 | return $self->{scope}{'pagi.connection'}; | |||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | # Check if client is still connected (synchronous, non-destructive) | ||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub is_connected { | ||||||||||||||||||||||||||||
|
Subroutine
is_connected: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 199 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 200 | 0 | my $conn = $self->connection; | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | return 0 unless $conn; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 202 | 0 | return $conn->is_connected; | |||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||
| 205 | # Check if client has disconnected (synchronous, non-destructive) | ||||||||||||||||||||||||||||||
| 206 | # This is the inverse of is_connected - preferred for new code | ||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | sub is_disconnected { | ||||||||||||||||||||||||||||
|
Subroutine
is_disconnected: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 208 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 209 | 0 | return !$self->is_connected; | |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||
| 212 | # Get the disconnect reason string, or undef if still connected | ||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub disconnect_reason { | ||||||||||||||||||||||||||||
|
Subroutine
disconnect_reason: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 214 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 215 | 0 | my $conn = $self->connection; | |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | return undef unless $conn; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 217 | 0 | return $conn->disconnect_reason; | |||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||
| 220 | # Register a callback to be invoked on an abnormal disconnect (not on a clean | ||||||||||||||||||||||||||||||
| 221 | # finish). The counterpart to on_complete; exactly one of the two fires. | ||||||||||||||||||||||||||||||
| 222 | 3 | ▶ | sub on_disconnect { | ||||||||||||||||||||||||||||
|
Subroutine
on_disconnect: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 223 | 3 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||
| 224 | 3 | my $conn = $self->connection; | |||||||||||||||||||||||||||||
| 225 | 3 | ▶ | $conn->on_disconnect($cb) if $conn; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 226 | 3 | return $self; | |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | # Register a callback to be invoked only when the request completes successfully. | ||||||||||||||||||||||||||||||
| 230 | # The counterpart to on_disconnect; exactly one of the two fires. | ||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | sub on_complete { | ||||||||||||||||||||||||||||
|
Subroutine
on_complete: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 232 | 2 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||
| 233 | 2 | my $conn = $self->connection; | |||||||||||||||||||||||||||||
| 234 | 2 | ▶ | $conn->on_complete($cb) if $conn; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 235 | 2 | return $self; | |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||
| 238 | # Get a Future that resolves when the client disconnects | ||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | sub disconnect_future { | ||||||||||||||||||||||||||||
|
Subroutine
disconnect_future: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 240 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 241 | 0 | my $conn = $self->connection; | |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | return undef unless $conn; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 243 | 0 | return $conn->disconnect_future; | |||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||
| 246 | # Outbound flow-control introspection (delegates to the pagi.transport handle) | ||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | sub buffered_amount { | ||||||||||||||||||||||||||||
|
Subroutine
buffered_amount: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 248 | 2 | my $self = shift; | |||||||||||||||||||||||||||||
| 249 | 2 | my $t = $self->{scope}{'pagi.transport'}; | |||||||||||||||||||||||||||||
| 250 | 2 | ▶ | return 0 unless $t; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 251 | 1 | return $t->buffered_amount; | |||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||
| 254 | 2 | ▶ | sub high_water_mark { | ||||||||||||||||||||||||||||
|
Subroutine
high_water_mark: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 255 | 2 | my $self = shift; | |||||||||||||||||||||||||||||
| 256 | 2 | my $t = $self->{scope}{'pagi.transport'}; | |||||||||||||||||||||||||||||
| 257 | 2 | ▶ | return undef unless $t; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 258 | 1 | return $t->high_water_mark; | |||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | 2 | ▶ | sub low_water_mark { | ||||||||||||||||||||||||||||
|
Subroutine
low_water_mark: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 262 | 2 | my $self = shift; | |||||||||||||||||||||||||||||
| 263 | 2 | my $t = $self->{scope}{'pagi.transport'}; | |||||||||||||||||||||||||||||
| 264 | 2 | ▶ | return undef unless $t; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 265 | 1 | return $t->low_water_mark; | |||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||
| 268 | 2 | ▶ | sub on_high_water { | ||||||||||||||||||||||||||||
|
Subroutine
on_high_water: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 269 | 2 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||
| 270 | 2 | my $t = $self->{scope}{'pagi.transport'}; | |||||||||||||||||||||||||||||
| 271 | 2 | ▶ | $t->on_high_water($cb) if $t && $t->can('on_high_water'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t and $t->can("on_high_water")
MC/DC50%1/2
$t and $t->can("on_high_water")
$t
$t->can("on_high_water")
Truth table66%2/3
A and B
A= $tB= $t->can("on_high_water")
| |||||||||||||||||||||||||||||||
| 272 | 2 | return $self; | |||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||
| 275 | 2 | ▶ | sub on_drain { | ||||||||||||||||||||||||||||
|
Subroutine
on_drain: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 276 | 2 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||
| 277 | 2 | my $t = $self->{scope}{'pagi.transport'}; | |||||||||||||||||||||||||||||
| 278 | 2 | ▶ | $t->on_drain($cb) if $t && $t->can('on_drain'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t and $t->can("on_drain")
MC/DC50%1/2
$t and $t->can("on_drain")
$t
$t->can("on_drain")
Truth table66%2/3
A and B
A= $tB= $t->can("on_drain")
| |||||||||||||||||||||||||||||||
| 279 | 2 | return $self; | |||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||
| 282 | 3 | ▶ | sub is_writable { | ||||||||||||||||||||||||||||
|
Subroutine
is_writable: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 283 | 3 | my $self = shift; | |||||||||||||||||||||||||||||
| 284 | 3 | my $t = $self->{scope}{'pagi.transport'}; | |||||||||||||||||||||||||||||
| 285 | 3 | ▶ | return 1 unless $t; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 286 | 2 | my $high = $t->high_water_mark; | |||||||||||||||||||||||||||||
| 287 | 2 | ▶ | return 1 unless defined $high; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 288 | 2 | ▶ | return $t->buffered_amount < $high ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||
| 291 | # Content-type predicates | ||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub is_json { | ||||||||||||||||||||||||||||
|
Subroutine
is_json: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 293 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 294 | 0 | my $ct = $self->content_type; | |||||||||||||||||||||||||||||
| 295 | 0 | return $ct eq 'application/json'; | |||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | sub is_form { | ||||||||||||||||||||||||||||
|
Subroutine
is_form: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 299 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 300 | 0 | my $ct = $self->content_type; | |||||||||||||||||||||||||||||
| 301 | 0 | ▶ | return $ct eq 'application/x-www-form-urlencoded' | ||||||||||||||||||||||||||||
|
Condition0%0/3
$ct eq 'application/x-www-form-urlencoded' || $ct =~ m[^multipart/form-data]
MC/DC0%0/2
$ct eq 'application/x-www-form-urlencoded' || $ct =~ m[^multipart/form-data]
$ct eq 'application/x-www-form-urlencoded'
$ct =~ m[^multipart/form-data]
Truth table0%0/3
A || B
A= $ct eq 'application/x-www-form-urlencoded'B= $ct =~ m[^multipart/form-data]
| |||||||||||||||||||||||||||||||
| 302 | || $ct =~ m{^multipart/form-data}; | ||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||
| 305 | 14 | ▶ | sub is_multipart { | ||||||||||||||||||||||||||||
|
Subroutine
is_multipart: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 306 | 14 | my $self = shift; | |||||||||||||||||||||||||||||
| 307 | 14 | my $ct = $self->content_type; | |||||||||||||||||||||||||||||
| 308 | 14 | return $ct =~ m{^multipart/form-data}; | |||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||
| 311 | # Accept header check using Negotiate module | ||||||||||||||||||||||||||||||
| 312 | # Combines multiple Accept headers per RFC 7230 Section 3.2.2 | ||||||||||||||||||||||||||||||
| 313 | 7 | ▶ | sub accepts { | ||||||||||||||||||||||||||||
|
Subroutine
accepts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 314 | 7 | my ($self, $mime_type) = @_; | |||||||||||||||||||||||||||||
| 315 | 7 | my @accept_values = $self->header_all('accept'); | |||||||||||||||||||||||||||||
| 316 | 7 | my $accept = join(', ', @accept_values); | |||||||||||||||||||||||||||||
| 317 | 7 | return PAGI::Request::Negotiate->accepts_type($accept, $mime_type); | |||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||
| 320 | # Find best matching content type from supported list | ||||||||||||||||||||||||||||||
| 321 | # Combines multiple Accept headers per RFC 7230 Section 3.2.2 | ||||||||||||||||||||||||||||||
| 322 | 4 | ▶ | sub preferred_type { | ||||||||||||||||||||||||||||
|
Subroutine
preferred_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 323 | 4 | my ($self, @types) = @_; | |||||||||||||||||||||||||||||
| 324 | 4 | my @accept_values = $self->header_all('accept'); | |||||||||||||||||||||||||||||
| 325 | 4 | my $accept = join(', ', @accept_values); | |||||||||||||||||||||||||||||
| 326 | 4 | return PAGI::Request::Negotiate->best_match(\@types, $accept); | |||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||
| 329 | # Extract Bearer token from Authorization header | ||||||||||||||||||||||||||||||
| 330 | 3 | ▶ | sub bearer_token { | ||||||||||||||||||||||||||||
|
Subroutine
bearer_token: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 331 | 3 | my $self = shift; | |||||||||||||||||||||||||||||
| 332 | 3 | ▶ | my $auth = $self->header('authorization') // ''; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$self->header("authorization") // ""
MC/DC100%1/1
$self->header("authorization") // ""
$self->header("authorization")
Truth table100%2/2
A
A= $self->header("authorization")
| |||||||||||||||||||||||||||||||
| 333 | 3 | ▶ | if ($auth =~ /^Bearer\s+(.+)$/i) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 334 | 1 | return $1; | |||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||
| 336 | 2 | return undef; | |||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||
| 339 | # Extract Basic auth credentials | ||||||||||||||||||||||||||||||
| 340 | 3 | ▶ | sub basic_auth { | ||||||||||||||||||||||||||||
|
Subroutine
basic_auth: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 341 | 3 | my $self = shift; | |||||||||||||||||||||||||||||
| 342 | 3 | ▶ | my $auth = $self->header('authorization') // ''; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$self->header("authorization") // ""
MC/DC100%1/1
$self->header("authorization") // ""
$self->header("authorization")
Truth table100%2/2
A
A= $self->header("authorization")
| |||||||||||||||||||||||||||||||
| 343 | 3 | ▶ | if ($auth =~ /^Basic\s+(.+)$/i) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 344 | 2 | my $decoded = decode_base64($1); | |||||||||||||||||||||||||||||
| 345 | 2 | my ($user, $pass) = split /:/, $decoded, 2; | |||||||||||||||||||||||||||||
| 346 | 2 | return ($user, $pass); | |||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||
| 348 | 1 | return (undef, undef); | |||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||
| 351 | # Path parameters - captured from URL path by router | ||||||||||||||||||||||||||||||
| 352 | # Stored in scope->{path_params} for router-agnostic access | ||||||||||||||||||||||||||||||
| 353 | 33 | ▶ | sub path_params { | ||||||||||||||||||||||||||||
|
Subroutine
path_params: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 354 | 33 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 355 | 33 | my $strict = delete $opts{strict}; | |||||||||||||||||||||||||||||
| 356 | 33 | ▶ | croak("Unknown options to path_params: " . join(', ', keys %opts)) if %opts; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||
| 358 | 32 | my $params = $self->{scope}{path_params}; | |||||||||||||||||||||||||||||
| 359 | 32 | ▶ | if (!defined $params && $strict) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $params and $strict
MC/DC100%2/2
not defined $params and $strict
not defined $params
$strict
Truth table100%3/3
not(A) and B
A= not defined $paramsB= $strict
| |||||||||||||||||||||||||||||||
| 360 | 1 | croak "path_params not set in scope (no router configured?). " | |||||||||||||||||||||||||||||
| 361 | . "Pass strict => 0 to allow this."; | ||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||
| 363 | 31 | ▶ | return $params // {}; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$params // {}
MC/DC100%1/1
$params // {}
$params
Truth table100%2/2
A
A= $params
| |||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||
| 366 | 19 | ▶ | sub _default_path_param_strict_opt { return 1 } | ||||||||||||||||||||||||||||
|
Subroutine
_default_path_param_strict_opt: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||
| 368 | 25 | ▶ | sub path_param { | ||||||||||||||||||||||||||||
|
Subroutine
path_param: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 369 | 25 | my ($self, $name, %opts) = @_; | |||||||||||||||||||||||||||||
| 370 | 25 | ▶ | my $strict = exists $opts{strict} ? delete $opts{strict} : $self->_default_path_param_strict_opt; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 371 | 25 | ▶ | croak("Unknown options to path_param: " . join(', ', keys %opts)) if %opts; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||
| 373 | 25 | my $params = $self->path_params; | |||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||
| 375 | 25 | ▶ | if ($strict && !exists $params->{$name}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$strict and not exists $params->{$name}
MC/DC100%2/2
$strict and not exists $params->{$name}
$strict
not exists $params->{$name}
Truth table100%3/3
A and not(B)
A= $strictB= not exists $params->{$name}
| |||||||||||||||||||||||||||||||
| 376 | 8 | my @available = keys %$params; | |||||||||||||||||||||||||||||
| 377 | 8 | ▶ | croak "path_param '$name' not found. " | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 378 | . (@available ? "Available: " . join(', ', sort @available) : "No path params set (no router?)"); | ||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||
| 381 | 17 | return $params->{$name}; | |||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||
| 384 | 9 | ▶ | sub scope { shift->{scope} } | ||||||||||||||||||||||||||||
|
Subroutine
scope: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||
| 386 | # Vend a detached response bound to this request's scope (the raw-app analog | ||||||||||||||||||||||||||||||
| 387 | # of $ctx->response). It is a value, not a connection; call ->respond($send) | ||||||||||||||||||||||||||||||
| 388 | # to send it. | ||||||||||||||||||||||||||||||
| 389 | 2 | ▶ | sub response { | ||||||||||||||||||||||||||||
|
Subroutine
response: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 390 | 2 | my $self = shift; | |||||||||||||||||||||||||||||
| 391 | 2 | require PAGI::Response; | |||||||||||||||||||||||||||||
| 392 | 2 | return PAGI::Response->new($self->{scope}); | |||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||
| 396 | # Application state (injected by PAGI::Lifespan, read-only) | ||||||||||||||||||||||||||||||
| 397 | 7 | ▶ | sub state { | ||||||||||||||||||||||||||||
|
Subroutine
state: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 398 | 7 | my $self = shift; | |||||||||||||||||||||||||||||
| 399 | 7 | ▶ | return $self->{scope}{state} // {}; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"scope"}{"state"} // {}
MC/DC100%1/1
$self->{"scope"}{"state"} // {}
$self->{"scope"}{"state"}
Truth table100%2/2
A
A= $self->{"scope"}{"state"}
| |||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||
| 402 | # Body streaming - mutually exclusive with buffered body methods | ||||||||||||||||||||||||||||||
| 403 | 3 | ▶ | sub body_stream { | ||||||||||||||||||||||||||||
|
Subroutine
body_stream: called CC=6 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 404 | 3 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||
| 406 | 3 | ▶ | croak "Body already consumed; streaming not available" if $self->{scope}{'pagi.request.body.read'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 407 | 2 | ▶ | croak "Body streaming already started" if $self->{scope}{'pagi.request.body.stream.created'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||
| 409 | 2 | $self->{scope}{'pagi.request.body.stream.created'} = 1; | |||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||
| 411 | 2 | my $max_bytes = $opts{max_bytes}; | |||||||||||||||||||||||||||||
| 412 | 2 | ▶ | my $limit_name = defined $max_bytes ? 'max_bytes' : undef; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 413 | 2 | ▶ | if (!defined $max_bytes) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 414 | 2 | my $cl = $self->content_length; | |||||||||||||||||||||||||||||
| 415 | 2 | ▶ | if (defined $cl) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 416 | 0 | $max_bytes = $cl; | |||||||||||||||||||||||||||||
| 417 | 0 | $limit_name = 'content-length'; | |||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||
| 421 | return PAGI::Request::BodyStream->new( | ||||||||||||||||||||||||||||||
| 422 | receive => $self->{receive}, | ||||||||||||||||||||||||||||||
| 423 | max_bytes => $max_bytes, | ||||||||||||||||||||||||||||||
| 424 | limit_name => $limit_name, | ||||||||||||||||||||||||||||||
| 425 | decode => $opts{decode}, | ||||||||||||||||||||||||||||||
| 426 | strict => $opts{strict}, | ||||||||||||||||||||||||||||||
| 427 | 2 | ); | |||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||
| 430 | # Streaming multipart - mutually exclusive with buffered body methods | ||||||||||||||||||||||||||||||
| 431 | 6 | ▶ | sub multipart_stream { | ||||||||||||||||||||||||||||
|
Subroutine
multipart_stream: called CC=9 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||||
| 432 | 6 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 433 | croak "Body already consumed; multipart_stream() not available" | ||||||||||||||||||||||||||||||
| 434 | if $self->{scope}{'pagi.request.body.read'} | ||||||||||||||||||||||||||||||
| 435 | 6 | ▶ | || $self->{scope}{'pagi.request.body.stream.created'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"scope"}{"pagi.request.body.read"} or $self->{"scope"}{"pagi.request.body.stream.created"}
MC/DC100%2/2
$self->{"scope"}{"pagi.request.body.read"} or $self->{"scope"}{"pagi.request.body.stream.created"}
$self->{"scope"}{"pagi.request.body.read"}
$self->{"scope"}{"pagi.request.body.stream.created"}
Truth table100%3/3
A or B
A= $self->{"scope"}{"pagi.request.body.read"}B= $self->{"scope"}{"pagi.request.body.stream.created"}
| |||||||||||||||||||||||||||||||
| 436 | 4 | ▶ | croak "multipart_stream() requires a multipart/form-data request" unless $self->is_multipart; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||
| 438 | 3 | ▶ | my $ct = $self->header('content-type') // ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$self->header("content-type") // ""
MC/DC0%0/1
$self->header("content-type") // ""
$self->header("content-type")
Truth table50%1/2
A
A= $self->header("content-type")
| |||||||||||||||||||||||||||||||
| 439 | 3 | my ($boundary) = $ct =~ /boundary=([^;\s]+)/; | |||||||||||||||||||||||||||||
| 440 | 3 | ▶ | $boundary =~ s/^["']|["']$//g if defined $boundary; # Strip quotes | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 441 | 3 | ▶ | croak "No boundary found in Content-Type" unless defined $boundary && length $boundary; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $boundary and length $boundary
MC/DC0%0/2
defined $boundary and length $boundary
defined $boundary
length $boundary
Truth table33%1/3
A and B
A= defined $boundaryB= length $boundary
| |||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||
| 443 | 3 | $self->{scope}{'pagi.request.body.stream.created'} = 1; # latch: lock out buffered readers | |||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||
| 445 | 3 | require PAGI::Request::MultipartStream; | |||||||||||||||||||||||||||||
| 446 | return PAGI::Request::MultipartStream->new( | ||||||||||||||||||||||||||||||
| 447 | receive => $self->{receive}, | ||||||||||||||||||||||||||||||
| 448 | boundary => $boundary, | ||||||||||||||||||||||||||||||
| 449 | 3 | ▶ | map { defined $opts{$_} ? ($_ => $opts{$_}) : () } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 450 | qw(max_files max_fields max_field_size max_file_size max_request_body), | ||||||||||||||||||||||||||||||
| 451 | ); | ||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||
| 454 | # Read raw body bytes (async, cached in scope) | ||||||||||||||||||||||||||||||
| 455 | 13 | ▶ | async sub body { | ||||||||||||||||||||||||||||
|
Subroutine
body: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||
| 456 | 13 | my $self = shift; | |||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||
| 458 | croak "Body streaming already started; buffered helpers unavailable" | ||||||||||||||||||||||||||||||
| 459 | 13 | ▶ | if $self->{scope}{'pagi.request.body.stream.created'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||
| 461 | # Return cached body if already read | ||||||||||||||||||||||||||||||
| 462 | 12 | ▶ | return $self->{scope}{'pagi.request.body'} if $self->{scope}{'pagi.request.body.read'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||
| 464 | 11 | my $receive = $self->{receive}; | |||||||||||||||||||||||||||||
| 465 | 11 | ▶ | die "No receive callback provided" unless $receive; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||
| 467 | 11 | my $body = ''; | |||||||||||||||||||||||||||||
| 468 | 11 | while (1) { | |||||||||||||||||||||||||||||
| 469 | 13 | my $message = await $receive->(); | |||||||||||||||||||||||||||||
| 470 | 13 | ▶ | last unless $message && $message->{type}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$message and $message->{"type"}
MC/DC0%0/2
$message and $message->{"type"}
$message
$message->{"type"}
Truth table33%1/3
A and B
A= $messageB= $message->{"type"}
| |||||||||||||||||||||||||||||||
| 471 | 13 | ▶ | last if $message->{type} eq 'http.disconnect'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||
| 473 | 12 | ▶ | $body .= $message->{body} // ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$message->{"body"} // ""
MC/DC0%0/1
$message->{"body"} // ""
$message->{"body"}
Truth table50%1/2
A
A= $message->{"body"}
| |||||||||||||||||||||||||||||||
| 474 | 12 | ▶ | last unless $message->{more}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||
| 477 | 11 | $self->{scope}{'pagi.request.body'} = $body; | |||||||||||||||||||||||||||||
| 478 | 11 | $self->{scope}{'pagi.request.body.read'} = 1; | |||||||||||||||||||||||||||||
| 479 | 11 | return $body; | |||||||||||||||||||||||||||||
| 480 | 23 | } | |||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||
| 482 | # Read body as decoded UTF-8 text (async) | ||||||||||||||||||||||||||||||
| 483 | # Options: strict => 1 (croak on invalid UTF-8) | ||||||||||||||||||||||||||||||
| 484 | 1 | ▶ | async sub text { | ||||||||||||||||||||||||||||
|
Subroutine
text: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 485 | 1 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 486 | 1 | ▶ | my $strict = delete $opts{strict} // 0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{"strict"} // 0
MC/DC0%0/1
delete $opts{"strict"} // 0
delete $opts{"strict"}
Truth table50%1/2
A
A= delete $opts{"strict"}
| |||||||||||||||||||||||||||||||
| 487 | 1 | ▶ | croak("Unknown options to text: " . join(', ', keys %opts)) if %opts; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||
| 489 | 1 | my $body = await $self->body; | |||||||||||||||||||||||||||||
| 490 | 1 | return _decode_utf8($body, $strict); | |||||||||||||||||||||||||||||
| 491 | 23 | } | |||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||
| 493 | # Parse body as JSON (async, dies on error) | ||||||||||||||||||||||||||||||
| 494 | 2 | ▶ | async sub json { | ||||||||||||||||||||||||||||
|
Subroutine
json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 495 | 2 | my $self = shift; | |||||||||||||||||||||||||||||
| 496 | 2 | my $body = await $self->body; | |||||||||||||||||||||||||||||
| 497 | 2 | return decode_json($body); | |||||||||||||||||||||||||||||
| 498 | 23 | } | |||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||
| 500 | # Parse URL-encoded form body (async, returns Hash::MultiValue, cached in scope) | ||||||||||||||||||||||||||||||
| 501 | # Options: strict => 1 (croak on invalid UTF-8), raw => 1 (skip UTF-8 decoding) | ||||||||||||||||||||||||||||||
| 502 | 8 | ▶ | async sub form_params { | ||||||||||||||||||||||||||||
|
Subroutine
form_params: called CC=16 SCAR=29.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 503 | 8 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 504 | 8 | ▶ | my $strict = delete $opts{strict} // 0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{"strict"} // 0
MC/DC0%0/1
delete $opts{"strict"} // 0
delete $opts{"strict"}
Truth table50%1/2
A
A= delete $opts{"strict"}
| |||||||||||||||||||||||||||||||
| 505 | 8 | ▶ | my $raw = delete $opts{raw} // 0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{"raw"} // 0
MC/DC0%0/1
delete $opts{"raw"} // 0
delete $opts{"raw"}
Truth table50%1/2
A
A= delete $opts{"raw"}
| |||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||
| 507 | # Extract multipart options before checking for unknown opts | ||||||||||||||||||||||||||||||
| 508 | 8 | my %multipart_opts; | |||||||||||||||||||||||||||||
| 509 | 8 | for my $key (qw(max_field_size max_file_size spool_threshold max_files max_fields temp_dir)) { | |||||||||||||||||||||||||||||
| 510 | 48 | ▶ | $multipart_opts{$key} = delete $opts{$key} if exists $opts{$key}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||
| 512 | 8 | ▶ | croak("Unknown options to form_params: " . join(', ', keys %opts)) if %opts; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||
| 514 | 8 | ▶ | my $cache_key = $raw ? 'pagi.request.form.raw' : ($strict ? 'pagi.request.form.strict' : 'pagi.request.form'); | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||
| 516 | # Return cached if available | ||||||||||||||||||||||||||||||
| 517 | 8 | ▶ | return $self->{scope}{$cache_key} if $self->{scope}{$cache_key}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||
| 519 | # For multipart, delegate to uploads handling | ||||||||||||||||||||||||||||||
| 520 | 7 | ▶ | if ($self->is_multipart) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 521 | # Multipart always parses to default cache, then copy | ||||||||||||||||||||||||||||||
| 522 | 3 | my $form = await $self->_parse_multipart_form(%multipart_opts); | |||||||||||||||||||||||||||||
| 523 | 2 | $self->{scope}{$cache_key} = $form; | |||||||||||||||||||||||||||||
| 524 | 2 | return $form; | |||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||
| 527 | # URL-encoded form | ||||||||||||||||||||||||||||||
| 528 | 4 | my $body = await $self->body; | |||||||||||||||||||||||||||||
| 529 | 4 | my @pairs; | |||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||
| 531 | 4 | for my $part (split /[&;]/, $body) { | |||||||||||||||||||||||||||||
| 532 | 6 | ▶ | next unless length $part; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 533 | 6 | my ($key, $val) = split /=/, $part, 2; | |||||||||||||||||||||||||||||
| 534 | 6 | ▶ | $key //= ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$key //= ""
MC/DC0%0/1
$key //= ""
$key
Truth table50%1/2
A
A= $key
| |||||||||||||||||||||||||||||||
| 535 | 6 | ▶ | $val //= ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$val //= ""
MC/DC0%0/1
$val //= ""
$val
Truth table50%1/2
A
A= $val
| |||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||
| 537 | # URL decode (handles + as space) | ||||||||||||||||||||||||||||||
| 538 | 6 | my $key_decoded = _url_decode($key); | |||||||||||||||||||||||||||||
| 539 | 6 | my $val_decoded = _url_decode($val); | |||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||
| 541 | # UTF-8 decode unless raw mode | ||||||||||||||||||||||||||||||
| 542 | 6 | ▶ | my $key_final = $raw ? $key_decoded : _decode_utf8($key_decoded, $strict); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 543 | 6 | ▶ | my $val_final = $raw ? $val_decoded : _decode_utf8($val_decoded, $strict); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||
| 545 | 6 | push @pairs, $key_final, $val_final; | |||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||
| 548 | 4 | $self->{scope}{$cache_key} = Hash::MultiValue->new(@pairs); | |||||||||||||||||||||||||||||
| 549 | 4 | return $self->{scope}{$cache_key}; | |||||||||||||||||||||||||||||
| 550 | 23 | } | |||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||
| 552 | # DEPRECATED: Alias with warning | ||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | async sub form { | ||||||||||||||||||||||||||||
|
Subroutine
form: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 554 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 555 | 0 | carp "form() is deprecated; use form_params() instead"; | |||||||||||||||||||||||||||||
| 556 | 0 | return await $self->form_params(@_); | |||||||||||||||||||||||||||||
| 557 | 23 | } | |||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||
| 559 | # Singular accessor for form params | ||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | async sub form_param { | ||||||||||||||||||||||||||||
|
Subroutine
form_param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 561 | 0 | my ($self, $name, %opts) = @_; | |||||||||||||||||||||||||||||
| 562 | 0 | my $form = await $self->form_params(%opts); | |||||||||||||||||||||||||||||
| 563 | 0 | return $form->get($name); | |||||||||||||||||||||||||||||
| 564 | 23 | } | |||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||
| 566 | # Raw form params (no UTF-8 decoding) | ||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | async sub raw_form_params { | ||||||||||||||||||||||||||||
|
Subroutine
raw_form_params: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 568 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 569 | 0 | return await $self->form_params(%opts, raw => 1); | |||||||||||||||||||||||||||||
| 570 | 23 | } | |||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||
| 572 | # DEPRECATED: Alias with warning | ||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | async sub raw_form { | ||||||||||||||||||||||||||||
|
Subroutine
raw_form: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 574 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 575 | 0 | carp "raw_form() is deprecated; use raw_form_params() instead"; | |||||||||||||||||||||||||||||
| 576 | 0 | return await $self->raw_form_params(@_); | |||||||||||||||||||||||||||||
| 577 | 23 | } | |||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||
| 579 | # Raw singular accessor | ||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | async sub raw_form_param { | ||||||||||||||||||||||||||||
|
Subroutine
raw_form_param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 581 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||
| 582 | 0 | return await $self->form_param($name, raw => 1); | |||||||||||||||||||||||||||||
| 583 | 23 | } | |||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||
| 585 | # Parse multipart form (internal, cached in scope) | ||||||||||||||||||||||||||||||
| 586 | 6 | ▶ | async sub _parse_multipart_form { | ||||||||||||||||||||||||||||
|
Subroutine
_parse_multipart_form: called CC=7 SCAR=20.2
| |||||||||||||||||||||||||||||||
| 587 | 6 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||
| 589 | croak "Body streaming already started; buffered helpers unavailable" | ||||||||||||||||||||||||||||||
| 590 | 6 | ▶ | if $self->{scope}{'pagi.request.body.stream.created'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||
| 592 | # Already parsed? | ||||||||||||||||||||||||||||||
| 593 | return $self->{scope}{'pagi.request.form'} | ||||||||||||||||||||||||||||||
| 594 | 5 | ▶ | if $self->{scope}{'pagi.request.form'} && $self->{scope}{'pagi.request.uploads'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"scope"}{"pagi.request.form"} and $self->{"scope"}{"pagi.request.uploads"}
MC/DC0%0/2
$self->{"scope"}{"pagi.request.form"} and $self->{"scope"}{"pagi.request.uploads"}
$self->{"scope"}{"pagi.request.form"}
$self->{"scope"}{"pagi.request.uploads"}
Truth table33%1/3
A and B
A= $self->{"scope"}{"pagi.request.form"}B= $self->{"scope"}{"pagi.request.uploads"}
| |||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||
| 596 | # Extract boundary from content-type | ||||||||||||||||||||||||||||||
| 597 | 5 | ▶ | my $ct = $self->header('content-type') // ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$self->header("content-type") // ""
MC/DC0%0/1
$self->header("content-type") // ""
$self->header("content-type")
Truth table50%1/2
A
A= $self->header("content-type")
| |||||||||||||||||||||||||||||||
| 598 | 5 | my ($boundary) = $ct =~ /boundary=([^;\s]+)/; | |||||||||||||||||||||||||||||
| 599 | 5 | ▶ | $boundary =~ s/^["']|["']$//g if $boundary; # Strip quotes | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||
| 601 | 5 | ▶ | die "No boundary found in Content-Type" unless $boundary; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||
| 603 | my $handler = PAGI::Request::MultiPartHandler->new( | ||||||||||||||||||||||||||||||
| 604 | boundary => $boundary, | ||||||||||||||||||||||||||||||
| 605 | receive => $self->{receive}, | ||||||||||||||||||||||||||||||
| 606 | max_field_size => $opts{max_field_size}, | ||||||||||||||||||||||||||||||
| 607 | max_file_size => $opts{max_file_size}, | ||||||||||||||||||||||||||||||
| 608 | spool_threshold => $opts{spool_threshold}, | ||||||||||||||||||||||||||||||
| 609 | max_files => $opts{max_files}, | ||||||||||||||||||||||||||||||
| 610 | max_fields => $opts{max_fields}, | ||||||||||||||||||||||||||||||
| 611 | temp_dir => $opts{temp_dir}, | ||||||||||||||||||||||||||||||
| 612 | 5 | ); | |||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||
| 614 | 5 | my ($form, $uploads) = await $handler->parse; | |||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||
| 616 | 5 | $self->{scope}{'pagi.request.form'} = $form; | |||||||||||||||||||||||||||||
| 617 | 5 | $self->{scope}{'pagi.request.uploads'} = $uploads; | |||||||||||||||||||||||||||||
| 618 | 5 | $self->{scope}{'pagi.request.body.read'} = 1; # Body has been consumed | |||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||
| 620 | 5 | return $form; | |||||||||||||||||||||||||||||
| 621 | 23 | } | |||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||
| 623 | # Get all uploads as Hash::MultiValue (cached in scope) | ||||||||||||||||||||||||||||||
| 624 | 4 | ▶ | async sub uploads { | ||||||||||||||||||||||||||||
|
Subroutine
uploads: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 625 | 4 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||
| 627 | 4 | ▶ | return $self->{scope}{'pagi.request.uploads'} if $self->{scope}{'pagi.request.uploads'}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||
| 629 | 3 | ▶ | if ($self->is_multipart) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 630 | 3 | await $self->_parse_multipart_form(%opts); | |||||||||||||||||||||||||||||
| 631 | 3 | return $self->{scope}{'pagi.request.uploads'}; | |||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||
| 634 | # Not multipart - return empty | ||||||||||||||||||||||||||||||
| 635 | 0 | $self->{scope}{'pagi.request.uploads'} = Hash::MultiValue->new(); | |||||||||||||||||||||||||||||
| 636 | 0 | return $self->{scope}{'pagi.request.uploads'}; | |||||||||||||||||||||||||||||
| 637 | 23 | } | |||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||
| 639 | # Get single upload by field name | ||||||||||||||||||||||||||||||
| 640 | 2 | ▶ | async sub upload { | ||||||||||||||||||||||||||||
|
Subroutine
upload: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 641 | 2 | my ($self, $name, %opts) = @_; | |||||||||||||||||||||||||||||
| 642 | 2 | my $uploads = await $self->uploads(%opts); | |||||||||||||||||||||||||||||
| 643 | 2 | return $uploads->get($name); | |||||||||||||||||||||||||||||
| 644 | 23 | } | |||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||
| 646 | # Get all uploads for a field name | ||||||||||||||||||||||||||||||
| 647 | 1 | ▶ | async sub upload_all { | ||||||||||||||||||||||||||||
|
Subroutine
upload_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 648 | 1 | my ($self, $name, %opts) = @_; | |||||||||||||||||||||||||||||
| 649 | 1 | my $uploads = await $self->uploads(%opts); | |||||||||||||||||||||||||||||
| 650 | 1 | return $uploads->get_all($name); | |||||||||||||||||||||||||||||
| 651 | 23 | } | |||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||
| 653 | 23 | 1; | |||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||
| 655 | __END__ | ||||||||||||||||||||||||||||||