blib/lib/Thunderhorse/Context.pm

filter: Statementstmt 97.2% 71 / 73 Branchbran 70.0% 7 / 10 Conditioncond 66.6% 12 / 18 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 92.3% 24 / 26 Podpod 100% 9 / 9 totaltotal 88.1% 126 / 143 CC 12 SCAR 10.5
CC
12
Cov
89%
is_consumed
8.5
update
3.1
try_send_res
3.0
CRAP 2.9
« blib/lib/Test2/Thunderhorse.pm ↑ Summary blib/lib/Thunderhorse/Autoloadable.pm »
1 package Thunderhorse::Context;
2 24 $Thunderhorse::Context::VERSION = '0.107';
3 24 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶use Devel::StrictMode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 24 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use Thunderhorse::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use Thunderhorse::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use Thunderhorse::WebSocket;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 24 ▶use Thunderhorse::SSE;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 24 ▶use PAGI::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 24 ▶use PAGI::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 24 extends 'Gears::Context';
17  
18 24 has param 'pagi' => (
19 (STRICT ? (isa => Tuple [HashRef, CodeRef, CodeRef]) : ()),
20 writer => -hidden,
21 );
22  
23 # match structure is recursive
24 24 has field 'match' => (
25 (STRICT ? (isa => (InstanceOf ['Gears::Router::Match']) | ArrayRef) : ()),
26 writer => 1,
27 );
28  
29 has field 'req' => (
30 (STRICT ? (isa => InstanceOf ['Thunderhorse::Request']) : ()),
31 106 ▶ default => sub ($self) { Thunderhorse::Request->new(context => $self) },
Subroutine __ANON__: called CC=1 SCAR=0.0
32 24 );
33  
34 has field 'connection' => (
35 (STRICT ? (isa => HasMethods ['response_started']) : ()),
36 95 ▶ lazy => sub ($self) { $self->scope->{'pagi.connection'} },
Subroutine __ANON__: called CC=1 SCAR=0.0
37 24 );
38  
39 has field 'res' => (
40 (STRICT ? (isa => InstanceOf ['Thunderhorse::Response']) : ()),
41 111 ▶ lazy => sub ($self) { Thunderhorse::Response->new(context => $self) },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 24 clearer => -hidden,
43 );
44  
45 # NOTE: websocket must be lazy, because it will die if scope is not websocket
46 has field 'ws' => (
47 (STRICT ? (isa => InstanceOf ['Thunderhorse::WebSocket']) : ()),
48 predicate => 1,
49 3 ▶ lazy => sub ($self) { Thunderhorse::WebSocket->new(context => $self) },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 24 );
51  
52 # NOTE: sse must be lazy, because it will die if scope is not sse
53 has field 'sse' => (
54 (STRICT ? (isa => InstanceOf ['Thunderhorse::SSE']) : ()),
55 predicate => 1,
56 4 ▶ lazy => sub ($self) { Thunderhorse::SSE->new(context => $self) },
Subroutine __ANON__: called CC=1 SCAR=0.0
57 24 );
58  
59 has field 'stash' => (
60 (STRICT ? (isa => InstanceOf ['PAGI::Stash']) : ()),
61 5 ▶ lazy => sub ($self) { PAGI::Stash->new($self) },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 24 );
63  
64 has field 'session' => (
65 (STRICT ? (isa => InstanceOf ['PAGI::Session']) : ()),
66 0 ▶ lazy => sub ($self) { PAGI::Session->new($self) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 24 );
68  
69 24 has field '_consumed' => (
70 (STRICT ? (isa => Bool) : ()),
71 writer => 1,
72 default => false,
73 );
74  
75 106 ▶sub update ($self, $scope, $receive, $send)
Subroutine update: called CC=3 SCAR=11.2
Pod documented
76 {
77 106 $self->_set_pagi([$scope, $receive, $send]);
78  
79 106 $self->req->update($scope, $receive, $send);
80 106 $self->res->update($scope, $receive, $send);
81  
82 106 ▶ $self->ws->update($scope, $receive, $send)
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_ws 0 106 106
83 if $self->has_ws;
84  
85 106 ▶ $self->sse->update($scope, $receive, $send)
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_sse 0 106 106
86 if $self->has_sse;
87  
88 106 return;
89 }
90  
91 100 ▶sub scope ($self)
Subroutine scope: called CC=1 SCAR=0.0
Pod documented
92 {
93 100 return $self->pagi->[0];
94 }
95  
96 0 ▶sub receiver ($self)
Subroutine receiver: not called CC=1 SCAR=6.9
Pod documented
97 {
98 0 return $self->pagi->[1];
99 }
100  
101 83 ▶sub sender ($self)
Subroutine sender: called CC=1 SCAR=0.0
Pod documented
102 {
103 83 return $self->pagi->[2];
104 }
105  
106 17 ▶sub consume ($self)
Subroutine consume: called CC=1 SCAR=0.0
Pod documented
107 {
108 17 $self->_set_consumed(true);
109 17 return $self;
110 }
111  
112 312 ▶sub is_consumed ($self)
Subroutine is_consumed: called CC=7 SCAR=21.5
Pod documented
113 {
114 312 ▶ return $self->_consumed
Condition66%12/18
$self->_consumed || $self->connection->response_started || $self->res->is_ready || $self->has_ws && $self->ws->is_closed || $self->has_sse && $self->sse->is_closed
l!l&&r!l&&!r
208099
$self->_consumed or $self->connection->response_started or $self->res->is_ready or $self->has_ws and $self->ws->is_closed
l!l&&r!l&&!r
208099
$self->_consumed or $self->connection->response_started or $self->res->is_ready
l!l&&r!l&&!r
202699
$self->_consumed or $self->connection->response_started
l!l&&r!l&&!r
37165110
$self->has_ws and $self->ws->is_closed
!ll&&!rl&&r
9900
$self->has_sse and $self->sse->is_closed
!ll&&!rl&&r
9900
MC/DC42%3/7
$self->_consumed || $self->connection->response_started || $self->res->is_ready || $self->has_ws && $self->ws->is_closed || $self->has_sse && $self->sse->is_closed
$self->_consumed $self->connection->response_started $self->res->is_ready $self->has_ws $self->ws->is_closed $self->has_sse $self->sse->is_closed
Truth table40%4/10
A or B or C or D and E || F and G
A= $self->_consumedB= $self->connection->response_startedC= $self->res->is_readyD= $self->has_wsE= $self->ws->is_closedF= $self->has_sseG= $self->sse->is_closed
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
00011XX1
0000X111
00010111
0000X0X0
0000X100
000100X0
00010100
115 || $self->connection->response_started
116 || $self->res->is_ready
117 || ($self->has_ws && $self->ws->is_closed)
118 || ($self->has_sse && $self->sse->is_closed);
119 }
120  
121 19 ▶sub empty_res ($self)
Subroutine empty_res: called CC=1 SCAR=0.0
Pod documented
122 {
123 19 $self->_clear_res;
124 19 return $self->res;
125 }
126  
127 5 ▶async sub send_res ($self)
Subroutine send_res: called CC=2 SCAR=7.0
Pod documented
128 5 {
129 # NOTE: we check a general pagi constraint, but raise a thunderhorse exception -
130 # should it just die()?
131 5 ▶ Gears::X::Thunderhorse->raise('response was already sent')
Branch: 1 branch
BranchTrueFalseTotal
if $self->connection->response_started 0 5 5
132 if $self->connection->response_started;
133  
134 5 await $self->res->respond($self->sender);
135  
136 5 return;
137 24 }
138  
139 105 ▶async sub try_send_res ($self)
Subroutine try_send_res: called CC=3 SCAR=11.0
Pod documented
140 105 {
141 return
142 105 ▶ if $self->connection->response_started;
Branch: 1 branch
BranchTrueFalseTotal
if $self->connection->response_started 2 98 100
143  
144 98 ▶ await $self->res->respond($self->sender)
Branch: 1 branch
BranchTrueFalseTotal
if $self->res->is_ready 78 20 98
145 if $self->res->is_ready;
146  
147 98 return;
148 }
149  
150 __END__
« blib/lib/Test2/Thunderhorse.pm ↑ Summary blib/lib/Thunderhorse/Autoloadable.pm »