Manager/Util.pm

filter: Statementstmt 91.8% 45 / 49 Branchbran 70.0% 14 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 88.6% 78 / 88 CC 12 SCAR 11.9
CC
12
Cov
86%
BEGIN
5.3
pid_is_running
4.1
clone_io
4.0
CRAP 3.3
« Manager/Base/FS.pm ↑ Summary Manager/Role/Service/Requests.pm »
1 package IPC::Manager::Util;
2 473 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 473 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 473 our $VERSION = '0.000035';
6  
7 473 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 473 ▶use Errno qw/ESRCH/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 BEGIN {
11 473 ▶ if (eval { require IO::Select; 1 }) {
Subroutine BEGIN: called CC=4 SCAR=16.8
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require IO::Select; 1 } }) { } 473 0 473
12 473 *USE_IO_SELECT = sub() { 1 };
13 }
14 else {
15 0 *USE_IO_SELECT = sub() { 0 };
16 }
17  
18 473 ▶ if (eval { require Linux::Inotify2; Linux::Inotify2->can('fh') ? 1 : 0 }) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require Linux::Inotify2; 'Linux::Inotify2'->can('fh') ? 1 : 0 } }) { } 0 473 473
'Linux::Inotify2'->can('fh') ? : 0 0 0
19 0 *USE_INOTIFY = sub() { 1 };
20 }
21 else {
22 473 *USE_INOTIFY = sub() { 0 };
23 }
24 }
25  
26 473 ▶use Importer Importer => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 473 our @EXPORT_OK = qw{
29 USE_INOTIFY
30 USE_IO_SELECT
31 require_mod
32 pid_is_running
33 clone_io
34 tinysleep
35 };
36  
37 # Sub-second sleep that returns early when interrupted by a signal.
38 # Time::HiRes::sleep restarts on EINTR, which delays signal-driven loops by
39 # up to a full cycle. select() with a timeout returns immediately on EINTR.
40 sub tinysleep {
41 806 ▶ my ($secs) = @_;
Subroutine tinysleep: called CC=3 SCAR=11.0
Pod documented
42 806 ▶ return unless defined($secs) && $secs > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $secs and $secs > 0 3 803 806
Condition100%3/3
defined $secs and $secs > 0
!ll&&!rl&&r
12803
MC/DC100%2/2
defined $secs and $secs > 0
defined $secs $secs > 0
Truth table100%3/3
A and B
A= defined $secsB= $secs > 0
ABresult
0X0
100
111
43 803 select(undef, undef, undef, $secs);
44 800 return;
45 }
46  
47 sub require_mod {
48 1777 ▶ my $mod = shift;
Subroutine require_mod: called CC=1 SCAR=0.0
Pod documented
49  
50 1777 my $file = $mod;
51 1777 $file =~ s{::}{/}g;
52 1777 $file .= ".pm";
53  
54 1777 require($file);
55  
56 1774 return $mod;
57 }
58  
59 sub pid_is_running {
60 616 ▶ my $pid = pop;
Subroutine pid_is_running: called CC=4 SCAR=14.0
Pod documented
61  
62 616 ▶ croak "A pid is required" unless $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless $pid 2 614 616
63  
64 614 local $!;
65  
66 614 ▶ return 1 if kill(0, $pid); # Running and we have perms
Branch: 1 branch
BranchTrueFalseTotal
if kill 0, $pid 582 32 614
67 32 ▶ return 0 if $! == ESRCH; # Does not exist (not running)
Branch: 1 branch
BranchTrueFalseTotal
if $! == 3 32 0 32
68 0 return -1; # Running, but not ours
69 }
70  
71 sub clone_io {
72 738 ▶ my ($mode, $orig) = @_;
Subroutine clone_io: called CC=4 SCAR=13.9
Pod documented
73 738 ▶ croak "No mode provided" unless $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 2 736 738
74 736 ▶ croak "No handle provided" unless $orig;
Branch: 1 branch
BranchTrueFalseTotal
unless $orig 2 734 736
75 734 ▶ open(my $fh, $mode, $orig) or die "Could not clone filehandle: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $mode, $orig or die "Could not clone filehandle: $!" 0 734 734
76 734 return $fh;
77 }
78  
79 473 1;
80  
81 __END__
« Manager/Base/FS.pm ↑ Summary Manager/Role/Service/Requests.pm »