diff options
author | Eric Wong <e@80x24.org> | 2016-05-14 06:10:36 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-05-16 02:55:58 +0000 |
commit | 48b21cb662c1e17b7219612bff6ea14b98c85221 (patch) | |
tree | 1f5b29c80c52dea26f1a9f33fae9cbe515e3debf /lib/PublicInbox/Inbox.pm | |
parent | 56008dad820a47fe70d2d69a51248ff1b87beabf (diff) | |
download | public-inbox-48b21cb662c1e17b7219612bff6ea14b98c85221.tar.gz |
From the beginning, we've avoided objects here in favor of faster startup time; but it may not be worth it since a persistent httpd/nntpd is faster and -mda isn't hit as often.
Diffstat (limited to 'lib/PublicInbox/Inbox.pm')
-rw-r--r-- | lib/PublicInbox/Inbox.pm | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm new file mode 100644 index 00000000..5d9fdb36 --- /dev/null +++ b/lib/PublicInbox/Inbox.pm @@ -0,0 +1,76 @@ +# Copyright (C) 2016 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +# +# Represents a public-inbox (which may have multiple mailing addresses) +package PublicInbox::Inbox; +use strict; +use warnings; +use Scalar::Util qw(weaken); +use PublicInbox::Git; + +sub new { + my ($class, $opts) = @_; + bless $opts, $class; +} + +sub weaken_all { + my ($self) = @_; + weaken($self->{$_}) foreach qw(git mm search); +} + +sub git { + my ($self) = @_; + $self->{git} ||= eval { PublicInbox::Git->new($self->{mainrepo}) }; +} + +sub mm { + my ($self) = @_; + $self->{mm} ||= eval { PublicInbox::Msgmap->new($self->{mainrepo}) }; +} + +sub search { + my ($self) = @_; + $self->{search} ||= eval { PublicInbox::Search->new($self->{mainrepo}) }; +} + +sub try_cat { + my ($path) = @_; + my $rv = ''; + if (open(my $fh, '<', $path)) { + local $/; + $rv = <$fh>; + } + $rv; +} + +sub description { + my ($self) = @_; + my $desc = $self->{description}; + return $desc if defined $desc; + $desc = try_cat("$self->{mainrepo}/description"); + chomp $desc; + $desc =~ s/\s+/ /smg; + $desc = '($GIT_DIR/description missing)' if $desc eq ''; + $self->{description} = $desc; +} + +sub cloneurl { + my ($self) = @_; + my $url = $self->{cloneurl}; + return $url if $url; + $url = try_cat("$self->{mainrepo}/cloneurl"); + my @url = split(/\s+/s, $url); + chomp @url; + $self->{cloneurl} = \@url; +} + +sub footer_html { + my ($self) = @_; + my $footer = $self->{footer}; + return $footer if defined $footer; + $footer = try_cat("$self->{mainrepo}/public-inbox/footer.html"); + chomp $footer; + $self->{footer} = $footer; +} + +1; |