diff options
Diffstat (limited to 'libpiny/lib/Piny/Config.pm')
-rw-r--r-- | libpiny/lib/Piny/Config.pm | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/libpiny/lib/Piny/Config.pm b/libpiny/lib/Piny/Config.pm index 3c1ae3f..acf63ff 100644 --- a/libpiny/lib/Piny/Config.pm +++ b/libpiny/lib/Piny/Config.pm @@ -13,6 +13,8 @@ use MooseX::StrictConstructor; use Carp; use Config::Simple qw( -lc ); +use Piny::Environment; + # Types subtype 'GitBool' @@ -91,6 +93,20 @@ sub _build__conf { $conf = { }; }; + my $home = Piny::Environment->instance->user->home . "/.gitconfig"; + + if ( -s $home ) { + + my $userconf = Config::Simple->new( $home )->vars; + + foreach my $key ( keys %$userconf ) { + if ( not exists $conf->{$key} ) { + $conf->{$key} = $userconf->{$key}; + }; + }; + + }; + if ( -s "/etc/piny-default.conf" ) { my $default = Config::Simple->new( "/etc/piny-default.conf" )->vars; @@ -129,28 +145,30 @@ sub save { croak "Can't save a Piny::Config if the confpath is not set!"; }; - if ( -s "/etc/piny-override.conf" ) { + my ( $override, $userconf, $default ) = ( {}, {}, {} ); - my $override = Config::Simple->new( "/etc/piny-override.conf" )->vars; + if ( -s "/etc/piny-override.conf" ) { + $override = Config::Simple->new( "/etc/piny-override.conf" )->vars; + }; - foreach my $key ( keys %$override ) { - if ( exists $s->_conf->{$key} and $s->_conf->{$key} eq $override->{$key} ) { - delete $s->_conf->{$key}; - }; - }; + my $home = Piny::Environment->instance->user->home . "/.gitconfig"; + if ( -s $home ) { + $userconf = Config::Simple->new( $home )->vars; }; if ( -s "/etc/piny-default.conf" ) { + $default = Config::Simple->new( "/etc/piny-default.conf" )->vars; + }; - my $default = Config::Simple->new( "/etc/piny-default.conf" )->vars; - - foreach my $key ( keys %$default ) { - if ( exists $s->_conf->{$key} and $s->_conf->{$key} eq $default->{$key} ) { - delete $s->_conf->{$key}; - }; + foreach my $key ( keys %{$s->_conf} ) { + if ( exists $override->{$key} ) { + delete $s->_conf->{$key}; + } elsif ( exists $userconf->{$key} ) { + delete $s->_conf->{$key} if $userconf->{$key} eq $s->_conf->{$key}; + } elsif ( exists $default->{$key} ) { + delete $s->_conf->{$key} if $default->{$key} eq $s->_conf->{$key}; }; - }; my $cs = Config::Simple->new( syntax => "ini" ); |