| 1 | package Uniform::Upload::PAGI; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use parent 'Uniform::Upload'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | our $VERSION = '1.02'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 4 | my ($class, @args) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | my ($scope, %opts); | |||||||||||||||||||||||||||
| 15 | 4 | ▶ | if (@args % 2 != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 3 | $scope = shift @args; | |||||||||||||||||||||||||||
| 17 | 3 | %opts = @args; | |||||||||||||||||||||||||||
| 18 | } else { | ||||||||||||||||||||||||||||
| 19 | 1 | %opts = @args; | |||||||||||||||||||||||||||
| 20 | 1 | $scope = delete $opts{scope}; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | ▶ | croak "Scope must be a HASH reference" if defined $scope && ref($scope) ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $scope and ref $scope ne "HASH"
MC/DC50%1/2
defined $scope and ref $scope ne "HASH"
defined $scope
ref $scope ne "HASH"
Truth table66%2/3
A and B
A= defined $scopeB= ref $scope ne "HASH"
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | return $class->SUPER::new(in => $scope, %opts); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub extract_async { | ||||||||||||||||||||||||||
|
Subroutine
extract_async: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($self, $receive) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | my $scope = $self->{in}; | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | croak "PAGI scope required to extract uploads" unless defined $scope; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return $self->_read_pagi_body($receive)->then(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 35 | 0 | my ($body) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Find Content-Type header from PAGI scope | ||||||||||||||||||||||||||||
| 38 | 0 | my $content_type = ''; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | for my $h (@{ $scope->{headers} || [] }) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$scope->{'headers'} || []
MC/DC0%0/1
$scope->{'headers'} || []
$scope->{'headers'}
Truth table0%0/2
A
A= $scope->{'headers'}
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (lc($h->[0]) eq 'content-type') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | $content_type = $h->[1]; | |||||||||||||||||||||||||||
| 42 | 0 | last; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Delegate parsing to base class method | ||||||||||||||||||||||||||||
| 47 | 0 | my $raw_files = $self->parse_multipart_stream($content_type, $body); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | return Future->done([ map { $self->wrap(%$_) } @$raw_files ]); | |||||||||||||||||||||||||||
| 50 | 0 | }); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub _read_pagi_body { | ||||||||||||||||||||||||||
|
Subroutine
_read_pagi_body: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 54 | 0 | my ($self, $receive) = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my $body = ''; | |||||||||||||||||||||||||||
| 57 | 0 | my $read_loop; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | $read_loop = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return $receive->()->then(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($event) = @_; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (($event->{type} || '') eq 'http.request') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$event->{'type'} || ''
MC/DC0%0/1
$event->{'type'} || ''
$event->{'type'}
Truth table0%0/2
A
A= $event->{'type'}
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $body .= $event->{body} if defined $event->{body}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return $read_loop->() if $event->{more_body}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | return Future->done($body); | |||||||||||||||||||||||||||
| 66 | 0 | }); | |||||||||||||||||||||||||||
| 67 | 0 | }; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | return $read_loop->(); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | 1; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||