blib/lib/At/Protocol/Firehose.pm

filter: Statementstmt 89.1% 33 / 37 Branchbran 41.6% 5 / 12 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 72.4% 50 / 69 CC 9 SCAR 21.5
CC
9
Cov
73%
__ANON__
16.9
__ANON__
2.1
start
1.1
CRAP 8.6
« lib/At.pm ↑ Summary lib/At/Protocol/URI.pm »
1 1 ▶use v5.42;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use experimental 'try';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 class At::Protocol::Firehose v1.8.0 {
6 1 ▶ use At::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use Codec::CBOR;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 field $at : param;
9 1 field $url : param : reader //= 'wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos';
10 1 field $callback : param;
11 1 field $codec;
12 3 ▶ ADJUST {
Subroutine __ANON__: called CC=2 SCAR=7.2
13 # Ensure url is absolute
14 3 ▶ $url = 'wss://' . $url if $url !~ m[^wss?://];
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[^wss?://]u 0 3 3
15 3 $codec = Codec::CBOR->new();
16 }
17  
18 1 ▶ method start() {
Subroutine start: called CC=1 SCAR=1.2
Pod documented
19 $at->http->websocket(
20 1 ▶ $url => sub ( $msg, $err ) {
Subroutine __ANON__: called CC=8 SCAR=28.3
21 1 ▶ return if !$msg && !defined $err;
Branch: 1 branch
BranchTrueFalseTotal
unless $msg or defined $err 0 1 1
Condition33%1/3
$msg or defined $err
l!l&&r!l&&!r
100
MC/DC0%0/2
$msg or defined $err
$msg defined $err
Truth table33%1/3
A or B
A= $msgB= defined $err
ABresult
1X1
011
000
22 1 ▶ if ( defined $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 0 1 1
23 0 $callback->( undef, undef, $err );
24 0 return;
25 }
26 1 ▶ return unless defined $msg && length $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg and length $msg 0 1 1
Condition33%1/3
defined $msg and length $msg
!ll&&!rl&&r
001
MC/DC0%0/2
defined $msg and length $msg
defined $msg length $msg
Truth table33%1/3
A and B
A= defined $msgB= length $msg
ABresult
0X0
100
111
27 1 try {
28 1 my @objects = $codec->decode_sequence($msg);
29 1 ▶ if ( @objects >= 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@objects >= 2) { } 1 0 1
elsif (@objects == 1) { } 0 0 0
30 1 $callback->( $objects[0], $objects[1], undef );
31 }
32 elsif ( @objects == 1 ) {
33 0 $callback->( $objects[0], undef, At::Error->new( message => 'Incomplete firehose message', fatal => 0 ) );
34 }
35 }
36 catch ($e) {
37 0 $callback->( undef, undef, At::Error->new( message => "Firehose decode failed: $e", fatal => 0 ) );
38 }
39 }
40 1 );
41 }
42 1 } 1;
43 __END__
« lib/At.pm ↑ Summary lib/At/Protocol/URI.pm »