From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 62C6420194 for ; Mon, 20 Jun 2016 00:57:20 +0000 (UTC) From: Eric Wong 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 Message-Id: <20160620005717.1482-8-e@80x24.org> In-Reply-To: <20160620005717.1482-1-e@80x24.org> References: <20160620005717.1482-1-e@80x24.org> List-Id: 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',