about summary refs log tree commit homepage
path: root/lib/PublicInbox/NewsWWW.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-25 07:50:52 +0000
committerEric Wong <e@80x24.org>2019-12-27 20:00:37 +0000
commit4bffd23fdd592c356c9b3d56b202d178a12fec43 (patch)
treeec64798ce143b45a300bd23de3a4c6226ec4acaf /lib/PublicInbox/NewsWWW.pm
parent8b192073ae9e940ec066811aaa5618a1601f0565 (diff)
downloadpublic-inbox-4bffd23fdd592c356c9b3d56b202d178a12fec43.tar.gz
Another place where we can replace anonymous subs with named
subs by passing a user-supplied arg.
Diffstat (limited to 'lib/PublicInbox/NewsWWW.pm')
-rw-r--r--lib/PublicInbox/NewsWWW.pm16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/PublicInbox/NewsWWW.pm b/lib/PublicInbox/NewsWWW.pm
index 80bb4886..ee11a089 100644
--- a/lib/PublicInbox/NewsWWW.pm
+++ b/lib/PublicInbox/NewsWWW.pm
@@ -24,16 +24,19 @@ sub redirect ($$) {
           [ "Redirecting to $url\n" ] ]
 }
 
-sub try_inbox ($$) {
-        my ($ibx, $mid) = @_;
+sub try_inbox {
+        my ($ibx, $arg) = @_;
+        return if scalar(@$arg) > 1;
+
         # do not pass $env since HTTP_HOST may differ
         my $url = $ibx->base_url or return;
 
+        my ($mid) = @$arg;
         eval { $ibx->mm->num_for($mid) } or return;
 
         # 302 since the same message may show up on
         # multiple inboxes and inboxes can be added/reordered
-        redirect(302, $url .= mid_escape($mid) . '/');
+        $arg->[1] = redirect(302, $url .= mid_escape($mid) . '/');
 }
 
 sub call {
@@ -70,10 +73,9 @@ sub call {
         }
 
         foreach my $mid (@try) {
-                $pi_config->each_inbox(sub {
-                        $res ||= try_inbox($_[0], $mid);
-                });
-                last if defined $res;
+                my $arg = [ $mid ];
+                $pi_config->each_inbox(\&try_inbox, $arg);
+                defined($res = $arg->[1]) and last;
         }
         $res || [ 404, [qw(Content-Type text/plain)], ["404 Not Found\n"] ];
 }