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, URIBL_BLOCKED shortcircuit=no autolearn=unavailable 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 DD78C1FCBF for ; Mon, 16 May 2016 07:56:07 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] config: allow taking an existing reference Date: Mon, 16 May 2016 07:56:02 +0000 Message-Id: <20160516075603.15700-3-e@80x24.org> In-Reply-To: <20160516075603.15700-1-e@80x24.org> References: <20160516075603.15700-1-e@80x24.org> List-Id: 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 3f3707e..b5f0fcb 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; }