blib/lib/PAGI/Context/SSE.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 96.6% 29 / 30 Podpod 96.0% 24 / 25 totaltotal 94.5% 104 / 110 CC 3 SCAR 1.5
CC
3
Cov
96%
sse
2.0
_sync_terminal_disconnect
2.0
every
2.0
CRAP 1.2
« lib/PAGI/Middleware/Runtime.pm ↑ Summary blib/lib/PAGI/Context/WebSocket.pm »
1 package PAGI::Context::SSE;
2 28 $PAGI::Context::SSE::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::SSE accessor ────────────────────────────────────
11  
12 63 ▶sub sse {
Subroutine sse: called CC=2 SCAR=7.0
Pod undocumented
13 63 my ($self) = @_;
14 63 ▶ return $self->{_sse} //= do {
Condition66%2/3
$self->{"_sse"} //= do { require PAGI::SSE; "PAGI::SSE"->new($self->{"scope"}, $self->{"receive"}, $self->{"send"}) }
l!l&&r!l&&!r
30330
MC/DC0%0/2
$self->{"_sse"} //= do { require PAGI::SSE; "PAGI::SSE"->new($self->{"scope"}, $self->{"receive"}, $self->{"send"}) }
$self->{"_sse"} do { require PAGI::SSE; "PAGI::SSE"->new($self->{"scope"}, $self->{"receive"}, $self->{"send"}) }
Truth table66%2/3
A //= B
A= $self->{"_sse"}B= do { require PAGI::SSE; "PAGI::SSE"->new($self->{"scope"}, $self->{"receive"}, $self->{"send"}) }
ABresult
1X1
011
000
15 33 require PAGI::SSE;
16 33 PAGI::SSE->new($self->{scope}, $self->{receive}, $self->{send});
17 };
18 }
19  
20 # Override of PAGI::Context's no-op hook: when $ctx->run's terminal branch
21 # consumes sse.disconnect directly off $receive, sync the underlying
22 # PAGI::SSE's close state and fire its on_close callbacks too, so
23 # is_closed/is_connected/on_close stay truthful regardless of which API
24 # (Context dispatcher or the object itself) observed the disconnect.
25 5 ▶async sub _sync_terminal_disconnect {
Subroutine _sync_terminal_disconnect: called CC=2 SCAR=6.9
26 5 my ($self, $code, $reason) = @_;
27  
28 # Only if the underlying object was actually lazily instantiated, so a
29 # pure-dispatcher context that never touched ->sse pays nothing.
30 5 ▶ return unless exists $self->{_sse};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_sse"} 4 1 5
31 1 await $self->{_sse}->_note_disconnected($code, $reason);
32 28 }
33  
34 # on_close() is PAGI::SSE-specific (see "Methods NOT delegated" below).
35 1 ▶sub on_close { croak "on_close() is on the underlying object: call \$c->sse->on_close(...)" }
Subroutine on_close: called CC=1 SCAR=0.0
Pod documented
36  
37 # ── Connection lifecycle ─────────────────────────────────────────────
38  
39 12 ▶sub start { shift->sse->start(@_) }
Subroutine start: called CC=1 SCAR=0.0
Pod documented
40 3 ▶sub close { shift->sse->close(@_) }
Subroutine close: called CC=1 SCAR=0.0
Pod documented
41  
42 # ── Send methods ─────────────────────────────────────────────────────
43  
44 1 ▶sub send { shift->sse->send(@_) }
Subroutine send: called CC=1 SCAR=0.0
Pod documented
45 3 ▶sub send_json { shift->sse->send_json(@_) }
Subroutine send_json: called CC=1 SCAR=0.0
Pod documented
46 1 ▶sub send_event { shift->sse->send_event(@_) }
Subroutine send_event: called CC=1 SCAR=0.0
Pod documented
47 1 ▶sub send_comment { shift->sse->send_comment(@_) }
Subroutine send_comment: called CC=1 SCAR=0.0
Pod documented
48  
49 1 ▶sub try_send { shift->sse->try_send(@_) }
Subroutine try_send: called CC=1 SCAR=0.0
Pod documented
50 1 ▶sub try_send_json { shift->sse->try_send_json(@_) }
Subroutine try_send_json: called CC=1 SCAR=0.0
Pod documented
51 1 ▶sub try_send_comment { shift->sse->try_send_comment(@_) }
Subroutine try_send_comment: called CC=1 SCAR=0.0
Pod documented
52 1 ▶sub try_send_event { shift->sse->try_send_event(@_) }
Subroutine try_send_event: called CC=1 SCAR=0.0
Pod documented
53  
54 # ── Iteration helpers ────────────────────────────────────────────────
55  
56 1 ▶sub each { shift->sse->each(@_) }
Subroutine each: called CC=1 SCAR=0.0
Pod documented
57 0 ▶sub every { shift->sse->every(@_) }
Subroutine every: not called CC=1 SCAR=6.9
Pod documented
58  
59 # ── State inspection ─────────────────────────────────────────────────
60  
61 2 ▶sub is_started { shift->sse->is_started }
Subroutine is_started: called CC=1 SCAR=0.0
Pod documented
62 4 ▶sub is_closed { shift->sse->is_closed }
Subroutine is_closed: called CC=1 SCAR=0.0
Pod documented
63  
64 # is_connected overrides the base Context method (which reads pagi.connection,
65 # N/A for sse) to use the SSE wrapper's own state — mirrors Context::WebSocket.
66 8 ▶sub is_connected { shift->sse->is_connected }
Subroutine is_connected: called CC=1 SCAR=0.0
Pod documented
67  
68 # ── Protocol metadata ────────────────────────────────────────────────
69  
70 1 ▶sub last_event_id { shift->sse->last_event_id }
Subroutine last_event_id: called CC=1 SCAR=0.0
Pod documented
71 1 ▶sub http_version { shift->sse->http_version }
Subroutine http_version: called CC=1 SCAR=0.0
Pod documented
72 1 ▶sub keepalive { shift->sse->keepalive(@_) }
Subroutine keepalive: called CC=1 SCAR=0.0
Pod documented
73  
74 # ── Query parameter accessors ────────────────────────────────────────
75 # SSE uses query_param (singular) vs WebSocket's query (method name
76 # mirrors what PAGI::SSE exposes).
77  
78 3 ▶sub query_param { shift->sse->query_param(@_) }
Subroutine query_param: called CC=1 SCAR=0.0
Pod documented
79 1 ▶sub query_params { shift->sse->query_params(@_) }
Subroutine query_params: called CC=1 SCAR=0.0
Pod documented
80 1 ▶sub raw_query_param { shift->sse->raw_query_param(@_) }
Subroutine raw_query_param: called CC=1 SCAR=0.0
Pod documented
81 1 ▶sub raw_query_params { shift->sse->raw_query_params(@_) }
Subroutine raw_query_params: called CC=1 SCAR=0.0
Pod documented
82  
83 # ── Header extras ────────────────────────────────────────────────────
84  
85 1 ▶sub header_all { shift->sse->header_all(@_) }
Subroutine header_all: called CC=1 SCAR=0.0
Pod documented
86  
87 28 1;
88  
89 __END__
« lib/PAGI/Middleware/Runtime.pm ↑ Summary blib/lib/PAGI/Context/WebSocket.pm »