blib/lib/Uniform/Upload/PAGI.pm

filter: Statementstmt 50.9% 26 / 51 Branchbran 28.5% 4 / 14 Conditioncond 28.5% 2 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 54.5% 6 / 11 Podpod 100% 2 / 2 totaltotal 46.0% 41 / 89 CC 12 SCAR 25.0
CC
12
Cov
44%
__ANON__
30.0
__ANON__
20.0
extract_async
6.0
CRAP 12.1
↑ Summary
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
BranchTrueFalseTotal
if (@args % 2 != 0) { } 3 1 4
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
BranchTrueFalseTotal
if defined $scope and ref $scope ne "HASH" 1 3 4
Condition66%2/3
defined $scope and ref $scope ne "HASH"
!ll&&!rl&&r
031
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $scope 0 0 0
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'} || []
l!l
00
MC/DC0%0/1
$scope->{'headers'} || []
$scope->{'headers'}
Truth table0%0/2
A
A= $scope->{'headers'}
Aresult
11
00
40 0 ▶ if (lc($h->[0]) eq 'content-type') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $h->[0] eq "content-type") 0 0 0
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
BranchTrueFalseTotal
if (($event->{"type"} || "") eq "http.request") 0 0 0
Condition0%0/2
$event->{'type'} || ''
l!l
00
MC/DC0%0/1
$event->{'type'} || ''
$event->{'type'}
Truth table0%0/2
A
A= $event->{'type'}
Aresult
11
00
62 0 ▶ $body .= $event->{body} if defined $event->{body};
Branch: 1 branch
BranchTrueFalseTotal
if defined $event->{"body"} 0 0 0
63 0 ▶ return $read_loop->() if $event->{more_body};
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"more_body"} 0 0 0
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__
↑ Summary