]> Sergey Matveev's repositories - public-inbox.git/commitdiff
config: allow taking an existing reference
authorEric Wong <e@80x24.org>
Sun, 15 May 2016 06:31:49 +0000 (06:31 +0000)
committerEric Wong <e@80x24.org>
Mon, 16 May 2016 02:55:58 +0000 (02:55 +0000)
This should make creating test cases easier and faster.

lib/PublicInbox/Config.pm

index 3f3707ecc1470efda6a32787b6a053de365b5c36..b5f0fcb1d8ef7a0b3ebdd7537748d7b51dc0e462 100644 (file)
@@ -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;
 }