| 1 | package PAGI::Context::WebSocket; | ||||||||||||||||||||
| 2 | 28 | $PAGI::Context::WebSocket::VERSION = '0.002002'; | |||||||||||||||||||
| 3 | 28 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 28 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 28 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 28 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 28 | our @ISA = ('PAGI::Context'); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | # ── Underlying PAGI::WebSocket accessor ────────────────────────────── | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 89 | ▶ | sub websocket { | ||||||||||||||||||
|
Subroutine
websocket: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 13 | 89 | my ($self) = @_; | |||||||||||||||||||
| 14 | 89 | ▶ | return $self->{_websocket} //= do { | ||||||||||||||||||
|
Condition66%2/3
$self->{"_websocket"} //= do {
require PAGI::WebSocket;
"PAGI::WebSocket"->new($self->{"scope"}, $self->{"receive"}, $self->{"send"})
}
MC/DC0%0/2
$self->{"_websocket"} //= do {
require PAGI::WebSocket;
"PAGI::WebSocket"->new($self->{"scope"}, $self->{"receive"}, $self->{"send"})
}
$self->{"_websocket"}
do {
require PAGI::WebSocket;
"PAGI::WebSocket"->new($self->{"scope"}, $self->{"receive"}, $self->{"send"})
}
Truth table66%2/3
A //= B
A= $self->{"_websocket"}B= do {
require PAGI::WebSocket;
"PAGI::WebSocket"->new($self->{"scope"}, $self->{"receive"}, $self->{"send"})
}
| |||||||||||||||||||||
| 15 | 45 | require PAGI::WebSocket; | |||||||||||||||||||
| 16 | 45 | PAGI::WebSocket->new($self->{scope}, $self->{receive}, $self->{send}); | |||||||||||||||||||
| 17 | }; | ||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 73 | ▶ | sub ws { shift->websocket } | ||||||||||||||||||
|
Subroutine
ws: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # Override of PAGI::Context's no-op hook: when $ctx->run's terminal branch | ||||||||||||||||||||
| 23 | # consumes websocket.disconnect directly off $receive, sync the underlying | ||||||||||||||||||||
| 24 | # PAGI::WebSocket's close state and fire its on_close callbacks too, so | ||||||||||||||||||||
| 25 | # is_closed/is_connected/on_close stay truthful regardless of which API | ||||||||||||||||||||
| 26 | # (Context dispatcher or the object itself) observed the disconnect. | ||||||||||||||||||||
| 27 | 24 | ▶ | async sub _sync_terminal_disconnect { | ||||||||||||||||||
|
Subroutine
_sync_terminal_disconnect: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 28 | 24 | my ($self, $code, $reason) = @_; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # Only if the underlying object was actually lazily instantiated, so a | ||||||||||||||||||||
| 31 | # pure-dispatcher context that never touched ->ws pays nothing. | ||||||||||||||||||||
| 32 | 24 | ▶ | return unless exists $self->{_websocket}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 1 | await $self->{_websocket}->_note_disconnected($code, $reason); | |||||||||||||||||||
| 34 | 28 | } | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | # on_close() is PAGI::WebSocket-specific (see "Methods NOT delegated" below). | ||||||||||||||||||||
| 37 | 1 | ▶ | sub on_close { croak "on_close() is on the underlying object: call \$c->websocket->on_close(...)" } | ||||||||||||||||||
|
Subroutine
on_close: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | # ── Connection lifecycle ───────────────────────────────────────────── | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 24 | ▶ | sub accept { shift->ws->accept(@_) } | ||||||||||||||||||
|
Subroutine
accept: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 42 | 4 | ▶ | sub close { shift->ws->close(@_) } | ||||||||||||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 43 | 2 | ▶ | sub deny { shift->ws->deny(@_) } | ||||||||||||||||||
|
Subroutine
deny: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 44 | 2 | ▶ | sub supports_denial_response { shift->ws->supports_denial_response(@_) } | ||||||||||||||||||
|
Subroutine
supports_denial_response: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # ── Send methods ───────────────────────────────────────────────────── | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | ▶ | sub send_text { shift->ws->send_text(@_) } | ||||||||||||||||||
|
Subroutine
send_text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 49 | 1 | ▶ | sub send_bytes { shift->ws->send_bytes(@_) } | ||||||||||||||||||
|
Subroutine
send_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 50 | 1 | ▶ | sub send_json { shift->ws->send_json(@_) } | ||||||||||||||||||
|
Subroutine
send_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 1 | ▶ | sub try_send_text { shift->ws->try_send_text(@_) } | ||||||||||||||||||
|
Subroutine
try_send_text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 53 | 1 | ▶ | sub try_send_bytes { shift->ws->try_send_bytes(@_) } | ||||||||||||||||||
|
Subroutine
try_send_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 54 | 1 | ▶ | sub try_send_json { shift->ws->try_send_json(@_) } | ||||||||||||||||||
|
Subroutine
try_send_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | ▶ | sub send_text_if_connected { shift->ws->send_text_if_connected(@_) } | ||||||||||||||||||
|
Subroutine
send_text_if_connected: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 57 | 1 | ▶ | sub send_bytes_if_connected { shift->ws->send_bytes_if_connected(@_) } | ||||||||||||||||||
|
Subroutine
send_bytes_if_connected: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 58 | 1 | ▶ | sub send_json_if_connected { shift->ws->send_json_if_connected(@_) } | ||||||||||||||||||
|
Subroutine
send_json_if_connected: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | # ── Receive methods ────────────────────────────────────────────────── | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 1 | ▶ | sub receive_text { shift->ws->receive_text(@_) } | ||||||||||||||||||
|
Subroutine
receive_text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 63 | 1 | ▶ | sub receive_bytes { shift->ws->receive_bytes(@_) } | ||||||||||||||||||
|
Subroutine
receive_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 64 | 1 | ▶ | sub receive_json { shift->ws->receive_json(@_) } | ||||||||||||||||||
|
Subroutine
receive_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | # ── Iteration helpers ──────────────────────────────────────────────── | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 1 | ▶ | sub each_message { shift->ws->each_message(@_) } | ||||||||||||||||||
|
Subroutine
each_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 69 | 1 | ▶ | sub each_text { shift->ws->each_text(@_) } | ||||||||||||||||||
|
Subroutine
each_text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 70 | 1 | ▶ | sub each_bytes { shift->ws->each_bytes(@_) } | ||||||||||||||||||
|
Subroutine
each_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 71 | 1 | ▶ | sub each_json { shift->ws->each_json(@_) } | ||||||||||||||||||
|
Subroutine
each_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | # ── State inspection ───────────────────────────────────────────────── | ||||||||||||||||||||
| 74 | # is_connected overrides the base Context method (which checks TCP-level | ||||||||||||||||||||
| 75 | # pagi.connection) to use WebSocket handshake state instead — that is | ||||||||||||||||||||
| 76 | # what handler code actually cares about. | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 5 | ▶ | sub is_connected { shift->ws->is_connected } | ||||||||||||||||||
|
Subroutine
is_connected: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 79 | 5 | ▶ | sub is_closed { shift->ws->is_closed } | ||||||||||||||||||
|
Subroutine
is_closed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 80 | 1 | ▶ | sub close_code { shift->ws->close_code } | ||||||||||||||||||
|
Subroutine
close_code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 81 | 1 | ▶ | sub close_reason { shift->ws->close_reason } | ||||||||||||||||||
|
Subroutine
close_reason: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | # ── Protocol metadata ──────────────────────────────────────────────── | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 1 | ▶ | sub subprotocols { shift->ws->subprotocols } | ||||||||||||||||||
|
Subroutine
subprotocols: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 86 | 1 | ▶ | sub http_version { shift->ws->http_version } | ||||||||||||||||||
|
Subroutine
http_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 87 | 1 | ▶ | sub keepalive { shift->ws->keepalive(@_) } | ||||||||||||||||||
|
Subroutine
keepalive: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | # ── Query parameter accessors ──────────────────────────────────────── | ||||||||||||||||||||
| 90 | # The base Context class has query_string but not parsed query access. | ||||||||||||||||||||
| 91 | # These delegate to PAGI::WebSocket's Hash::MultiValue-based parsing. | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 3 | ▶ | sub query { shift->ws->query(@_) } | ||||||||||||||||||
|
Subroutine
query: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 94 | 1 | ▶ | sub query_params { shift->ws->query_params(@_) } | ||||||||||||||||||
|
Subroutine
query_params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 95 | 1 | ▶ | sub raw_query { shift->ws->raw_query(@_) } | ||||||||||||||||||
|
Subroutine
raw_query: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 96 | 1 | ▶ | sub raw_query_params { shift->ws->raw_query_params(@_) } | ||||||||||||||||||
|
Subroutine
raw_query_params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | # ── Header extras ──────────────────────────────────────────────────── | ||||||||||||||||||||
| 99 | # Base Context has header() (single value). header_all() returns all | ||||||||||||||||||||
| 100 | # values for multi-value headers like Cookie via Hash::MultiValue. | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 1 | ▶ | sub header_all { shift->ws->header_all(@_) } | ||||||||||||||||||
|
Subroutine
header_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 28 | 1; | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||