]> Sergey Matveev's repositories - public-inbox.git/commitdiff
inbox: move field population logic to initializer
authorEric Wong <e@80x24.org>
Mon, 20 Jun 2016 00:57:17 +0000 (00:57 +0000)
committerEric Wong <e@80x24.org>
Mon, 20 Jun 2016 00:57:39 +0000 (00:57 +0000)
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
lib/PublicInbox/Inbox.pm
t/feed.t
t/html_index.t

index 43ffba77395652493d92262dc79d15a82b10c8dd..ea84da353c81827bcd018aa3a880d17959a52893 100644 (file)
@@ -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 {
index faab03ce4cb220d491dbf6d501956f49dcfa9289..3f1b7334f01109343a1b1723c165f6d5bbe5b299 100644 (file)
@@ -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;
 }
 
index 5dd869aa16107828d6591a7f01b6f2d5b809a7af..19a9ba09b4149343edd8879bc340ae532bb2cc51 100644 (file)
--- 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',
index 32d7b8de4383c01226f43c18c6695f5f522ebd2a..100d21a84feb5bb4715e4b769ec880458f82643c 100644 (file)
@@ -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',