From f22bbb56cf44c6864d53cf27746f9cafc12e05c1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 15 May 2016 06:31:49 +0000 Subject: config: allow taking an existing reference This should make creating test cases easier and faster. --- lib/PublicInbox/Config.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 3f3707ec..b5f0fcb1 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -15,9 +15,12 @@ use File::Path::Expand qw/expand_filename/; sub new { my ($class, $file) = @_; $file = default_file() unless defined($file); - my $self = bless git_config_dump($file), $class; - $self->{-by_addr} = {}; - $self->{-by_name} = {}; + $file = ref $file ? $file : git_config_dump($file); + my $self = bless $file, $class; + + # caches + $self->{-by_addr} ||= {}; + $self->{-by_name} ||= {}; $self; } -- cgit v1.2.3-24-ge0c7