summaryrefslogtreecommitdiff
path: root/libpiny/lib/Piny
diff options
context:
space:
mode:
Diffstat (limited to 'libpiny/lib/Piny')
-rw-r--r--libpiny/lib/Piny/Config.pm57
1 files changed, 19 insertions, 38 deletions
diff --git a/libpiny/lib/Piny/Config.pm b/libpiny/lib/Piny/Config.pm
index f179d98..bb72536 100644
--- a/libpiny/lib/Piny/Config.pm
+++ b/libpiny/lib/Piny/Config.pm
@@ -11,7 +11,7 @@ use Moose::Util::TypeConstraints;
use MooseX::StrictConstructor;
use Carp;
-use Config::Simple qw( -lc );
+use Config::GitLike;
use Piny::Environment;
@@ -87,13 +87,8 @@ sub _build__conf {
my $conf;
- if ( $s->has_confpath and -e $s->confpath ) {
- $conf = Config::Simple->new( $s->confpath );
- if ( defined $conf ) {
- $conf = $conf->vars;
- } else {
- $conf = { };
- };
+ if ( $s->has_confpath and -s $s->confpath ) {
+ $conf = Config::GitLike->load_file( $s->confpath );
} else {
$conf = { };
};
@@ -102,15 +97,11 @@ sub _build__conf {
if ( -s $home ) {
- my $userconf = Config::Simple->new( $home );
+ my $userconf = Config::GitLike->load_file( $home );
- if ( defined $userconf ) {
- $userconf = $userconf->vars;
-
- foreach my $key ( keys %$userconf ) {
- if ( not exists $conf->{$key} ) {
- $conf->{$key} = $userconf->{$key};
- };
+ foreach my $key ( keys %$userconf ) {
+ if ( not exists $conf->{$key} ) {
+ $conf->{$key} = $userconf->{$key};
};
};
@@ -118,15 +109,11 @@ sub _build__conf {
if ( -s "/etc/piny-default.conf" ) {
- my $default = Config::Simple->new( "/etc/piny-default.conf" );
-
- if ( defined $default ) {
- $default = $default->vars;
+ my $default = Config::GitLike->load_file( "/etc/piny-default.conf" );
- foreach my $key ( keys %$default ) {
- if ( not exists $conf->{$key} ) {
- $conf->{$key} = $default->{$key};
- };
+ foreach my $key ( keys %$default ) {
+ if ( not exists $conf->{$key} ) {
+ $conf->{$key} = $default->{$key};
};
};
@@ -134,14 +121,10 @@ sub _build__conf {
if ( -s "/etc/piny-override.conf" ) {
- my $override = Config::Simple->new( "/etc/piny-override.conf" );
+ my $override = Config::GitLike->load_file( "/etc/piny-override.conf" );
- if ( defined $override ) {
- $override = $override->vars;
-
- foreach my $key ( keys %$override ) {
- $conf->{$key} = $override->{$key};
- };
+ foreach my $key ( keys %$override ) {
+ $conf->{$key} = $override->{$key};
};
};
@@ -165,17 +148,17 @@ sub save {
my ( $override, $userconf, $default ) = ( {}, {}, {} );
if ( -s "/etc/piny-override.conf" ) {
- $override = Config::Simple->new( "/etc/piny-override.conf" )->vars;
+ $override = Config::GitLike->load_file( "/etc/piny-override.conf" );
};
my $home = Piny::Environment->instance->user->home . "/.gitconfig";
if ( $s->confpath ne $home and -s $home ) {
- $userconf = Config::Simple->new( $home )->vars;
+ $userconf = Config::GitLike->load_file( $home );
};
if ( -s "/etc/piny-default.conf" ) {
- $default = Config::Simple->new( "/etc/piny-default.conf" )->vars;
+ $default = Config::GitLike->load_file( "/etc/piny-default.conf" );
};
foreach my $key ( keys %{$s->_conf} ) {
@@ -189,14 +172,12 @@ sub save {
};
};
- my $cs = Config::Simple->new( syntax => "ini" );
+ my $cs = Config::GitLike->new( confname => 'blank' );
foreach my $key ( keys %{$s->_conf} ) {
- $cs->param( $key, $s->_conf->{$key} );
+ $cs->set( key => $key, value => $s->_conf->{$key}, filename => $s->confpath );
};
- $cs->write( $s->confpath );
-
$s->clear_conf;
};