blib/lib/IPC/Manager/Base/FS.pm

filter: Statementstmt 89.9% 214 / 238 Branchbran 70.4% 62 / 88 Conditioncond 63.1% 24 / 38 MC/DCmcdc 34.7% 8 / 23 Subroutinesub 80.3% 41 / 51 Podpod 91.6% 33 / 36 totaltotal 80.5% 382 / 474 CC 62 SCAR 14.6
CC
62
Cov
82%
read_resume_file
10.5
init
9.4
on_disk_name
7.0
CRAP 4.3
« blib/lib/IPC/Manager/Serializer/JSON/Zstd.pm ↑ Summary blib/lib/IPC/Manager/Util.pm »
1 package IPC::Manager::Base::FS;
2 264 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 264 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 264 our $VERSION = '0.000036';
6  
7 264 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 264 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 264 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 264 ▶use File::Path qw/remove_tree/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 264 ▶use Digest::SHA qw/sha256_hex/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 264 ▶use IPC::Manager::Util qw/USE_INOTIFY USE_IO_SELECT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # When the peer id is too long or contains path-unsafe characters, we hash
17 # it to this on-disk form. "h-" + 40 hex chars of sha256 = 42 chars total.
18 # The "h-" prefix is reserved: any caller-supplied id starting with "h-"
19 # that would otherwise be used verbatim is still hashed, so the real name
20 # is always read from the ".name" sidecar to avoid ambiguity.
21 264 ▶use constant ON_DISK_HASH_LEN => 40;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 264 ▶use constant ON_DISK_HASH_PREFIX => 'h-';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 264 ▶use parent 'IPC::Manager::Client';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 264 use Object::HashBase qw{
26 +path
27 +pidfile
28 +resume_file
29 +select
30 +peer_inotify
31 264 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 0 ▶sub pending_messages { 0 }
Subroutine pending_messages: not called CC=1 SCAR=6.9
Pod undocumented
34  
35 0 ▶sub ready_messages { croak "Not Implemented" }
Subroutine ready_messages: not called CC=1 SCAR=6.9
Pod undocumented
36 0 ▶sub get_messages { croak "Not Implemented" }
Subroutine get_messages: not called CC=1 SCAR=6.9
Pod documented
37 0 ▶sub send_message { croak "Not Implemented" }
Subroutine send_message: not called CC=1 SCAR=6.9
Pod documented
38 0 ▶sub check_path { croak "Not Implemented" }
Subroutine check_path: not called CC=1 SCAR=6.9
Pod documented
39 0 ▶sub make_path { croak "Not Implemented" }
Subroutine make_path: not called CC=1 SCAR=6.9
Pod documented
40 0 ▶sub path_type { croak "Not Implemented" }
Subroutine path_type: not called CC=1 SCAR=6.9
Pod documented
41  
42 1757 ▶sub max_on_disk_name_length { 200 }
Subroutine max_on_disk_name_length: called CC=1 SCAR=0.0
Pod documented
43  
44 sub on_disk_name {
45 4759 ▶ my ($self, $peer_id) = @_;
Subroutine on_disk_name: called CC=7 SCAR=19.5
Pod documented
46 4759 ▶ croak "peer_id is required" unless defined $peer_id && length $peer_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $peer_id and length $peer_id 1 4758 4759
Condition66%2/3
defined $peer_id and length $peer_id
!ll&&!rl&&r
104758
MC/DC50%1/2
defined $peer_id and length $peer_id
defined $peer_id length $peer_id
Truth table66%2/3
A and B
A= defined $peer_idB= length $peer_id
ABresult
0X0
100
111
47  
48 4758 my $max = $self->max_on_disk_name_length;
49 4758 ▶ if (length($peer_id) <= $max
Branch: 1 branch
BranchTrueFalseTotal
if (length $peer_id <= $max and not $peer_id =~ m([\x00-\x1f/\\]) and index($peer_id, "h-") != 0) 4729 29 4758
Condition100%6/6
length $peer_id <= $max and not $peer_id =~ m([\x00-\x1f/\\]) and index($peer_id, "h-") != 0
!ll&&!rl&&r
2814729
length $peer_id <= $max and not $peer_id =~ m([\x00-\x1f/\\])
!ll&&!rl&&r
2714730
MC/DC100%3/3
length $peer_id <= $max and not $peer_id =~ m([\x00-\x1f/\\]) and index($peer_id, "h-") != 0
length $peer_id <= $max not $peer_id =~ m([\x00-\x1f/\\]) index($peer_id, "h-") != 0
Truth table100%4/4
A and not(B) and C
A= length $peer_id <= $maxB= not $peer_id =~ m([\x00-\x1f/\\])C= index($peer_id, "h-") != 0
ABCresult
0XX0
10X0
1100
1111
50 && $peer_id !~ m{[\x00-\x1f/\\]}
51 && index($peer_id, ON_DISK_HASH_PREFIX) != 0)
52 {
53 4729 return $peer_id;
54 }
55  
56 29 my $hashed_len = length(ON_DISK_HASH_PREFIX) + ON_DISK_HASH_LEN;
57 croak sprintf(
58 "Cannot map peer id '%s' to on-disk name: hashed form (%d bytes) exceeds available budget (%d bytes) under route '%s'",
59 29 ▶ $peer_id, $hashed_len, $max, $self->{+ROUTE},
Branch: 1 branch
BranchTrueFalseTotal
if $hashed_len > $max 6 23 29
60 ) if $hashed_len > $max;
61  
62 23 return ON_DISK_HASH_PREFIX . substr(sha256_hex($peer_id), 0, ON_DISK_HASH_LEN);
63 }
64  
65 sub name_file {
66 0 ▶ my $self = shift;
Subroutine name_file: not called CC=2 SCAR=17.9
Pod documented
67 0 my ($peer_id) = @_;
68 0 ▶ $peer_id //= $self->{+ID};
Condition0%0/3
$peer_id //= $self->{"id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$peer_id //= $self->{"id"}
$peer_id $self->{"id"}
Truth table0%0/3
A //= B
A= $peer_idB= $self->{"id"}
ABresult
1X1
011
000
69 0 return File::Spec->catfile($self->{+ROUTE}, $self->on_disk_name($peer_id) . ".name");
70 }
71  
72 sub _read_name_file {
73 663 ▶ my ($self, $on_disk) = @_;
Subroutine _read_name_file: called CC=3 SCAR=11.0
74 663 my $file = File::Spec->catfile($self->{+ROUTE}, "$on_disk.name");
75 663 ▶ return undef unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 660 3 663
76 3 ▶ open(my $fh, '<', $file) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return undef 0 3 3
77 3 my $real = do { local $/; <$fh> };
78 3 close($fh);
79 3 return $real;
80 }
81  
82 sub _real_name_for_on_disk {
83 663 ▶ my ($self, $on_disk) = @_;
Subroutine _real_name_for_on_disk: called CC=2 SCAR=6.9
84 663 my $real = $self->_read_name_file($on_disk);
85 663 ▶ return defined($real) ? $real : $on_disk;
Branch: 1 branch
BranchTrueFalseTotal
defined $real ? : 3 660 663
86 }
87  
88 sub _write_name_file {
89 417 ▶ my $self = shift;
Subroutine _write_name_file: called CC=4 SCAR=14.0
90  
91 417 my $on_disk = $self->on_disk_name($self->{+ID});
92 417 ▶ return if $on_disk eq $self->{+ID};
Branch: 1 branch
BranchTrueFalseTotal
if $on_disk eq $self->{"id"} 415 2 417
93  
94 2 my $file = File::Spec->catfile($self->{+ROUTE}, "$on_disk.name");
95 2 my $pend = $file . ".pend";
96 2 ▶ open(my $fh, '>', $pend) or die "Could not open name file '$pend': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $pend or die "Could not open name file '${pend}': $!" 0 2 2
97 2 print $fh $self->{+ID};
98 2 close($fh);
99 2 ▶ rename($pend, $file) or die "Could not rename '$pend' -> '$file': $!";
Branch: 1 branch
BranchTrueFalseTotal
rename $pend, $file or die "Could not rename '${pend}' -> '${file}': $!" 0 2 2
100 }
101  
102 sub have_resume_file {
103 830 ▶ my $self = shift;
Subroutine have_resume_file: called CC=2 SCAR=6.9
Pod documented
104 830 ▶ my $file = eval { $self->resume_file } // return 0;
Condition100%2/2
eval { do { $self->resume_file } } // (return 0)
l!l
8273
MC/DC100%1/1
eval { do { $self->resume_file } } // (return 0)
eval { do { $self->resume_file } }
Truth table100%2/2
A
A= eval { do { $self->resume_file } }
Aresult
11
00
105 827 return -e $file;
106 }
107  
108 212 ▶sub can_select { USE_IO_SELECT() }
Subroutine can_select: called CC=1 SCAR=0.0
Pod documented
109 sub select {
110 212 ▶ my $self = shift;
Subroutine select: called CC=2 SCAR=6.9
Pod documented
111  
112 212 ▶ return $self->{+SELECT} if $self->{+SELECT};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"select"} 109 103 212
113  
114 103 croak "Not Implemented (Or you are missing IO::Select)" unless USE_IO_SELECT();
115 103 my $sel = IO::Select->new;
116 103 $sel->add($self->handles_for_select);
117  
118 103 return $self->{+SELECT} = $sel;
119 }
120  
121 sub all_stats {
122 5 ▶ my $self = shift;
Subroutine all_stats: called CC=5 SCAR=16.2
Pod documented
123  
124 5 my $out = {};
125  
126 5 ▶ opendir(my $dh, $self->{+ROUTE}) or die "Could not open dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $self->{"route"} or die "Could not open dir: $!" 0 5 5
127 5 for my $file (readdir($dh)) {
128 47 ▶ next unless $file =~ m/^(.+)\.stats$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /^(.+)\.stats$/ 31 16 47
129 16 my $peer = $self->_real_name_for_on_disk($1);
130 16 ▶ open(my $fh, '<', File::Spec->catfile($self->{+ROUTE}, $file)) or die "Could not open stats file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "File::Spec"->catfile($self->{"route"}, $file) or die "Could not open stats file: $!" 0 16 16
131 16 $out->{$peer} = do { local $/; $self->{+SERIALIZER}->deserialize(<$fh>) };
132 16 close($fh);
133 }
134  
135 5 close($dh);
136  
137 5 return $out;
138 }
139  
140 sub stats_file {
141 365 ▶ my $self = shift;
Subroutine stats_file: called CC=1 SCAR=0.0
Pod documented
142 365 return File::Spec->catfile($self->{+ROUTE}, $self->on_disk_name($self->{+ID}) . ".stats");
143 }
144  
145 sub write_stats {
146 352 ▶ my $self = shift;
Subroutine write_stats: called CC=4 SCAR=15.0
Pod documented
147  
148 352 ▶ my $file = eval { $self->stats_file } // return;
Condition100%2/2
eval { do { $self->stats_file } } // (return)
l!l
3511
MC/DC100%1/1
eval { do { $self->stats_file } } // (return)
eval { do { $self->stats_file } }
Truth table100%2/2
A
A= eval { do { $self->stats_file } }
Aresult
11
00
149 351 ▶ if (open(my $fh, '>', $file)) {
Branch: 2 branches
BranchTrueFalseTotal
if (open my $fh, '>', $file) { } 351 0 351
elsif (-d $self->{'route'}) { } 0 0 0
150 351 print $fh $self->{+SERIALIZER}->serialize($self->{+STATS});
151 351 close($fh);
152 }
153 elsif(-d $self->{+ROUTE}) {
154 0 die "Could not open stats file ($file): $!";
155 }
156 }
157  
158 sub read_stats {
159 12 ▶ my $self = shift;
Subroutine read_stats: called CC=2 SCAR=7.0
Pod documented
160  
161 12 ▶ open(my $fh, '<', $self->stats_file) or die "Could not open stats file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->stats_file or die "Could not open stats file: $!" 0 12 12
162 12 my $stats = do { local $/; <$fh> };
163 12 close($fh);
164 12 $self->{+SERIALIZER}->deserialize($stats);
165 }
166  
167 sub pidfile {
168 427 ▶ my $self = shift;
Subroutine pidfile: called CC=2 SCAR=7.1
Pod documented
169 427 ▶ return $self->{+PIDFILE} //= $self->peer_pid_file($self->{+ID});
Condition66%2/3
$self->{"pidfile"} //= $self->peer_pid_file($self->{"id"})
l!l&&r!l&&!r
84190
MC/DC0%0/2
$self->{"pidfile"} //= $self->peer_pid_file($self->{"id"})
$self->{"pidfile"} $self->peer_pid_file($self->{"id"})
Truth table66%2/3
A //= B
A= $self->{"pidfile"}B= $self->peer_pid_file($self->{"id"})
ABresult
1X1
011
000
170 }
171  
172 sub path {
173 1428 ▶ my $self = shift;
Subroutine path: called CC=2 SCAR=7.1
Pod documented
174 1428 ▶ return $self->{+PATH} //= File::Spec->catfile($self->{+ROUTE}, $self->on_disk_name($self->{+ID}));
Condition66%2/3
$self->{"path"} //= "File::Spec"->catfile($self->{"route"}, $self->on_disk_name($self->{"id"}))
l!l&&r!l&&!r
10074210
MC/DC0%0/2
$self->{"path"} //= "File::Spec"->catfile($self->{"route"}, $self->on_disk_name($self->{"id"}))
$self->{"path"} "File::Spec"->catfile($self->{"route"}, $self->on_disk_name($self->{"id"}))
Truth table66%2/3
A //= B
A= $self->{"path"}B= "File::Spec"->catfile($self->{"route"}, $self->on_disk_name($self->{"id"}))
ABresult
1X1
011
000
175 }
176  
177 sub resume_file {
178 1218 ▶ my $self = shift;
Subroutine resume_file: called CC=2 SCAR=7.1
Pod documented
179 1218 ▶ return $self->{+RESUME_FILE} //= File::Spec->catfile($self->{+ROUTE}, $self->on_disk_name($self->{+ID}) . ".resume");
Condition66%2/3
$self->{"resume_file"} //= "File::Spec"->catfile($self->{"route"}, $self->on_disk_name($self->{"id"}) . '.resume')
l!l&&r!l&&!r
8024160
MC/DC0%0/2
$self->{"resume_file"} //= "File::Spec"->catfile($self->{"route"}, $self->on_disk_name($self->{"id"}) . '.resume')
$self->{"resume_file"} "File::Spec"->catfile($self->{"route"}, $self->on_disk_name($self->{"id"}) . '.resume')
Truth table66%2/3
A //= B
A= $self->{"resume_file"}B= "File::Spec"->catfile($self->{"route"}, $self->on_disk_name($self->{"id"}) . '.resume')
ABresult
1X1
011
000
180 }
181  
182 sub peer_pid_file {
183 924 ▶ my $self = shift;
Subroutine peer_pid_file: called CC=1 SCAR=0.0
Pod documented
184 924 my ($peer_id) = @_;
185  
186 924 return File::Spec->catfile($self->{+ROUTE}, $self->on_disk_name($peer_id) . ".pid");
187 }
188  
189 sub init {
190 420 ▶ my $self = shift;
Subroutine init: called CC=7 SCAR=22.4
Pod undocumented
191  
192 420 $self->SUPER::init();
193  
194 420 my $id = $self->{+ID};
195 420 my $path = $self->path;
196  
197 419 my $pt = $self->path_type;
198  
199 419 ▶ if ($self->{+RECONNECT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'reconnect'}) { } 2 417 419
200 2 ▶ croak "${id} ${pt} does not exist" unless $self->check_path($path);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->check_path($path) 0 2 2
201 2 my $pidfile = $self->pidfile;
202 2 ▶ if (open(my $fh, '<', $pidfile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $pidfile) 0 2 2
203 0 chomp(my $pid = <$fh>);
204 0 ▶ croak "Looks like the connection is already running in pid $pid" if $pid && $self->pid_is_running($pid);
Branch: 1 branch
BranchTrueFalseTotal
if $pid and $self->pid_is_running($pid) 0 0 0
Condition0%0/3
$pid and $self->pid_is_running($pid)
!ll&&!rl&&r
000
MC/DC0%0/2
$pid and $self->pid_is_running($pid)
$pid $self->pid_is_running($pid)
Truth table0%0/3
A and B
A= $pidB= $self->pid_is_running($pid)
ABresult
0X0
100
111
205 0 close($fh);
206 }
207 }
208 else {
209 417 ▶ croak "${id} ${pt} already exists" if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 0 417 417
210 417 $self->make_path($path);
211 417 $self->_write_name_file;
212 }
213  
214 # Prime the peer-change inotify watch now that the route directory
215 # exists, so events are captured from the start.
216 419 $self->handles_for_peer_change if USE_INOTIFY();
217  
218 419 $self->write_pid;
219 }
220  
221 sub clear_pid {
222 3 ▶ my $self = shift;
Subroutine clear_pid: called CC=2 SCAR=7.1
Pod documented
223  
224 3 my $pidfile = $self->pidfile;
225 3 ▶ unlink($pidfile) or die "Could not unlink pidfile '$pidfile': $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $pidfile or die "Could not unlink pidfile '${pidfile}': $!" 0 3 3
226 }
227  
228 sub write_pid {
229 420 ▶ my $self = shift;
Subroutine write_pid: called CC=3 SCAR=11.2
Pod documented
230  
231 420 my $pidfile = $self->pidfile;
232 420 my $pend = $pidfile . ".pend";
233 420 ▶ open(my $fh, '>', $pend) or die "Could not open pidfile '$pend': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $pend or die "Could not open pidfile '${pend}': $!" 0 420 420
234 420 print $fh $self->{+PID};
235 420 close($fh);
236 420 ▶ rename($pend, $pidfile) or die "Could not rename file '$pend' -> '$pidfile': $!";
Branch: 1 branch
BranchTrueFalseTotal
rename $pend, $pidfile or die "Could not rename file '${pend}' -> '${pidfile}': $!" 0 420 420
237 }
238  
239 sub requeue_message {
240 1 ▶ my $self = shift;
Subroutine requeue_message: called CC=3 SCAR=11.0
Pod documented
241 1 $self->pid_check;
242 1 ▶ open(my $fh, '>>', $self->resume_file) or die "Could not open resume file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $self->resume_file or die "Could not open resume file: $!" 0 1 1
243 1 binmode($fh);
244 1 for my $msg (@_) {
245 1 my $bytes = $self->{+SERIALIZER}->serialize($msg);
246 1 print $fh pack('N', length $bytes), $bytes;
247 }
248 1 close($fh);
249 }
250  
251 sub read_resume_file {
252 386 ▶ my $self = shift;
Subroutine read_resume_file: called CC=10 SCAR=23.5
Pod documented
253  
254 386 my @out;
255  
256 386 my $rf = $self->resume_file;
257 386 ▶ return @out unless -e $rf;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $rf 385 1 386
258  
259 1 ▶ open(my $fh, '<', $rf) or die "Could not open resume file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $rf or die "Could not open resume file: $!" 0 1 1
260 1 binmode($fh);
261 1 while (1) {
262 2 my $hdr;
263 2 my $r = read($fh, $hdr, 4);
264 2 ▶ last unless defined $r && $r > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r and $r > 0 1 1 2
Condition66%2/3
defined $r and $r > 0
!ll&&!rl&&r
011
MC/DC50%1/2
defined $r and $r > 0
defined $r $r > 0
Truth table66%2/3
A and B
A= defined $rB= $r > 0
ABresult
0X0
100
111
265 1 ▶ die "Truncated resume file header (got $r bytes)" if $r != 4;
Branch: 1 branch
BranchTrueFalseTotal
if $r != 4 0 1 1
266 1 my ($len) = unpack('N', $hdr);
267 1 my $bytes = '';
268 1 my $need = $len;
269 1 ▶ while ($need) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need) 1 1 2
270 1 my $got = read($fh, $bytes, $need, length $bytes);
271 1 ▶ die "Truncated resume file payload (wanted $len, got " . length($bytes) . ")"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $got and $got > 0 0 1 1
Condition33%1/3
defined $got and $got > 0
!ll&&!rl&&r
001
MC/DC0%0/2
defined $got and $got > 0
defined $got $got > 0
Truth table33%1/3
A and B
A= defined $gotB= $got > 0
ABresult
0X0
100
111
272 unless defined $got && $got > 0;
273 1 $need -= $got;
274 }
275 1 push @out => IPC::Manager::Message->new($self->{+SERIALIZER}->deserialize($bytes));
276 }
277 1 close($fh);
278  
279 1 ▶ unlink($rf) or die "Could not unlink resume file";
Branch: 1 branch
BranchTrueFalseTotal
unlink $rf or die "Could not unlink resume file" 0 1 1
280  
281 1 return @out;
282 }
283  
284 sub post_disconnect_hook {
285 336 ▶ my $self = shift;
Subroutine post_disconnect_hook: called CC=3 SCAR=11.0
Pod documented
286 336 $self->SUPER::post_disconnect_hook;
287 336 ▶ my $path = eval { $self->path } // return;
Condition100%2/2
eval { do { $self->path } } // (return)
l!l
3351
MC/DC100%1/1
eval { do { $self->path } } // (return)
eval { do { $self->path } }
Truth table100%2/2
A
A= eval { do { $self->path } }
Aresult
11
00
288 335 ▶ remove_tree($path, {keep_root => 0, safe => 1}) if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 120 215 335
289 }
290  
291 sub pre_suspend_hook {
292 2 ▶ my $self = shift;
Subroutine pre_suspend_hook: called CC=1 SCAR=0.0
Pod documented
293 2 $self->clear_pid;
294 }
295  
296 0 ▶sub reset_handles_for_peer_change { $_[0]->{+PEER_INOTIFY}->read }
Subroutine reset_handles_for_peer_change: not called CC=1 SCAR=6.9
Pod documented
297 473 ▶sub have_handles_for_peer_change { USE_INOTIFY() }
Subroutine have_handles_for_peer_change: called CC=1 SCAR=0.0
Pod documented
298 sub handles_for_peer_change {
299 0 ▶ my $self = shift;
Subroutine handles_for_peer_change: not called CC=2 SCAR=17.9
Pod documented
300 0 croak "Not Implemented (Linux::Inotify2)" unless USE_INOTIFY();
301  
302 0 ▶ unless ($self->{+PEER_INOTIFY}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"peer_inotify"}) 0 0 0
303 0 my $i = Linux::Inotify2->new;
304 0 $i->blocking(0);
305 0 $i->watch($self->{+ROUTE}, Linux::Inotify2::IN_CREATE());
306 0 $self->{+PEER_INOTIFY} = $i;
307 }
308  
309 0 return $self->{+PEER_INOTIFY}->fh;
310 }
311  
312 sub peers {
313 843 ▶ my $self = shift;
Subroutine peers: called CC=7 SCAR=19.5
Pod documented
314  
315 843 my $my_on_disk = $self->on_disk_name($self->{+ID});
316  
317 843 my @out;
318  
319 843 ▶ opendir(my $dh, $self->{+ROUTE}) or die "Could not open dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $self->{"route"} or die "Could not open dir: $!" 0 843 843
320 843 for my $file (readdir($dh)) {
321 6486 ▶ next if $file eq $my_on_disk;
Branch: 1 branch
BranchTrueFalseTotal
if $file eq $my_on_disk 600 5886 6486
322 5886 ▶ next if $file =~ m/^(\.|_)/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^(\.|_)/ 1686 4200 5886
323 4200 ▶ next if $file =~ m/\.(?:pid|name|resume|stats)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.(?:pid|name|resume|stats)$/ 3552 648 4200
324  
325 648 my $path = File::Spec->catdir($self->{+ROUTE}, $file);
326 648 ▶ next unless $self->check_path($path);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->check_path($path) 1 647 648
327  
328 647 push @out => $self->_real_name_for_on_disk($file);
329 }
330  
331 843 close($dh);
332  
333 843 return sort @out;
334 }
335  
336 sub peer_pid {
337 698 ▶ my $self = shift;
Subroutine peer_pid: called CC=4 SCAR=13.9
Pod documented
338 698 my ($peer_id) = @_;
339  
340 698 ▶ my $path = $self->peer_exists($peer_id) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $path = $self->peer_exists($peer_id) or return undef 193 505 698
341 505 my $pidfile = $self->peer_pid_file($peer_id);
342 505 ▶ return 0 unless -f $pidfile;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $pidfile 23 482 505
343 482 ▶ open(my $fh, '<', $pidfile) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $pidfile or return 0 0 482 482
344 482 chomp(my $pid = <$fh>);
345 482 close($fh);
346 482 return $pid;
347 }
348  
349 sub peer_exists {
350 1245 ▶ my $self = shift;
Subroutine peer_exists: called CC=3 SCAR=11.0
Pod documented
351 1245 my ($peer_id) = @_;
352  
353 1245 ▶ croak "'peer_id' is required" unless $peer_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $peer_id 1 1244 1245
354  
355 1244 my $path = File::Spec->catdir($self->{+ROUTE}, $self->on_disk_name($peer_id));
356 1244 ▶ return $path if $self->check_path($path);
Branch: 1 branch
BranchTrueFalseTotal
if $self->check_path($path) 1032 212 1244
357 212 return undef;
358 }
359  
360 sub spawn {
361 207 ▶ my $class = shift;
Subroutine spawn: called CC=2 SCAR=7.0
Pod documented
362 207 my (%params) = @_;
363  
364 207 ▶ my $template = delete $params{template} // "PerlIPCManager-$$-XXXXXX";
Condition50%1/2
delete $params{"template"} // "PerlIPCManager-${$}-XXXXXX"
l!l
0207
MC/DC0%0/1
delete $params{"template"} // "PerlIPCManager-${$}-XXXXXX"
delete $params{"template"}
Truth table50%1/2
A
A= delete $params{"template"}
Aresult
11
00
365 207 my $dir = tempdir($template, TMPDIR => 1, CLEANUP => 0, %params);
366  
367 207 return "$dir";
368 }
369  
370 sub unspawn {
371 122 ▶ my $class = shift;
Subroutine unspawn: called CC=1 SCAR=0.0
Pod documented
372 122 my ($route) = @_;
373 122 remove_tree($route, {keep_root => 0, safe => 1});
374 }
375  
376 264 1;
377  
378 __END__
« blib/lib/IPC/Manager/Serializer/JSON/Zstd.pm ↑ Summary blib/lib/IPC/Manager/Util.pm »