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,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 93F402082E for ; Fri, 23 Jun 2017 22:34:53 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/2] config: assume lists have multiple addresses Date: Fri, 23 Jun 2017 22:34:51 +0000 Message-Id: <20170623223452.835-2-e@80x24.org> In-Reply-To: <20170623223452.835-1-e@80x24.org> References: <20170623223452.835-1-e@80x24.org> List-Id: This should simplify the rest of our code for handling the do-not-obfuscate list. --- lib/PublicInbox/Config.pm | 11 +++-------- t/config.t | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 0597a52..2be485e 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -134,7 +134,7 @@ sub _fill { my ($self, $pfx) = @_; my $rv = {}; - foreach my $k (qw(mainrepo address filter url newsgroup + foreach my $k (qw(mainrepo filter url newsgroup infourl watch watchheader httpbackendmax replyto feedmax nntpserver)) { my $v = $self->{"$pfx.$k"}; @@ -154,7 +154,7 @@ sub _fill { # TODO: more arrays, we should support multi-value for # more things to encourage decentralization - foreach my $k (qw(altid nntpmirror)) { + foreach my $k (qw(address altid nntpmirror)) { if (defined(my $v = $self->{"$pfx.$k"})) { $rv->{$k} = ref($v) eq 'ARRAY' ? $v : [ $v ]; } @@ -166,12 +166,7 @@ sub _fill { $rv->{name} = $name; $rv->{-pi_config} = $self; $rv = PublicInbox::Inbox->new($rv); - my $v = $rv->{address}; - if (ref($v) eq 'ARRAY') { - $self->{-by_addr}->{lc($_)} = $rv foreach @$v; - } else { - $self->{-by_addr}->{lc($v)} = $rv; - } + $self->{-by_addr}->{lc($_)} = $rv foreach @{$rv->{address}}; if (my $ng = $rv->{newsgroup}) { $self->{-by_newsgroup}->{$ng} = $rv; } diff --git a/t/config.t b/t/config.t index 3ba6111..437f1d1 100644 --- a/t/config.t +++ b/t/config.t @@ -25,7 +25,7 @@ my $tmpdir = tempdir('pi-config-XXXXXX', TMPDIR => 1, CLEANUP => 1); my $cfg = PublicInbox::Config->new($f); is_deeply($cfg->lookup('meta@public-inbox.org'), { 'mainrepo' => '/home/pi/meta-main.git', - 'address' => 'meta@public-inbox.org', + 'address' => [ 'meta@public-inbox.org' ], 'domain' => 'public-inbox.org', 'url' => 'http://example.com/meta', -primary_address => 'meta@public-inbox.org', -- EW