user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] qspawn: simplify by using PerlIO::scalar
@ 2019-09-14  9:21  7% Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2019-09-14  9:21 UTC (permalink / raw)
  To: meta

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 | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index f2e91ab6..76e48e81 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -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;
-- 
EW


^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2019-09-14  9:21  7% [PATCH] qspawn: simplify by using PerlIO::scalar Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).