| 1 | 2 | ▶ | use v5.44; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use experimental 'class'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # What join, action and request handlers receive as their first argument. | ||||||||||||||||||||||||||||
| 5 | 2 | class BoardStreams::Context { | |||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = "v0.0.59"; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use BoardStreams::Rejection; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | field $hub :param :reader; | |||||||||||||||||||||||||||
| 11 | 2 | field $c :param :reader; # the WebSocket's Mojolicious controller | |||||||||||||||||||||||||||
| 12 | 2 | field $channel :param :reader; | |||||||||||||||||||||||||||
| 13 | 2 | field $connection :param = undef; | |||||||||||||||||||||||||||
| 14 | 2 | field $user :param :reader = undef; # what the plugin's "identify" option returned for this browser | |||||||||||||||||||||||||||
| 15 | 2 | field $request_id :param = undef; | |||||||||||||||||||||||||||
| 16 | 2 | field $seq :reader = 0; # highest sequence number this handler produced | |||||||||||||||||||||||||||
| 17 | 2 | field $guarded = 0; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Like $hub->update on this handler's channel. The first update made | ||||||||||||||||||||||||||||
| 20 | # while handling an action or request is tied to its unique id, so a | ||||||||||||||||||||||||||||
| 21 | # resent copy of the same message cannot apply it twice. | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | method update ($cb) { | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my @guard = defined $request_id && !$guarded++ ? (request_id => $request_id) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $request_id and not $guarded++
MC/DC0%0/2
defined $request_id and not $guarded++
defined $request_id
not $guarded++
Truth table0%0/3
A and not(B)
A= defined $request_idB= not $guarded++
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return $hub->update($channel, $cb, @guard)->then(sub ($new_seq) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $seq = $new_seq if $new_seq > $seq; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | return $new_seq; | |||||||||||||||||||||||||||
| 27 | 0 | }); | |||||||||||||||||||||||||||
| 28 | 2 | } | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | method emit ($name, $payload = undef) { | ||||||||||||||||||||||||||
|
Subroutine
emit: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return $self->update(sub ($u) { $u->emit($name, $payload) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 2 | } | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Ends this browser's membership of the channel, as $hub->kick does | ||||||||||||||||||||||||||||
| 35 | # for all of a user's browsers. | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | method kick ($reason = 'kicked', $data = undef) { | ||||||||||||||||||||||||||
|
Subroutine
kick: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | return $hub->kick_connection($connection, $channel, $reason, $data); | |||||||||||||||||||||||||||
| 38 | 2 | } | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Closes this browser's connection for good, as $hub->disconnect does | ||||||||||||||||||||||||||||
| 41 | # for all of a user's browsers. | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | method disconnect ($reason = 'disconnected', $data = undef) { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 0 | return $hub->disconnect_connection($connection, $reason, $data); | |||||||||||||||||||||||||||
| 44 | 2 | } | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | method reject ($reason, $data = undef) { | ||||||||||||||||||||||||||
|
Subroutine
reject: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 0 | die BoardStreams::Rejection->new(reason => $reason, data => $data); | |||||||||||||||||||||||||||
| 48 | 2 | } | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | 1; | |||||||||||||||||||||||||||