user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH] qspawn: simplify by using PerlIO::scalar
@ 2019-09-14  9:21 Eric Wong
  0 siblings, 0 replies; only message in thread
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	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-14  9:21 [PATCH] qspawn: simplify by using PerlIO::scalar Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox