1 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 package PublicInbox::NewsGroup;
6 use Scalar::Util qw(weaken);
8 require PublicInbox::Msgmap;
9 require PublicInbox::Search;
10 require PublicInbox::GitCatFile;
13 my ($class, $name, $git_dir, $address) = @_;
14 $address = $address->[0] if ref($address);
20 $self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
25 my ($self, $field) = @_;
26 Danga::Socket->AddTimer(30, sub { weaken($self->{$field}) });
31 $self->{gcf} ||= eval {
32 my $gcf = PublicInbox::GitCatFile->new($self->{git_dir});
34 # git repos may be repacked and old packs unlinked
35 defer_weaken($self, 'gcf');
43 PublicInbox::Msgmap->new($self->{git_dir});
44 PublicInbox::Search->new($self->{git_dir});
50 $self->{mm} ||= eval {
51 my $mm = PublicInbox::Msgmap->new($self->{git_dir});
53 # may be needed if we run low on handles
54 defer_weaken($self, 'mm');
61 $self->{search} ||= eval {
62 my $search = PublicInbox::Search->new($self->{git_dir});
64 # may be needed if we run low on handles
65 defer_weaken($self, 'search');
72 open my $fh, '<', "$self->{git_dir}/description" or return '';
73 my $desc = eval { local $/; <$fh> };
80 my ($self, $new) = @_;
81 $self->{address} = $new->{address};
82 $self->{domain} = $new->{domain};
83 if ($self->{git_dir} ne $new->{git_dir}) {
84 # new git_dir requires a new mm and gcf
85 $self->{mm} = $self->{gcf} = undef;
86 $self->{git_dir} = $new->{git_dir};