| 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 | 1 | ▶ | async sub handle_lifespan { | ||||||||||||
|
Subroutine
handle_lifespan: called CC=4 SCAR=13.9
| |||||||||||||||
| 6 | 1 | my ($scope, $receive, $send) = @_; | |||||||||||||
| 7 | |||||||||||||||
| 8 | 1 | ▶ | my $state = $scope->{state} //= {}; | ||||||||||||
|
Condition50%1/2
$scope->{"state"} //= {}
MC/DC0%0/1
$scope->{"state"} //= {}
$scope->{"state"}
Truth table50%1/2
A
A= $scope->{"state"}
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | while (1) { | |||||||||||||
| 11 | 2 | my $event = await $receive->(); | |||||||||||||
| 12 | 2 | ▶ | if ($event->{type} eq 'lifespan.startup') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 13 | 1 | $state->{greeting} = 'Hello from lifespan'; | |||||||||||||
| 14 | 1 | await $send->({ type => 'lifespan.startup.complete' }); | |||||||||||||
| 15 | } | ||||||||||||||
| 16 | elsif ($event->{type} eq 'lifespan.shutdown') { | ||||||||||||||
| 17 | 1 | await $send->({ type => 'lifespan.shutdown.complete' }); | |||||||||||||
| 18 | 1 | last; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | } | ||||||||||||||
| 21 | 1 | } | |||||||||||||
| 22 | |||||||||||||||
| 23 | 1 | ▶ | async sub handle_http { | ||||||||||||
|
Subroutine
handle_http: called CC=5 SCAR=16.6
| |||||||||||||||
| 24 | 1 | my ($scope, $receive, $send) = @_; | |||||||||||||
| 25 | |||||||||||||||
| 26 | 1 | ▶ | my $state = $scope->{state} // {}; | ||||||||||||
|
Condition50%1/2
$scope->{"state"} // {}
MC/DC0%0/1
$scope->{"state"} // {}
$scope->{"state"}
Truth table50%1/2
A
A= $scope->{"state"}
| |||||||||||||||
| 27 | 1 | ▶ | my $greeting = $state->{greeting} // 'Hello'; | ||||||||||||
|
Condition50%1/2
$state->{"greeting"} // "Hello"
MC/DC0%0/1
$state->{"greeting"} // "Hello"
$state->{"greeting"}
Truth table50%1/2
A
A= $state->{"greeting"}
| |||||||||||||||
| 28 | |||||||||||||||
| 29 | # Drain the request body (if any) | ||||||||||||||
| 30 | 1 | while (1) { | |||||||||||||
| 31 | 1 | my $event = await $receive->(); | |||||||||||||
| 32 | 1 | ▶ | last if $event->{type} ne 'http.request'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 1 | ▶ | last unless $event->{more}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | await $send->({ | ||||||||||||||
| 37 | type => 'http.response.start', | ||||||||||||||
| 38 | status => 200, | ||||||||||||||
| 39 | headers => [ [ 'content-type', 'text/plain' ] ], | ||||||||||||||
| 40 | 1 | }); | |||||||||||||
| 41 | |||||||||||||||
| 42 | 1 | await $send->({ type => 'http.response.body', body => "$greeting via shared state", more => 0 }); | |||||||||||||
| 43 | 1 | } | |||||||||||||
| 44 | |||||||||||||||
| 45 | 2 | ▶ | async sub app { | ||||||||||||
|
Subroutine
app: called CC=3 SCAR=11.3
| |||||||||||||||
| 46 | 2 | my ($scope, $receive, $send) = @_; | |||||||||||||
| 47 | |||||||||||||||
| 48 | 2 | ▶ | return await handle_lifespan($scope, $receive, $send) if $scope->{type} eq 'lifespan'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | 1 | ▶ | return await handle_http($scope, $receive, $send) if $scope->{type} eq 'http'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | 0 | die "Unsupported scope type: $scope->{type}"; | |||||||||||||
| 51 | 1 | } | |||||||||||||
| 52 | |||||||||||||||
| 53 | 1 | \&app; | |||||||||||||