about summary refs log tree commit homepage
path: root/lib/PublicInbox/ProcessPipe.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/ProcessPipe.pm')
-rw-r--r--lib/PublicInbox/ProcessPipe.pm9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/PublicInbox/ProcessPipe.pm b/lib/PublicInbox/ProcessPipe.pm
index bbba75a2..16971801 100644
--- a/lib/PublicInbox/ProcessPipe.pm
+++ b/lib/PublicInbox/ProcessPipe.pm
@@ -8,6 +8,15 @@
 package PublicInbox::ProcessPipe;
 use v5.12;
 use PublicInbox::DS qw(awaitpid);
+use Symbol qw(gensym);
+
+sub maybe_new {
+        my ($cls, $pid, $fh, $opt) = @_;
+        return ($fh, $pid) if wantarray;
+        my $s = gensym;
+        tie *$s, $cls, $pid, $fh, @{$opt->{cb_arg} // []};
+        $s;
+}
 
 sub waitcb { # awaitpid callback
         my ($pid, $err_ref, $cb, @args) = @_;