App-CLI-Plugin-Proc-PID-File
view release on metacpan or search on metacpan
inc/Test/Builder.pm view on Meta::CPAN
}
elsif( $cmd eq 'skip_all' ) {
return $self->skip_all($arg);
}
elsif( $cmd eq 'tests' ) {
if( $arg ) {
return $self->expected_tests($arg);
}
elsif( !defined $arg ) {
die "Got an undefined number of tests. Looks like you tried to ".
"say how many tests you plan to run but made a mistake.\n";
}
elsif( !$arg ) {
die "You said to run 0 tests! You've got to run something.\n";
}
}
else {
require Carp;
my @args = grep { defined } ($cmd, $arg);
Carp::croak("plan() doesn't understand @args");
}
lib/App/CLI/Plugin/Proc/PID/File.pm view on Meta::CPAN
=head2 Proc::PID::File::path
return pidfile path
Example:
# MyApp::Hello(App::CLI::Command base package)
sub run {
my($self, @args) = @_;
say $self->pf->path;
}
=cut
*Proc::PID::File::path = \&_path;
if ($Proc::PID::File::VERSION < $PROC_PID_FILE_RECOMENDED_VERSION) {
{
no warnings "redefine";
*Proc::PID::File::alive = \&_alive;
*Proc::PID::File::read = \&_read;
lib/App/CLI/Plugin/Proc/PID/File.pm view on Meta::CPAN
package MyApp::Run;
use strict;
use feature ":5.10.0";
sub run {
my($self, @args) = @_;
sleep 60;
say "end";
}
4. first execute
# 60 seconds after the "end" to exit and output
myapp run
5. second execute
first execute run to run the same script again before the end of the
lib/App/CLI/Plugin/Proc/PID/File.pm view on Meta::CPAN
my $act = POSIX::SigAction->new(sub {
my $signal = shift;
die "signal $signal recevied...";
}, $set, SA_RESTART);
my $old_act = POSIX::SigAction->new;
sigaction(SIGTERM, $act, $old_act);
sigaction(SIGINT, $act, $old_act);
if ($self->pf->alive) {
my $pid = $self->pf->read;
kill SIGTERM, $pid;
say "old process " . $self->argv0 . "[$pid] is killed";
}
$self->pf->touch;
$self->maybe::next::method(@argv);
}
1;
2. Load MyApp::Plugin::OldProcessKill
# in MyApp.pm
lib/App/CLI/Plugin/Proc/PID/File.pm view on Meta::CPAN
package MyApp::Run;
use strict;
use feature ":5.10.0";
sub run {
my($self, @args) = @_;
sleep 60;
say "end";
}
4. first execute
# 60 seconds after the "end" to exit and output
myapp run
5. second execute
first execute run to run the same script again before the end of the
( run in 0.548 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )