mirroring instructions on how to clone and mirror
+all data and code used by this external index.
+EOF
+ } elsif ($ctx->{git}) { # coderepo
+ $x = join('', map { "git clone $_\n" }
+ @{$ctx->{git}->cloneurl($ctx->{env})});
}
- my $url = PublicInbox::Hval::prurl($ctx->{env}, PI_URL);
- '
'.join("\n\n",
- $desc,
- $urls,
- 'Served with public-inbox: '.
- qq(git clone $url public-inbox)
- ).'
';
+ chomp $x;
+ '
'.join("\n\n", coderepos($ctx), $x).'
'
}
+# callback for HTTP.pm (and any other PSGI servers)
sub getline {
- my ($self) = @_;
- my $nr = $self->{nr}++;
+ my ($ctx) = @_;
+ my $cb = $ctx->{cb} or return;
+ while (defined(my $x = $cb->($ctx))) { # x = smsg or scalar non-ref
+ if (ref($x)) { # smsg
+ my $eml = $ctx->{ibx}->smsg_eml($x) or next;
+ $ctx->{smsg} = $x;
+ return $ctx->translate($cb->($ctx, $eml));
+ } else { # scalar
+ return $ctx->translate($x);
+ }
+ }
+ delete $ctx->{cb};
+ $ctx->zflush(_html_end($ctx));
+}
- return _html_top($self) if $nr == 0;
+sub html_done ($;@) {
+ my $ctx = $_[0];
+ my $bdy = $ctx->zflush(@_[1..$#_], _html_end($ctx));
+ my $res_hdr = delete $ctx->{-res_hdr};
+ push @$res_hdr, 'Content-Length', length($bdy);
+ [ 200, $res_hdr, [ $bdy ] ]
+}
- if (my $mid = $self->{cb}) { # middle
- $mid = $mid->($nr, $self->{ctx}) and return $mid;
- }
+sub html_oneshot ($$;@) {
+ my ($ctx, $code) = @_[0, 1];
+ my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8',
+ 'Content-Length' => undef ];
+ bless $ctx, __PACKAGE__;
+ $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
+ my @top;
+ $ctx->{base_url} // do {
+ @top = html_top($ctx);
+ $ctx->{base_url} = base_url($ctx);
+ };
+ my $bdy = $ctx->zflush(@top, @_[2..$#_], _html_end($ctx));
+ $res_hdr->[3] = length($bdy);
+ [ $code, $res_hdr, [ $bdy ] ]
+}
+
+sub async_next ($) {
+ my ($http) = @_; # PublicInbox::HTTP
+ my $ctx = $http->{forward} or return;
+ eval {
+ if (my $smsg = $ctx->{smsg} = $ctx->{cb}->($ctx)) {
+ $ctx->smsg_blob($smsg);
+ } else {
+ $ctx->write(_html_end($ctx));
+ $ctx->close; # GzipFilter->close
+ }
+ };
+ warn "E: $@" if $@;
+}
+
+sub aresponse {
+ my ($ctx, $cb) = @_;
+ init($ctx, $cb);
+ $ctx->psgi_response(200, delete $ctx->{-res_hdr});
+}
+
+sub html_init {
+ my ($ctx) = @_;
+ $ctx->{base_url} = base_url($ctx);
+ my $h = $ctx->{-res_hdr} = ['Content-Type', 'text/html; charset=UTF-8'];
+ $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($h, $ctx->{env});
+ bless $ctx, __PACKAGE__;
+ print { $ctx->zfh } html_top($ctx);
+}
- delete $self->{cb} ? _html_end($self) : undef;
+sub DESTROY {
+ my ($ctx) = @_;
+ $ctx->{git}->cleanup if $ctx->{git} && $ctx->{git}->{-tmp};
}
1;