IPC-Manager
view release on metacpan or search on metacpan
lib/IPC/Manager/Util.pm view on Meta::CPAN
require($file);
return $mod;
}
sub pid_is_running {
my $pid = pop;
croak "A pid is required" unless $pid;
local $!;
return 1 if kill(0, $pid); # Running and we have perms
return 0 if $! == ESRCH; # Does not exist (not running)
return -1; # Running, but not ours
}
sub clone_io {
my ($mode, $orig) = @_;
croak "No mode provided" unless $mode;
croak "No handle provided" unless $orig;
open(my $fh, $mode, $orig) or die "Could not clone filehandle: $!";
return $fh;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
IPC::Manager::Util - Utility functions for IPC::Manager
=head1 DESCRIPTION
This module provides utility functions used throughout the IPC::Manager
distribution.
=head1 EXPORTS
The following functions are available via C<use IPC::Manager::Util qw(...)>:
=over 4
=item $bool = USE_INOTIFY()
Returns true if the L<Linux::Inotify2> module is available and supports the
C<fh> method.
This can be used as a constant.
=item $bool = USE_IO_SELECT()
Returns true if the L<IO::Select> module is available.
=item $mod = require_mod($module)
Loads a module by name. Converts C<::> to C</> and appends C<.pm>.
Returns the original input.
=item $val = pid_is_running($pid)
Checks if a PID is running.
returns 1 if the process is running and we have permissions.
returns 0 if the process does not exist.
return -1 if the process is running but we don't have permissions to do
anything with it.
=item $fh = clone_io($mode, $orig)
Clones a filehandle. C<$mode> is the open mode (e.g. C<< '<' >>, C<< '>' >>,
C<< '+<' >>), and C<$orig> is the filehandle to clone.
Returns the filehandle clone.
=item tinysleep($seconds)
Sleeps for up to C<$seconds> seconds (sub-second resolution allowed) using a
4-arg C<select()> under the hood. Unlike L<Time::HiRes/sleep>, which restarts
on C<EINTR>, this returns immediately when a signal handler fires. Use this
in polling loops whose progress depends on signals (C<SIGCHLD>, C<SIGTERM>,
user-installed handlers, etc).
Returns nothing. Like C<Time::HiRes::sleep>, the actual time slept may be
shorter than requested when a signal interrupts it; callers that require a
minimum elapsed time should use a deadline loop.
C<$seconds> values that are undefined or non-positive are treated as a no-op.
=back
=head1 SOURCE
The source code repository for IPC::Manager can be found at
L<https://github.com/exodist/IPC-Manager>.
=head1 MAINTAINERS
=over 4
=item Chad Granum E<lt>exodist@cpan.orgE<gt>
=back
=head1 AUTHORS
=over 4
=item Chad Granum E<lt>exodist@cpan.orgE<gt>
=back
( run in 1.364 second using v1.01-cache-2.11-cpan-39bf76dae61 )