examples/04-websocket-echo/app.pl

filter: Statementstmt 96.3% 26 / 27 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 90.7% 39 / 43 CC 7 SCAR 16.7
CC
7
Cov
90%
app
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 5.3
« examples/07-extension-fullflush/app.pl ↑ Summary examples/08-tls-introspection/app.pl »
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
BranchTrueFalseTotal
if $scope->{"type"} ne "websocket" 4 4 8
9  
10 4 my $event = await $receive->();
11 4 ▶ die "Expected websocket.connect" if $event->{type} ne 'websocket.connect';
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"type"} ne "websocket.connect" 0 4 4
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
BranchTrueFalseTotal
if ($frame->{'type'} eq 'websocket.receive') { } 5 4 9
elsif ($frame->{'type'} eq 'websocket.disconnect') { } 4 0 4
18 5 my %payload;
19 5 ▶ if (defined $frame->{text}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $frame->{'text'}) { } 4 1 5
elsif (defined $frame->{'bytes'}) { } 1 0 1
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
« examples/07-extension-fullflush/app.pl ↑ Summary examples/08-tls-introspection/app.pl »