]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WwwStream.pm
wwwstream: use parent.pm and no warnings
[public-inbox.git] / lib / PublicInbox / WwwStream.pm
index c80440d14dad6291abdc0fe091c7f9011c9e1eb7..fd558e1b799bb45c8a86797f6b78d0afdcab483a 100644 (file)
@@ -8,8 +8,7 @@
 # more common "push" model)
 package PublicInbox::WwwStream;
 use strict;
-use warnings;
-use base qw(Exporter);
+use parent qw(Exporter);
 our @EXPORT_OK = qw(html_oneshot);
 use bytes (); # length
 use PublicInbox::Hval qw(ascii_html prurl);
@@ -31,7 +30,6 @@ sub init {
        my ($ctx, $cb) = @_;
        $ctx->{cb} = $cb;
        $ctx->{base_url} = base_url($ctx);
-       $ctx->{nr} = 0;
        bless $ctx, __PACKAGE__;
 }
 
@@ -43,7 +41,7 @@ sub response {
        [ $code, $h, $ctx ]
 }
 
-sub _html_top ($) {
+sub html_top ($) {
        my ($ctx) = @_;
        my $ibx = $ctx->{-inbox};
        my $desc = ascii_html($ibx->description);
@@ -159,15 +157,9 @@ EOF
 # callback for HTTP.pm (and any other PSGI servers)
 sub getline {
        my ($ctx) = @_;
-       my $nr = $ctx->{nr}++;
-
-       my $buf = do {
-               if ($nr == 0) {
-                       _html_top($ctx);
-               } elsif (my $middle = $ctx->{cb}) {
-                       $middle->($nr, $ctx);
-               }
-       } // (delete($ctx->{cb}) ? _html_end($ctx) : undef);
+       my $cb = $ctx->{cb};
+       my $buf = $cb->($ctx) if $cb;
+       $buf //= delete($ctx->{cb}) ? _html_end($ctx) : undef;
 
        # gzf may be GzipFilter, `undef' or `0'
        my $gzf = $ctx->{gzf} or return $buf;
@@ -185,12 +177,12 @@ sub html_oneshot ($$;$) {
        my $h = [ 'Content-Type' => 'text/html; charset=UTF-8',
                'Content-Length' => undef ];
        if (my $gzf = gzf_maybe($h, $ctx->{env})) {
-               $gzf->zmore(_html_top($ctx));
+               $gzf->zmore(html_top($ctx));
                $gzf->zmore($$sref) if $sref;
                $x[0] = $gzf->zflush(_html_end($ctx));
                $h->[3] = length($x[0]);
        } else {
-               @x = (_html_top($ctx), $sref ? $$sref : (), _html_end($ctx));
+               @x = (html_top($ctx), $sref ? $$sref : (), _html_end($ctx));
                $h->[3] += bytes::length($_) for @x;
        }
        [ $code, $h, \@x ]