examples/03-request-body/app.pl

filter: Statementstmt 100% 28 / 28 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.9% 40 / 44 CC 6 SCAR 10.5
CC
6
Cov
92%
read_body
4.1
app
3.0
BEGIN
1.0
CRAP 2.9
« examples/06-lifespan-state/app.pl ↑ Summary blib/lib/PAGI/Server/TransportState.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶async sub read_body {
Subroutine read_body: called CC=4 SCAR=14.2
6 2 my ($receive) = @_;
7  
8 2 my $body = '';
9 2 while (1) {
10 2 my $event = await $receive->();
11 2 ▶ last if $event->{type} ne 'http.request';
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"type"} ne "http.request" 0 2 2
12 2 ▶ $body .= $event->{body} // '';
Condition50%1/2
$event->{"body"} // ""
l!l
20
MC/DC0%0/1
$event->{"body"} // ""
$event->{"body"}
Truth table50%1/2
A
A= $event->{"body"}
Aresult
11
00
13 2 ▶ last unless $event->{more};
Branch: 1 branch
BranchTrueFalseTotal
unless $event->{"more"} 2 0 2
14 }
15 2 return $body;
16 1 }
17  
18 4 ▶async sub app {
Subroutine app: called CC=3 SCAR=11.0
19 4 my ($scope, $receive, $send) = @_;
20  
21 4 ▶ die "Unsupported scope type: $scope->{type}" if $scope->{type} ne 'http';
Branch: 1 branch
BranchTrueFalseTotal
if $scope->{"type"} ne "http" 2 2 4
22  
23 2 my $body = await read_body($receive);
24 2 ▶ my $message = length $body
Branch: 1 branch
BranchTrueFalseTotal
length $body ? : 1 1 2
25 ? "You sent: $body"
26 : "No body provided";
27  
28 2 await $send->({
29 type => 'http.response.start',
30 status => 200,
31 headers => [ [ 'content-type', 'text/plain' ] ],
32 });
33  
34 2 await $send->({ type => 'http.response.body', body => $message, more => 0 });
35 1 }
36  
37 1 \&app;
« examples/06-lifespan-state/app.pl ↑ Summary blib/lib/PAGI/Server/TransportState.pm »