From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 7/7] inbox: move field population logic to initializer
Date: Mon, 20 Jun 2016 00:57:17 +0000 [thread overview]
Message-ID: <20160620005717.1482-8-e@80x24.org> (raw)
In-Reply-To: <20160620005717.1482-1-e@80x24.org>
Inboxes are normally created by Config, but having the
population logic in Inbox should make it easier to mock
for testing.
---
lib/PublicInbox/Config.pm | 4 +---
lib/PublicInbox/Inbox.pm | 3 +++
t/feed.t | 1 -
t/html_index.t | 1 -
4 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 43ffba7..ea84da3 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -129,10 +129,8 @@ sub _fill {
my $name = $pfx;
$name =~ s/\Apublicinbox\.//;
$rv->{name} = $name;
- my $v = $rv->{address} ||= 'public-inbox@example.com';
- my $p = $rv->{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
- $rv->{domain} = ($p =~ /\@(\S+)\z/) ? $1 : 'localhost';
$rv = PublicInbox::Inbox->new($rv);
+ my $v = $rv->{address};
if (ref($v) eq 'ARRAY') {
$self->{-by_addr}->{lc($_)} = $rv foreach @$v;
} else {
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index faab03c..3f1b733 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -11,6 +11,9 @@ use PublicInbox::MID qw(mid2path);
sub new {
my ($class, $opts) = @_;
+ my $v = $opts->{address} ||= 'public-inbox@example.com';
+ my $p = $opts->{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
+ $opts->{domain} = ($p =~ /\@(\S+)\z/) ? $1 : 'localhost';
bless $opts, $class;
}
diff --git a/t/feed.t b/t/feed.t
index 5dd869a..19a9ba0 100644
--- a/t/feed.t
+++ b/t/feed.t
@@ -43,7 +43,6 @@ my $tmpdir = tempdir('pi-feed-XXXXXX', TMPDIR => 1, CLEANUP => 1);
my $git_dir = "$tmpdir/gittest";
my $ibx = PublicInbox::Inbox->new({
address => 'test@example',
- -primary_address => 'test@example',
name => 'testbox',
mainrepo => $git_dir,
url => 'http://example.com/test',
diff --git a/t/html_index.t b/t/html_index.t
index 32d7b8d..100d21a 100644
--- a/t/html_index.t
+++ b/t/html_index.t
@@ -13,7 +13,6 @@ my $tmpdir = tempdir('pi-http-XXXXXX', TMPDIR => 1, CLEANUP => 1);
my $git_dir = "$tmpdir/gittest";
my $ibx = PublicInbox::Inbox->new({
address => 'test@example',
- -primary_address => 'test@example',
name => 'tester',
mainrepo => $git_dir,
url => 'http://example.com/test',
prev parent reply other threads:[~2016-06-20 0:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-20 0:57 [PATCH 0/7] www: various feed/streaming related cleanups Eric Wong
2016-06-20 0:57 ` [PATCH 1/7] MANIFEST: update with recent changes Eric Wong
2016-06-20 0:57 ` [PATCH 2/7] feed: avoid needless method dispatches on 404 Eric Wong
2016-06-20 0:57 ` [PATCH 3/7] feed: remove dependence on fh->write for streaming Eric Wong
2016-06-20 0:57 ` [PATCH 4/7] mbox: remove feed dependency Eric Wong
2016-06-20 0:57 ` [PATCH 5/7] mbox: avoid write dependency for streaming Eric Wong
2016-06-20 0:57 ` [PATCH 6/7] feed: various object-orientation cleanups Eric Wong
2016-06-20 0:57 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160620005717.1482-8-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).