Manager/Client/JSONFile.pm

filter: Statementstmt 90.7% 205 / 226 Branchbran 61.5% 48 / 78 Conditioncond 54.8% 17 / 31 MC/DCmcdc 18.7% 3 / 16 Subroutinesub 97.3% 36 / 37 Podpod 73.3% 11 / 15 totaltotal 79.4% 320 / 403 CC 56 SCAR 17.0
CC
56
Cov
81%
_cache_is_stale
16.0
_init_inotify
13.7
init
8.6
CRAP 5.5
« Manager/Client/AtomicPipe.pm ↑ Summary Manager/Message.pm »
1 package IPC::Manager::Client::JSONFile;
2 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 87 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 87 our $VERSION = '0.000035';
6  
7 87 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use Fcntl qw/:flock/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 87 my $HAVE_SHA;
13 87 ▶BEGIN { $HAVE_SHA = eval { require Digest::SHA; Digest::SHA->import('sha256_hex'); 1 } ? 1 : 0 }
Subroutine BEGIN: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Digest::SHA; 'Digest::SHA'->import('sha256_hex'); 1 } } ? : 87 0 87
14  
15 87 ▶use IPC::Manager::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 87 ▶use IPC::Manager::Serializer::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 87 ▶use IPC::Manager::Util qw/USE_INOTIFY/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 87 ▶use parent 'IPC::Manager::Client';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 87 use Object::HashBase qw{
21 +_cache_state
22 +_cache_mtime
23 +_cache_sha
24 +_cache_gen
25 +_cache_sha_verified
26 +_inotify
27 interval
28 87 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # Per-route write generation counter so that multiple client objects
31 # sharing the same file in a single process always detect each other's
32 # writes, even when filesystem mtime resolution is too coarse.
33 my %_WRITE_GEN;
34  
35 1 ▶sub _viable { USE_INOTIFY || $HAVE_SHA || die "Need Linux::Inotify2 or Digest::SHA" }
Subroutine _viable: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$HAVE_SHA or die "Need Linux::Inotify2 or Digest::SHA" 0 1 1
36  
37 sub sanity {
38 250 ▶ return if USE_INOTIFY || $HAVE_SHA;
Subroutine sanity: called CC=2 SCAR=9.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $HAVE_SHA 250 0 250
39 0 croak "JSONFile requires either Linux::Inotify2 or Digest::SHA for reliable cache invalidation";
40 }
41  
42 # The route is the path to the JSON file. The file stores:
43 # {
44 # clients => { id => { pid => $$ } },
45 # messages => { id => [ @message_hashes ] },
46 # stats => { id => { read => {}, sent => {} } },
47 # }
48  
49 sub spawn {
50 94 ▶ my $class = shift;
Subroutine spawn: called CC=2 SCAR=6.9
Pod documented
51 94 my %params = @_;
52  
53 94 $class->sanity;
54  
55 94 ▶ my $template = delete $params{template} // "PerlIPCMgr-$$-XXXXXX";
Condition100%2/2
delete $params{"template"} // "PerlIPCMgr-${$}-XXXXXX"
l!l
193
MC/DC100%1/1
delete $params{"template"} // "PerlIPCMgr-${$}-XXXXXX"
delete $params{"template"}
Truth table100%2/2
A
A= delete $params{"template"}
Aresult
11
00
56 94 my ($fh, $file) = File::Temp::tempfile($template, TMPDIR => 1, SUFFIX => '.json', UNLINK => 0);
57  
58 94 my $state = {clients => {}, messages => {}, stats => {}};
59 94 print $fh IPC::Manager::Serializer::JSON->serialize($state);
60 94 close $fh;
61  
62 94 return $file;
63 }
64  
65 sub unspawn {
66 66 ▶ my $class = shift;
Subroutine unspawn: called CC=3 SCAR=12.5
Pod documented
67 66 my ($route) = @_;
68 66 ▶ unlink $route if $route && -e $route;
Branch: 1 branch
BranchTrueFalseTotal
if $route and -e $route 66 0 66
Condition33%1/3
$route and -e $route
!ll&&!rl&&r
0066
MC/DC0%0/2
$route and -e $route
$route -e $route
Truth table33%1/3
A and B
A= $routeB= -e $route
ABresult
0X0
100
111
69 }
70  
71 # --- Cache / change-detection ---
72  
73 sub _file_sha {
74 1344 ▶ my $self = shift;
Subroutine _file_sha: called CC=3 SCAR=11.1
75 1344 ▶ croak "Digest::SHA is required for SHA-based cache invalidation" unless $HAVE_SHA;
Branch: 1 branch
BranchTrueFalseTotal
unless $HAVE_SHA 0 1344 1344
76 1344 ▶ open(my $fh, '<', $self->{route}) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->{"route"} or return undef 0 1344 1344
77 1344 my $data = do { local $/; <$fh> };
78 1344 close $fh;
79 1344 return sha256_hex($data);
80 }
81  
82 sub _init_inotify {
83 156 ▶ my $self = shift;
Subroutine _init_inotify: called CC=4 SCAR=26.2
84 156 return unless USE_INOTIFY;
85 0 ▶ return if $self->{+_INOTIFY};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_inotify"} 0 0 0
86  
87 0 ▶ my $i = Linux::Inotify2->new or return;
Branch: 1 branch
BranchTrueFalseTotal
my $i = "Linux::Inotify2"->new or return 0 0 0
88 0 $i->blocking(0);
89 $i->watch(
90 $self->{route},
91 0 ▶ Linux::Inotify2::IN_MODIFY() | Linux::Inotify2::IN_CLOSE_WRITE(),
Branch: 1 branch
BranchTrueFalseTotal
$i->watch($self->{"route"}, Linux::Inotify2::IN_MODIFY() | Linux::Inotify2::IN_CLOSE_WRITE()) or return 0 0 0
92 ) or return;
93  
94 0 $self->{+_INOTIFY} = $i;
95 }
96  
97 sub _cache_is_stale {
98 734 ▶ my $self = shift;
Subroutine _cache_is_stale: called CC=13 SCAR=27.7
99  
100 # No cache yet
101 734 ▶ return 1 unless defined $self->{+_CACHE_MTIME};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_cache_mtime"} 3 731 734
102  
103 # Another client in this process wrote to the same file
104 731 ▶ my $current_gen = $_WRITE_GEN{$self->{route}} // 0;
Condition50%1/2
$_WRITE_GEN{$self->{"route"}} // 0
l!l
7310
MC/DC0%0/1
$_WRITE_GEN{$self->{"route"}} // 0
$_WRITE_GEN{$self->{"route"}}
Truth table50%1/2
A
A= $_WRITE_GEN{$self->{"route"}}
Aresult
11
00
105 731 ▶ return 1 if ($self->{+_CACHE_GEN} // 0) != $current_gen;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_cache_gen"} // 0) != $current_gen 47 684 731
Condition50%1/2
$self->{"_cache_gen"} // 0
l!l
7310
MC/DC0%0/1
$self->{"_cache_gen"} // 0
$self->{"_cache_gen"}
Truth table50%1/2
A
A= $self->{"_cache_gen"}
Aresult
11
00
106  
107 684 ▶ if (my $i = $self->{+_INOTIFY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $i = $self->{"_inotify"}) 0 684 684
108 # If inotify has pending events the file has changed
109 0 my @events = $i->read;
110 0 ▶ return 1 if @events;
Branch: 1 branch
BranchTrueFalseTotal
if @events 0 0 0
111 0 return 0;
112 }
113  
114 # Fallback: compare mtime (sub-second via Time::HiRes), then SHA.
115 # Time::HiRes::stat returns nanosecond-resolution mtime on filesystems
116 # that support it (most modern Linux/BSD), so same-second cross-process
117 # writes are detected by mtime alone. When mtime equality is reported
118 # we still SHA-compare to handle filesystems that round mtime to whole
119 # seconds; SHA on small JSON state files is microseconds.
120 684 ▶ my $current_mtime = (Time::HiRes::stat($self->{route}))[9] // return 1;
Condition50%1/2
(&Time::HiRes::stat($self->{"route"}))[9] // (return 1)
l!l
6840
MC/DC0%0/1
(&Time::HiRes::stat($self->{"route"}))[9] // (return 1)
(&Time::HiRes::stat($self->{"route"}))[9]
Truth table50%1/2
A
A= (&Time::HiRes::stat($self->{"route"}))[9]
Aresult
11
00
121  
122 684 ▶ if ($current_mtime != $self->{+_CACHE_MTIME}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mtime != $self->{"_cache_mtime"}) 98 586 684
123 98 delete $self->{+_CACHE_SHA_VERIFIED};
124 98 return 1;
125 }
126  
127 # Mtime unchanged — if we already verified via SHA, trust it
128 # until the mtime changes again.
129 586 ▶ return 0 if $self->{+_CACHE_SHA_VERIFIED};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache_sha_verified"} 171 415 586
130  
131 # Mtime unchanged — verify via SHA in case the filesystem rounds
132 # mtime and a same-tick write was masked.
133 415 ▶ my $current_sha = $self->_file_sha // return 1;
Condition50%1/2
$self->_file_sha // (return 1)
l!l
4150
MC/DC0%0/1
$self->_file_sha // (return 1)
$self->_file_sha
Truth table50%1/2
A
A= $self->_file_sha
Aresult
11
00
134 415 ▶ if ($current_sha ne ($self->{+_CACHE_SHA} // '')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_sha ne ($self->{"_cache_sha"} // "")) 10 405 415
Condition50%1/2
$self->{"_cache_sha"} // ""
l!l
4150
MC/DC0%0/1
$self->{"_cache_sha"} // ""
$self->{"_cache_sha"}
Truth table50%1/2
A
A= $self->{"_cache_sha"}
Aresult
11
00
135 10 return 1;
136 }
137  
138 405 $self->{+_CACHE_SHA_VERIFIED} = 1;
139 405 return 0;
140 }
141  
142 sub _update_cache {
143 929 ▶ my ($self, $state) = @_;
Subroutine _update_cache: called CC=3 SCAR=11.0
144 929 $self->{+_CACHE_STATE} = $state;
145 929 $self->{+_CACHE_MTIME} = (Time::HiRes::stat($self->{route}))[9];
146 929 ▶ $self->{+_CACHE_SHA} = $self->_file_sha if $HAVE_SHA;
Branch: 1 branch
BranchTrueFalseTotal
if $HAVE_SHA 929 0 929
147 929 ▶ $self->{+_CACHE_GEN} = $_WRITE_GEN{$self->{route}} // 0;
Condition100%2/2
$_WRITE_GEN{$self->{"route"}} // 0
l!l
9281
MC/DC100%1/1
$_WRITE_GEN{$self->{"route"}} // 0
$_WRITE_GEN{$self->{"route"}}
Truth table100%2/2
A
A= $_WRITE_GEN{$self->{"route"}}
Aresult
11
00
148 929 delete $self->{+_CACHE_SHA_VERIFIED};
149 }
150  
151 sub _invalidate_cache {
152 0 ▶ my $self = shift;
Subroutine _invalidate_cache: not called CC=1 SCAR=6.9
153 0 delete $self->{+_CACHE_STATE};
154 0 delete $self->{+_CACHE_MTIME};
155 }
156  
157 # --- File I/O with locking ---
158  
159 sub _read_file_locked {
160 934 ▶ my ($self, $fh) = @_;
Subroutine _read_file_locked: called CC=2 SCAR=7.0
161 934 ▶ seek($fh, 0, 0) or croak "Cannot seek: $!";
Branch: 1 branch
BranchTrueFalseTotal
seek $fh, 0, 0 or croak("Cannot seek: $!") 0 934 934
162 934 my $data = do { local $/; <$fh> };
163 934 return IPC::Manager::Serializer::JSON->deserialize($data);
164 }
165  
166 sub _lock_read {
167 734 ▶ my $self = shift;
Subroutine _lock_read: called CC=4 SCAR=13.9
168  
169 # Fast path: return cached state if the file hasn't changed.
170 # We return undef for $fh to signal that no lock is held — callers
171 # that receive undef must not try to close it.
172 734 ▶ unless ($self->_cache_is_stale) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_cache_is_stale) 576 158 734
173 576 return ($self->{+_CACHE_STATE}, undef);
174 }
175  
176 158 my $route = $self->{route};
177 158 ▶ open(my $fh, '<', $route) or croak "Cannot open '$route': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $route or croak("Cannot open '${route}': $!") 0 158 158
178 158 ▶ flock($fh, LOCK_SH) or croak "Cannot lock '$route': $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 1 or croak("Cannot lock '${route}': $!") 0 158 158
179 158 my $state = $self->_read_file_locked($fh);
180 158 close $fh;
181  
182 158 $self->_update_cache($state);
183  
184 158 return ($state, undef);
185 }
186  
187 sub _lock_write {
188 776 ▶ my $self = shift;
Subroutine _lock_write: called CC=3 SCAR=11.2
189 776 my $route = $self->{route};
190 776 ▶ open(my $fh, '+<', $route) or croak "Cannot open '$route': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "+<", $route or croak("Cannot open '${route}': $!") 0 776 776
191 776 ▶ flock($fh, LOCK_EX) or croak "Cannot lock '$route': $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 2 or croak("Cannot lock '${route}': $!") 0 776 776
192 776 my $state = $self->_read_file_locked($fh);
193 # Don't update cache yet — caller will modify state and call _commit
194 776 return ($state, $fh);
195 }
196  
197 sub _commit {
198 771 ▶ my ($self, $state, $fh) = @_;
Subroutine _commit: called CC=4 SCAR=14.6
199 771 ▶ seek($fh, 0, 0) or croak "Cannot seek: $!";
Branch: 1 branch
BranchTrueFalseTotal
seek $fh, 0, 0 or croak("Cannot seek: $!") 0 771 771
200 771 ▶ truncate($fh, 0) or croak "Cannot truncate: $!";
Branch: 1 branch
BranchTrueFalseTotal
truncate $fh, 0 or croak("Cannot truncate: $!") 0 771 771
201 771 print $fh IPC::Manager::Serializer::JSON->serialize($state);
202 771 close $fh;
203  
204 771 $_WRITE_GEN{$self->{route}}++;
205  
206 # Drain any inotify events caused by our own write so the cache
207 # doesn't immediately appear stale on the next read.
208 771 ▶ if (my $i = $self->{+_INOTIFY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $i = $self->{"_inotify"}) 0 771 771
209 0 $i->read;
210 }
211  
212 771 $self->_update_cache($state);
213 }
214  
215 # --- Client lifecycle ---
216  
217 sub init {
218 156 ▶ my $self = shift;
Subroutine init: called CC=8 SCAR=21.6
Pod undocumented
219  
220 156 $self->sanity;
221  
222 156 $self->SUPER::init();
223  
224 156 $self->_init_inotify;
225  
226 156 my $id = $self->{id};
227 156 my ($state, $fh) = $self->_lock_write;
228  
229 156 ▶ if ($self->{reconnect}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'reconnect'}) { } 3 153 156
230 3 ▶ unless ($state->{clients}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"clients"}{$id}) 1 2 3
231 1 $self->{disconnected} = 1;
232 1 croak "Client '$id' does not exist";
233 }
234 2 my $data = $state->{clients}{$id};
235 2 ▶ if ($data->{pid} && $data->{pid} != $$ && $self->pid_is_running($data->{pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"pid"} and $data->{"pid"} != $$ and $self->pid_is_running($data->{"pid"})) 0 2 2
Condition33%2/6
$data->{"pid"} and $data->{"pid"} != $$ and $self->pid_is_running($data->{"pid"})
!ll&&!rl&&r
200
$data->{"pid"} and $data->{"pid"} != $$
!ll&&!rl&&r
020
MC/DC0%0/3
$data->{"pid"} and $data->{"pid"} != $$ and $self->pid_is_running($data->{"pid"})
$data->{"pid"} $data->{"pid"} != $$ $self->pid_is_running($data->{"pid"})
Truth table25%1/4
A and B and C
A= $data->{"pid"}B= $data->{"pid"} != $$C= $self->pid_is_running($data->{"pid"})
ABCresult
0XX0
10X0
1100
1111
236 0 $self->{disconnected} = 1;
237 0 croak "Connection already running in pid $data->{pid}";
238 }
239 }
240 else {
241 153 ▶ if ($state->{clients}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"clients"}{$id}) 1 152 153
242 1 $self->{disconnected} = 1;
243 1 croak "Client '$id' already exists";
244 }
245 152 $state->{clients}{$id} = {pid => $$};
246 152 ▶ $state->{messages}{$id} //= [];
Condition50%1/2
$state->{"messages"}{$id} //= []
l!l
0152
MC/DC0%0/1
$state->{"messages"}{$id} //= []
$state->{"messages"}{$id}
Truth table50%1/2
A
A= $state->{"messages"}{$id}
Aresult
11
00
247 }
248  
249 154 $state->{clients}{$id}{pid} = $$;
250  
251 154 $self->_commit($state, $fh);
252 }
253  
254 # --- Messages ---
255  
256 129 ▶sub pending_messages { 0 }
Subroutine pending_messages: called CC=1 SCAR=0.0
Pod undocumented
257  
258 sub ready_messages {
259 131 ▶ my $self = shift;
Subroutine ready_messages: called CC=4 SCAR=14.6
Pod undocumented
260 131 my $state;
261 131 ▶ unless (eval { ($state) = $self->_lock_read; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { ($state) = $self->_lock_read; 1 } }) 0 131 131
262 0 warn $@;
263 0 return 0;
264 }
265 131 ▶ my $msgs = $state->{messages}{$self->{id}} // [];
Condition50%1/2
$state->{"messages"}{$self->{"id"}} // []
l!l
1310
MC/DC0%0/1
$state->{"messages"}{$self->{"id"}} // []
$state->{"messages"}{$self->{"id"}}
Truth table50%1/2
A
A= $state->{"messages"}{$self->{"id"}}
Aresult
11
00
266 131 ▶ return @$msgs ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$msgs ? : 5 126 131
267 }
268  
269 sub get_messages {
270 223 ▶ my $self = shift;
Subroutine get_messages: called CC=3 SCAR=11.0
Pod documented
271 223 $self->pid_check;
272  
273 223 my ($state, $fh) = $self->_lock_write;
274 223 ▶ my $raw = delete $state->{messages}{$self->{id}} // [];
Condition50%1/2
delete $state->{"messages"}{$self->{"id"}} // []
l!l
2230
MC/DC0%0/1
delete $state->{"messages"}{$self->{"id"}} // []
delete $state->{"messages"}{$self->{"id"}}
Truth table50%1/2
A
A= delete $state->{"messages"}{$self->{"id"}}
Aresult
11
00
275 223 $state->{messages}{$self->{id}} = [];
276 223 $self->_commit($state, $fh);
277  
278 223 my @out;
279 223 for my $h (@$raw) {
280 134 my $msg = IPC::Manager::Message->new(%$h);
281 134 $self->{stats}{read}{$msg->{from}}++;
282 134 push @out, $msg;
283 }
284  
285 223 return $self->sort_messages(@out);
286 }
287  
288 sub send_message {
289 138 ▶ my $self = shift;
Subroutine send_message: called CC=3 SCAR=11.0
Pod documented
290 138 my $msg = $self->build_message(@_);
291 138 $self->pid_check;
292  
293 138 ▶ my $peer_id = $msg->to or croak "Message has no peer";
Branch: 1 branch
BranchTrueFalseTotal
my $peer_id = $msg->to or croak("Message has no peer") 0 138 138
294  
295 138 my ($state, $fh) = $self->_lock_write;
296  
297 croak "Client '$peer_id' does not exist"
298 138 ▶ unless $state->{clients}{$peer_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $state->{"clients"}{$peer_id} 3 135 138
299  
300 135 push @{$state->{messages}{$peer_id}}, $msg->TO_JSON;
301  
302 135 $self->_commit($state, $fh);
303  
304 135 $self->{stats}{sent}{$peer_id}++;
305 }
306  
307 # --- Peer queries ---
308  
309 sub peers {
310 316 ▶ my $self = shift;
Subroutine peers: called CC=1 SCAR=0.0
Pod documented
311 316 my ($state) = $self->_lock_read;
312 316 return sort grep { $_ ne $self->{id} } keys %{$state->{clients}};
313 }
314  
315 sub peer_exists {
316 51 ▶ my $self = shift;
Subroutine peer_exists: called CC=3 SCAR=11.0
Pod documented
317 51 my ($peer_id) = @_;
318 51 ▶ croak "'peer_id' is required" unless $peer_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $peer_id 0 51 51
319 51 my ($state) = $self->_lock_read;
320 51 ▶ return $state->{clients}{$peer_id} ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$state->{'clients'}{$peer_id} ? : 34 17 51
321 }
322  
323 sub peer_pid {
324 226 ▶ my $self = shift;
Subroutine peer_pid: called CC=2 SCAR=6.9
Pod documented
325 226 my ($peer_id) = @_;
326 226 my ($state) = $self->_lock_read;
327 226 my $data = $state->{clients}{$peer_id};
328 226 ▶ return undef unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 66 160 226
329 160 return $data->{pid};
330 }
331  
332 # --- Stats ---
333  
334 sub write_stats {
335 134 ▶ my $self = shift;
Subroutine write_stats: called CC=2 SCAR=7.3
Pod documented
336 134 my ($state, $fh);
337 134 ▶ unless (eval { ($state, $fh) = $self->_lock_write; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { () = $self->_lock_write; 1 } }) 0 134 134
338 0 warn $@;
339 0 return;
340 }
341 134 $state->{stats}{$self->{id}} = $self->{stats};
342 134 $self->_commit($state, $fh);
343 }
344  
345 sub read_stats {
346 8 ▶ my $self = shift;
Subroutine read_stats: called CC=2 SCAR=6.9
Pod documented
347 8 my ($state) = $self->_lock_read;
348 8 ▶ return $state->{stats}{$self->{id}} // {read => {}, sent => {}};
Condition100%2/2
$state->{"stats"}{$self->{"id"}} // {"read", {}, "sent", {}}
l!l
71
MC/DC100%1/1
$state->{"stats"}{$self->{"id"}} // {"read", {}, "sent", {}}
$state->{"stats"}{$self->{"id"}}
Truth table100%2/2
A
A= $state->{"stats"}{$self->{"id"}}
Aresult
11
00
349 }
350  
351 sub all_stats {
352 2 ▶ my $self = shift;
Subroutine all_stats: called CC=2 SCAR=6.9
Pod documented
353 2 my ($state) = $self->_lock_read;
354 2 my %out;
355 2 for my $id (keys %{$state->{stats}}) {
356 6 $out{$id} = $state->{stats}{$id};
357 }
358 2 return \%out;
359 }
360  
361 # --- Disconnect ---
362  
363 sub post_disconnect_hook {
364 125 ▶ my $self = shift;
Subroutine post_disconnect_hook: called CC=2 SCAR=7.2
Pod documented
365 125 my ($state, $fh);
366 125 ▶ unless (eval { ($state, $fh) = $self->_lock_write; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { () = $self->_lock_write; 1 } }) 0 125 125
367 0 warn $@;
368 0 return;
369 }
370 125 delete $state->{clients}{$self->{id}};
371 125 delete $state->{messages}{$self->{id}};
372 125 $self->_commit($state, $fh);
373 }
374  
375 87 1;
376  
377 __END__
« Manager/Client/AtomicPipe.pm ↑ Summary Manager/Message.pm »