| 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 | 8 | ▶ | async sub app { | ||||||||||||
|
Subroutine
app: called CC=7 SCAR=19.7
| |||||||||||||||
| 6 | 8 | my ($scope, $receive, $send) = @_; | |||||||||||||
| 7 | |||||||||||||||
| 8 | 8 | ▶ | die "Unsupported scope type: $scope->{type}" if $scope->{type} ne 'websocket'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 4 | my $event = await $receive->(); | |||||||||||||
| 11 | 4 | ▶ | die "Expected websocket.connect" if $event->{type} ne 'websocket.connect'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 4 | await $send->({ type => 'websocket.accept' }); | |||||||||||||
| 14 | |||||||||||||||
| 15 | 4 | while (1) { | |||||||||||||
| 16 | 9 | my $frame = await $receive->(); | |||||||||||||
| 17 | 9 | ▶ | if ($frame->{type} eq 'websocket.receive') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 18 | 5 | my %payload; | |||||||||||||
| 19 | 5 | ▶ | if (defined $frame->{text}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 20 | 4 | $payload{text} = "echo: $frame->{text}"; | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | elsif (defined $frame->{bytes}) { | ||||||||||||||
| 23 | 1 | $payload{bytes} = $frame->{bytes}; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | else { | ||||||||||||||
| 26 | 0 | next; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | 5 | await $send->({ type => 'websocket.send', %payload }); | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | elsif ($frame->{type} eq 'websocket.disconnect') { | ||||||||||||||
| 31 | 4 | last; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | } | ||||||||||||||
| 34 | 1 | } | |||||||||||||
| 35 | |||||||||||||||
| 36 | 1 | \&app; # Return coderef when loaded via do | |||||||||||||