]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Spawn.pm
favor procedural calls for most private functions
[public-inbox.git] / lib / PublicInbox / Spawn.pm
index 72cd6c3cc4fce032bb8ce36b025854dbeb5b67b4..23f303fbe182ee7968f6ca6ff6c1486498fe1f61 100644 (file)
@@ -15,6 +15,7 @@ use strict;
 use warnings;
 use base qw(Exporter);
 use Symbol qw(gensym);
+use IO::Handle;
 use PublicInbox::ProcessPipe;
 our @EXPORT_OK = qw/which spawn popen_rd/;
 
@@ -165,18 +166,12 @@ sub spawn ($;$$) {
 
 sub popen_rd {
        my ($cmd, $env, $opts) = @_;
-       unless (wantarray || defined $vfork_spawn || defined $env) {
-               open my $fh, '-|', @$cmd or
-                       die('open `'.join(' ', @$cmd) . " pipe failed: $!\n");
-               return $fh
-       }
        pipe(my ($r, $w)) or die "pipe: $!\n";
        $opts ||= {};
        my $blocking = $opts->{Blocking};
-       $r->blocking($blocking) if defined $blocking;
+       IO::Handle::blocking($r, $blocking) if defined $blocking;
        $opts->{1} = fileno($w);
        my $pid = spawn($cmd, $env, $opts);
-       close $w;
        return ($r, $pid) if wantarray;
        my $ret = gensym;
        tie *$ret, 'PublicInbox::ProcessPipe', $pid, $r;