File Coverage

blib/lib/PAGI/Context/SSE.pm
Criterion Covered Total %
statement 32 33 96.9
branch n/a
condition 2 3 66.6
subroutine 25 26 96.1
pod 23 24 95.8
total 82 86 95.3


line stmt bran cond sub pod time code
1             package PAGI::Context::SSE;
2             $PAGI::Context::SSE::VERSION = '0.002001';
3 28     28   175 use strict;
  28         42  
  28         927  
4 28     28   97 use warnings;
  28         32  
  28         16695  
5              
6             our @ISA = ('PAGI::Context');
7              
8             # ── Underlying PAGI::SSE accessor ────────────────────────────────────
9              
10             sub sse {
11 58     58 0 132 my ($self) = @_;
12 58   66     231 return $self->{_sse} //= do {
13 32         3839 require PAGI::SSE;
14 32         235 PAGI::SSE->new($self->{scope}, $self->{receive}, $self->{send});
15             };
16             }
17              
18             # ── Connection lifecycle ─────────────────────────────────────────────
19              
20 11     11 1 90 sub start { shift->sse->start(@_) }
21 3     3 1 99 sub close { shift->sse->close(@_) }
22              
23             # ── Send methods ─────────────────────────────────────────────────────
24              
25 1     1 1 11 sub send { shift->sse->send(@_) }
26 3     3 1 28 sub send_json { shift->sse->send_json(@_) }
27 1     1 1 13 sub send_event { shift->sse->send_event(@_) }
28 1     1 1 27 sub send_comment { shift->sse->send_comment(@_) }
29              
30 1     1 1 28 sub try_send { shift->sse->try_send(@_) }
31 1     1 1 26 sub try_send_json { shift->sse->try_send_json(@_) }
32 1     1 1 27 sub try_send_comment { shift->sse->try_send_comment(@_) }
33 1     1 1 27 sub try_send_event { shift->sse->try_send_event(@_) }
34              
35             # ── Iteration helpers ────────────────────────────────────────────────
36              
37 1     1 1 26 sub each { shift->sse->each(@_) }
38 0     0 1 0 sub every { shift->sse->every(@_) }
39              
40             # ── State inspection ─────────────────────────────────────────────────
41              
42 2     2 1 53 sub is_started { shift->sse->is_started }
43 3     3 1 36 sub is_closed { shift->sse->is_closed }
44              
45             # is_connected overrides the base Context method (which reads pagi.connection,
46             # N/A for sse) to use the SSE wrapper's own state — mirrors Context::WebSocket.
47 6     6 1 64 sub is_connected { shift->sse->is_connected }
48              
49             # ── Protocol metadata ────────────────────────────────────────────────
50              
51 1     1 1 8 sub last_event_id { shift->sse->last_event_id }
52 1     1 1 11 sub http_version { shift->sse->http_version }
53 1     1 1 11 sub keepalive { shift->sse->keepalive(@_) }
54              
55             # ── Query parameter accessors ────────────────────────────────────────
56             # SSE uses query_param (singular) vs WebSocket's query (method name
57             # mirrors what PAGI::SSE exposes).
58              
59 3     3 1 731 sub query_param { shift->sse->query_param(@_) }
60 1     1 1 12 sub query_params { shift->sse->query_params(@_) }
61 1     1 1 12 sub raw_query_param { shift->sse->raw_query_param(@_) }
62 1     1 1 14 sub raw_query_params { shift->sse->raw_query_params(@_) }
63              
64             # ── Header extras ────────────────────────────────────────────────────
65              
66 1     1 1 12 sub header_all { shift->sse->header_all(@_) }
67              
68             1;
69              
70             __END__