Skip to content

Commit

Permalink
Update IPC-Cmd to CPAN version 0.98
Browse files Browse the repository at this point in the history
  [DELTA]

0.98 Fri May 12 17:00:07 BST 2017

  Enhancements:
  * Added wait_loop_callback for run_forked()

  Bug fixes:
  * Only search in curdir in can_run() when on Win32
    RT#105601
  • Loading branch information
bingos committed Jun 14, 2017
1 parent 7346c75 commit 34b02a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Porting/Maintainers.pl
Expand Up @@ -633,7 +633,7 @@ package Maintainers;
},

'IPC::Cmd' => {
'DISTRIBUTION' => 'BINGOS/IPC-Cmd-0.96.tar.gz',
'DISTRIBUTION' => 'BINGOS/IPC-Cmd-0.98.tar.gz',
'FILES' => q[cpan/IPC-Cmd],
},

Expand Down
31 changes: 29 additions & 2 deletions cpan/IPC-Cmd/lib/IPC/Cmd.pm
Expand Up @@ -18,7 +18,7 @@ BEGIN {
$HAVE_MONOTONIC
];

$VERSION = '0.96';
$VERSION = '0.98';
$VERBOSE = 0;
$DEBUG = 0;
$WARN = 1;
Expand Down Expand Up @@ -242,7 +242,7 @@ sub can_run {
} else {
for my $dir (
File::Spec->path,
File::Spec->curdir
( IS_WIN32 ? File::Spec->curdir : () )
) {
next if ! $dir || ! -d $dir;
my $abs = File::Spec->catfile( IS_WIN32 ? Win32::GetShortPathName( $dir ) : $dir, $command);
Expand Down Expand Up @@ -742,6 +742,29 @@ STDOUT from the executing program.
Coderef of a subroutine to call when a portion of data is received on
STDERR from the executing program.
=item C<wait_loop_callback>
Coderef of a subroutine to call inside of the main waiting loop
(while C<run_forked> waits for the external to finish or fail).
It is useful to stop running external process before it ends
by itself, e.g.
my $r = run_forked("some external command", {
'wait_loop_callback' => sub {
if (condition) {
kill(1, $$);
}
},
'terminate_on_signal' => 'HUP',
});
Combined with C<stdout_handler> and C<stderr_handler> allows terminating
external command based on its output. Could also be used as a timer
without engaging with L<alarm> (signals).
Remember that this code could be called every millisecond (depending
on the output which external command generates), so try to make it
as lightweight as possible.
=item C<discard_output>
Expand Down Expand Up @@ -1075,6 +1098,10 @@ sub run_forked {
push @{$ready_fds}, $select->can_read(1/100) if $child_finished;
}

if ($opts->{'wait_loop_callback'} && ref($opts->{'wait_loop_callback'}) eq 'CODE') {
$opts->{'wait_loop_callback'}->();
}

Time::HiRes::usleep(1);
}

Expand Down

0 comments on commit 34b02a7

Please sign in to comment.