This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update IPC-Cmd to CPAN version 0.98
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Wed, 14 Jun 2017 19:23:55 +0000 (20:23 +0100)
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Wed, 14 Jun 2017 19:23:55 +0000 (20:23 +0100)
  [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

Porting/Maintainers.pl
cpan/IPC-Cmd/lib/IPC/Cmd.pm

index 75165fb..726e065 100755 (executable)
@@ -633,7 +633,7 @@ use File::Glob qw(:case);
     },
 
     'IPC::Cmd' => {
-        'DISTRIBUTION' => 'BINGOS/IPC-Cmd-0.96.tar.gz',
+        'DISTRIBUTION' => 'BINGOS/IPC-Cmd-0.98.tar.gz',
         'FILES'        => q[cpan/IPC-Cmd],
     },
 
index c0e25a2..bef7e4a 100644 (file)
@@ -18,7 +18,7 @@ BEGIN {
                         $HAVE_MONOTONIC
                     ];
 
-    $VERSION        = '0.96';
+    $VERSION        = '0.98';
     $VERBOSE        = 0;
     $DEBUG          = 0;
     $WARN           = 1;
@@ -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);
@@ -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>
 
@@ -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);
       }