| 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
| |||||||||||||
| 12 | 2 | ▶ | $body .= $event->{body} // ''; | ||||||||||
|
Condition50%1/2
$event->{"body"} // ""
MC/DC0%0/1
$event->{"body"} // ""
$event->{"body"}
Truth table50%1/2
A
A= $event->{"body"}
| |||||||||||||
| 13 | 2 | ▶ | last unless $event->{more}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 22 | |||||||||||||
| 23 | 2 | my $body = await read_body($receive); | |||||||||||
| 24 | 2 | ▶ | my $message = length $body | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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; | |||||||||||