diff options
author | Eric Wong <e@80x24.org> | 2023-09-27 06:02:48 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-09-28 02:34:57 +0000 |
commit | 10ca39f5bddcb414dac2a3fcee4cc53844c74fc1 (patch) | |
tree | feb7b4dc50ffd3e5c1bb6da13a10cf97bc2e7ba9 /lib/PublicInbox/ProcessPipe.pm | |
parent | 3cea12e29643a02bc9d33802896d3dd12c8bc8fa (diff) | |
download | public-inbox-10ca39f5bddcb414dac2a3fcee4cc53844c74fc1.tar.gz |
This makes interesting parts of our code easier to read IMHO. We can take advantage of `local' while avoiding `fileno' calls since it's called in spawn() anyways to reduce LoC even further.
Diffstat (limited to 'lib/PublicInbox/ProcessPipe.pm')
-rw-r--r-- | lib/PublicInbox/ProcessPipe.pm | 9 |
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) = @_; |