| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $secs and $secs > 0
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 614 | local $!; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 614 | ▶ | return 1 if kill(0, $pid); # Running and we have perms | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 32 | ▶ | return 0 if $! == ESRCH; # Does not exist (not running) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 74 | 736 | ▶ | croak "No handle provided" unless $orig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 734 | ▶ | open(my $fh, $mode, $orig) or die "Could not clone filehandle: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 734 | return $fh; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 473 | 1; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||