| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$msg or defined $err
MC/DC0%0/2
$msg or defined $err
$msg
defined $err
Truth table33%1/3
A or B
A= $msgB= defined $err
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | if ( defined $err ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | $callback->( undef, undef, $err ); | |||||||||||||||||||||||||||
| 24 | 0 | return; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 1 | ▶ | return unless defined $msg && length $msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $msg and length $msg
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
| |||||||||||||||||||||||||||||
| 27 | 1 | try { | |||||||||||||||||||||||||||
| 28 | 1 | my @objects = $codec->decode_sequence($msg); | |||||||||||||||||||||||||||
| 29 | 1 | ▶ | if ( @objects >= 2 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||