1 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
4 # Used only by the NNTP server to represent a public-inbox git repository
6 package PublicInbox::NewsGroup;
9 use Scalar::Util qw(weaken);
10 require Danga::Socket;
11 require PublicInbox::Msgmap;
12 require PublicInbox::Search;
13 require PublicInbox::Git;
16 my ($class, $name, $git_dir, $address) = @_;
17 $address = $address->[0] if ref($address);
23 $self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
29 weaken($self->{$_}) foreach qw(gcf mm search);
34 $self->{gcf} ||= eval { PublicInbox::Git->new($self->{git_dir}) };
40 PublicInbox::Msgmap->new($self->{git_dir});
41 PublicInbox::Search->new($self->{git_dir});
47 $self->{mm} ||= eval { PublicInbox::Msgmap->new($self->{git_dir}) };
52 $self->{search} ||= eval { PublicInbox::Search->new($self->{git_dir}) };
57 open my $fh, '<', "$self->{git_dir}/description" or return '';
58 my $desc = eval { local $/; <$fh> };
65 my ($self, $new) = @_;
66 $self->{address} = $new->{address};
67 $self->{domain} = $new->{domain};
68 if ($self->{git_dir} ne $new->{git_dir}) {
69 # new git_dir requires a new mm and gcf
70 $self->{mm} = $self->{gcf} = undef;
71 $self->{git_dir} = $new->{git_dir};