]> Sergey Matveev's repositories - public-inbox.git/commitdiff
viewvcs: avoid anonymous sub for HTML response
authorEric Wong <e@80x24.org>
Wed, 25 Dec 2019 07:51:02 +0000 (07:51 +0000)
committerEric Wong <e@80x24.org>
Fri, 27 Dec 2019 20:00:38 +0000 (20:00 +0000)
No need to create a new sub for every HTML page we render
with our VCS viewer.

lib/PublicInbox/ViewVCS.pm

index 7618b19831c9419b2425ec482eea1deccd7265ae..a6dbb9a9080eba3fd197d10599c74287f302241a 100644 (file)
@@ -31,14 +31,17 @@ my %QP_MAP = ( A => 'oid_a', B => 'oid_b', a => 'path_a', b => 'path_b' );
 our $MAX_SIZE = 1024 * 1024; # TODO: configurable
 my $BIN_DETECT = 8000; # same as git
 
+sub html_i { # WwwStream::getline callback
+       my ($nr, $ctx) =  @_;
+       $nr == 1 ? ${delete $ctx->{rv}} : undef;
+}
+
 sub html_page ($$$) {
        my ($ctx, $code, $strref) = @_;
        my $wcb = delete $ctx->{-wcb};
        $ctx->{-upfx} = '../../'; # from "/$INBOX/$OID/s/"
-       my $res = PublicInbox::WwwStream->response($ctx, $code, sub {
-               my ($nr, undef) =  @_;
-               $nr == 1 ? $$strref : undef;
-       });
+       $ctx->{rv} = $strref;
+       my $res = PublicInbox::WwwStream->response($ctx, $code, \&html_i);
        $wcb ? $wcb->($res) : $res;
 }