]> Sergey Matveev's repositories - public-inbox.git/commitdiff
qspawn: simplify by using PerlIO::scalar
authorEric Wong <e@80x24.org>
Sat, 14 Sep 2019 09:21:14 +0000 (09:21 +0000)
committerEric Wong <e@80x24.org>
Sat, 14 Sep 2019 09:22:14 +0000 (09:22 +0000)
I didn't know PerlIO::scalar existed until a few months ago,
but it's been distributed with Perl since 5.8 and doesn't
seem to be split out into it's own package on any distro.

lib/PublicInbox/Qspawn.pm

index f2e91ab6ab671e67c72806d3da6ac7ee7b01bb6b..76e48e8126b912082166660c764d906993510b63 100644 (file)
@@ -153,11 +153,12 @@ sub start {
 # and safe to slurp.
 sub psgi_qx {
        my ($self, $env, $limiter, $qx_cb) = @_;
-       my $qx = PublicInbox::Qspawn::Qx->new;
+       my $scalar = '';
+       open(my $qx, '+>', \$scalar) or die; # PerlIO::scalar
        my $end = sub {
                finish($self, $env);
-               eval { $qx_cb->($qx) };
-               $qx = undef;
+               eval { $qx_cb->(\$scalar) };
+               $qx = $scalar = undef;
        };
        my $rpipe; # comes from popen_rd
        my $async = $env->{'pi-httpd.async'};
@@ -338,21 +339,4 @@ sub setup_rlimit {
        }
 }
 
-# captures everything into a buffer and executes a callback when done
-package PublicInbox::Qspawn::Qx;
-use strict;
-use warnings;
-
-sub new {
-       my ($class) = @_;
-       my $buf = '';
-       bless \$buf, $class;
-}
-
-# called by PublicInbox::HTTPD::Async ($fh->write)
-sub write {
-       ${$_[0]} .= $_[1];
-       undef;
-}
-
 1;