| 1 | package Uniform::Upload::PAGI; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use parent 'Uniform::Upload'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '1.01'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # Constructor: Explicitly expects an asynchronous PAGI HTTP connection scope hash reference | ||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||
| 12 | 2 | ▶ | my ($class, $scope) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=28.5
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | unless (defined $scope && ref($scope) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $scope and ref $scope eq "HASH"
MC/DC0%0/2
defined $scope and ref $scope eq "HASH"
defined $scope
ref $scope eq "HASH"
Truth table33%1/3
A and B
A= defined $scopeB= ref $scope eq "HASH"
| |||||||||||||||||||||||||||||
| 15 | 0 | require Uniform::Exceptions; | |||||||||||||||||||||||||||
| 16 | 0 | Uniform::Exceptions->throw( | |||||||||||||||||||||||||||
| 17 | type => 'TypeError', | ||||||||||||||||||||||||||||
| 18 | message => 'PAGI scope context must be a strict HASH reference', | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | unless (defined $scope->{type} && $scope->{type} eq 'http') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $scope->{"type"} and $scope->{"type"} eq "http"
MC/DC50%1/2
defined $scope->{"type"} and $scope->{"type"} eq "http"
defined $scope->{"type"}
$scope->{"type"} eq "http"
Truth table66%2/3
A and B
A= defined $scope->{"type"}B= $scope->{"type"} eq "http"
| |||||||||||||||||||||||||||||
| 23 | 1 | require Uniform::Exceptions; | |||||||||||||||||||||||||||
| 24 | 1 | Uniform::Exceptions->throw( | |||||||||||||||||||||||||||
| 25 | type => 'ValidationError', | ||||||||||||||||||||||||||||
| 26 | message => 'Not a valid PAGI HTTP connection scope', | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | my $self = bless { files => {}, _ctx => $scope }, $class; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Extract PAGI multipart attachments if parsed by the gateway pipeline. | ||||||||||||||||||||||||||||
| 33 | # The PAGI spec exposes uploaded files inside an array reference block: $scope->{uploads} | ||||||||||||||||||||||||||||
| 34 | # where each element is a hash containing: field, tempname, filename, size, and type. | ||||||||||||||||||||||||||||
| 35 | 1 | ▶ | my $uploads = $scope->{uploads} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$scope->{'uploads'} || []
MC/DC0%0/1
$scope->{'uploads'} || []
$scope->{'uploads'}
Truth table50%1/2
A
A= $scope->{'uploads'}
| |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if (ref($uploads) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 1 | foreach my $upload_payload (@$uploads) { | |||||||||||||||||||||||||||
| 38 | 2 | ▶ | next unless ref($upload_payload) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | my $field = $upload_payload->{field}; | |||||||||||||||||||||||||||
| 41 | 2 | ▶ | next unless defined $field && length $field; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $field and length $field
MC/DC0%0/2
defined $field and length $field
defined $field
length $field
Truth table33%1/3
A and B
A= defined $fieldB= length $field
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Map values explicitly to match your core layout specification expectations. | ||||||||||||||||||||||||||||
| 44 | # If duplicate field keys are passed, the trailing definition overrides prior entries, | ||||||||||||||||||||||||||||
| 45 | # respecting the strict last-scalar-wins policy standard of your ecosystem. | ||||||||||||||||||||||||||||
| 46 | $self->{files}->{$field} = { | ||||||||||||||||||||||||||||
| 47 | tempname => $upload_payload->{tempname}, | ||||||||||||||||||||||||||||
| 48 | filename => $upload_payload->{filename}, | ||||||||||||||||||||||||||||
| 49 | size => $upload_payload->{size} || 0, | ||||||||||||||||||||||||||||
| 50 | type => $upload_payload->{type}, | ||||||||||||||||||||||||||||
| 51 | 2 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$upload_payload->{'size'} || 0
MC/DC0%0/1
$upload_payload->{'size'} || 0
$upload_payload->{'size'}
Truth table50%1/2
A
A= $upload_payload->{'size'}
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | return $self; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||