From 33cef7f24d3ddedc4cd79ee88b0bba6ed1aab4c9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 2 Jul 2016 21:50:28 +0000 Subject: config: introduce each_inbox for iteration This fills in the internal lookup hashes and simplifies callers. --- lib/PublicInbox/Config.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'lib/PublicInbox/Config.pm') diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index ddb4f6b1..d34d11ad 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -50,11 +50,21 @@ sub lookup { _fill($self, $pfx); } -sub lookup_name { +sub lookup_name ($$) { my ($self, $name) = @_; - my $rv = $self->{-by_name}->{$name}; - return $rv if $rv; - $rv = _fill($self, "publicinbox.$name") or return; + $self->{-by_name}->{$name} || _fill($self, "publicinbox.$name"); +} + +sub each_inbox { + my ($self, $cb) = @_; + my %seen; + foreach my $k (keys %$self) { + $k =~ /\Apublicinbox\.([A-Z0-9a-z-]+)\.mainrepo\z/ or next; + next if $seen{$1}; + $seen{$1} = 1; + my $ibx = lookup_name($self, $1) or next; + $cb->($ibx); + } } sub lookup_newsgroup { -- cgit v1.2.3-24-ge0c7