]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/NNTPD.pm
nntpd: avoid exiting subroutine via next
[public-inbox.git] / lib / PublicInbox / NNTPD.pm
1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # represents an NNTPD (currently a singleton),
5 # see script/public-inbox-nntpd for how it is used
6 package PublicInbox::NNTPD;
7 use strict;
8 use warnings;
9 require PublicInbox::Config;
10
11 sub new {
12         my ($class) = @_;
13         bless {
14                 groups => {},
15                 err => \*STDERR,
16                 out => \*STDOUT,
17                 grouplist => [],
18         }, $class;
19 }
20
21 sub refresh_groups () {
22         my ($self) = @_;
23         my $pi_config = PublicInbox::Config->new;
24         my $new = {};
25         my @list;
26         $pi_config->each_inbox(sub {
27                 my ($ng) = @_;
28                 my $ngname = $ng->{newsgroup} or return;
29                 if (ref $ngname) {
30                         warn 'multiple newsgroups not supported: '.
31                                 join(', ', @$ngname). "\n";
32                 } elsif ($ng->nntp_usable) {
33                         # Only valid if msgmap and search works
34                         $new->{$ngname} = $ng;
35                         push @list, $ng;
36                 }
37         });
38         @list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list;
39         $self->{grouplist} = \@list;
40         # this will destroy old groups that got deleted
41         %{$self->{groups}} = %$new;
42 }
43
44 1;