about summary refs log tree commit homepage
path: root/lib/PublicInbox/Feed.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-28 21:43:17 +0000
committerEric Wong <e@80x24.org>2019-12-28 21:43:17 +0000
commit65e3cc8f6cc73e45db827cbeee4ccecbf1502496 (patch)
treec7575754de71f56b92b9ac808cc3d675f374fef2 /lib/PublicInbox/Feed.pm
parentac1ac3b4e2858bcee5a644aac8b6320422ea7383 (diff)
parentf2364c5765f0692d2f1e82b61804359a38f3fdfc (diff)
downloadpublic-inbox-65e3cc8f6cc73e45db827cbeee4ccecbf1502496.tar.gz
* no-closure: (30 commits)
  search: retry_reopen passes user arg to callback
  solvergit: allow passing arg to user-supplied callback
  viewvcs: avoid anonymous sub for HTML response
  wwwattach: avoid anonymous sub for msg_iter
  view: msg_iter calls add_body_text directly
  searchview: remove anonymous sub when sorting threads by relevance
  view: thread_html: pass named sub to WwwStream
  searchview: pass named subs to Www*Stream
  wwwtext: avoid anonymous sub in response
  contentid: no anonymous sub
  view: msg_html: stop using an anonymous sub
  view: avoid anon sub in stream_thread
  config: each_inbox: pass user arg to callback
  feed: avoid anonymous subs
  mboxgz: pass $ctx to callback to avoid anon subs
  www: lazy load Plack::Util
  githttpbackend: split out wwwstatic
  qspawn: psgi_return: allow non-anon parse_hdr callback
  qspawn: drop "qspawn.filter" support, for now
  qspawn: psgi_qx: eliminate anonymous subs
  ...
Diffstat (limited to 'lib/PublicInbox/Feed.pm')
-rw-r--r--lib/PublicInbox/Feed.pm51
1 files changed, 24 insertions, 27 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 6d659759..cbf25d46 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -10,32 +10,26 @@ use PublicInbox::View;
 use PublicInbox::WwwAtomStream;
 use PublicInbox::SearchMsg; # this loads w/o Search::Xapian
 
+sub generate_i {
+        my ($ctx) = @_;
+        while (my $smsg = shift @{$ctx->{msgs}}) {
+                $ctx->{-inbox}->smsg_mime($smsg) and return $smsg;
+        }
+}
+
 # main function
 sub generate {
         my ($ctx) = @_;
-        my $msgs = recent_msgs($ctx);
+        my $msgs = $ctx->{msgs} = recent_msgs($ctx);
         return _no_thread() unless @$msgs;
-
-        my $ibx = $ctx->{-inbox};
-        PublicInbox::WwwAtomStream->response($ctx, 200, sub {
-                while (my $smsg = shift @$msgs) {
-                        $ibx->smsg_mime($smsg) and return $smsg;
-                }
-        });
+        PublicInbox::WwwAtomStream->response($ctx, 200, \&generate_i);
 }
 
 sub generate_thread_atom {
         my ($ctx) = @_;
-        my $mid = $ctx->{mid};
-        my $ibx = $ctx->{-inbox};
-        my $msgs = $ibx->over->get_thread($mid);
+        my $msgs = $ctx->{msgs} = $ctx->{-inbox}->over->get_thread($ctx->{mid});
         return _no_thread() unless @$msgs;
-
-        PublicInbox::WwwAtomStream->response($ctx, 200, sub {
-                while (my $smsg = shift @$msgs) {
-                        $ibx->smsg_mime($smsg) and return $smsg;
-                }
-        });
+        PublicInbox::WwwAtomStream->response($ctx, 200, \&generate_i);
 }
 
 sub generate_html_index {
@@ -56,9 +50,20 @@ sub generate_html_index {
                 [ "Redirecting to $url\n" ] ];
 }
 
+sub new_html_i {
+        my ($nr, $ctx) = @_;
+        my $msgs = $ctx->{msgs};
+        while (my $smsg = shift @$msgs) {
+                my $m = $ctx->{-inbox}->smsg_mime($smsg) or next;
+                my $more = scalar @$msgs;
+                return PublicInbox::View::index_entry($m, $ctx, $more);
+        }
+        PublicInbox::View::pagination_footer($ctx, './new.html');
+}
+
 sub new_html {
         my ($ctx) = @_;
-        my $msgs = recent_msgs($ctx);
+        my $msgs = $ctx->{msgs} = recent_msgs($ctx);
         if (!@$msgs) {
                 return [404, ['Content-Type', 'text/plain'],
                         ["No messages, yet\n"] ];
@@ -66,15 +71,7 @@ sub new_html {
         $ctx->{-html_tip} = '<pre>';
         $ctx->{-upfx} = '';
         $ctx->{-hr} = 1;
-        my $ibx = $ctx->{-inbox};
-        PublicInbox::WwwStream->response($ctx, 200, sub {
-                while (my $smsg = shift @$msgs) {
-                        my $m = $ibx->smsg_mime($smsg) or next;
-                        my $more = scalar @$msgs;
-                        return PublicInbox::View::index_entry($m, $ctx, $more);
-                }
-                PublicInbox::View::pagination_footer($ctx, './new.html');
-        });
+        PublicInbox::WwwStream->response($ctx, 200, \&new_html_i);
 }
 
 # private subs