From 0c8f677e55941c5c65b263294692899c549ce533 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 20 Jun 2016 00:57:17 +0000 Subject: inbox: move field population logic to initializer 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 +++ 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 43ffba77..ea84da35 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 faab03ce..3f1b7334 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; } -- cgit v1.2.3-24-ge0c7