From: Eric Wong Date: Sun, 15 May 2016 06:31:49 +0000 (+0000) Subject: config: allow taking an existing reference X-Git-Tag: v1.0.0~538 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=f22bbb56cf44c6864d53cf27746f9cafc12e05c1 config: allow taking an existing reference This should make creating test cases easier and faster. --- 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; }