From 71abf270f5b11f147be839a9b057e106d0f8509f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 1 Apr 2014 23:07:38 +0000 Subject: flesh out MDA and simplify config setup We will be reusing the config parsing code for the CGI script, too. --- lib/PublicInbox/Config.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index d91c28a9..9ba4ad32 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -3,12 +3,13 @@ package PublicInbox::Config; use strict; use warnings; +use File::Path::Expand qw/expand_filename/; # returns key-value pairs of config directives in a hash sub new { my ($class, $file) = @_; - local $ENV{GIT_CONFIG} = $file; + local $ENV{GIT_CONFIG} = defined $file ? $file : default_file(); my @cfg = `git config -l`; $? == 0 or die "git config -l failed: $?\n"; @@ -37,4 +38,11 @@ sub lookup { \%rv; } +sub default_file { + my $f = $ENV{PI_CONFIG}; + return $f if defined $f; + my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox/'); + "$pi_dir/config"; +} + 1; -- cgit v1.2.3-24-ge0c7