summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-12-16 23:24:20 +0100
committerFlorian Pritz <bluewind@xinu.at>2018-12-16 23:24:20 +0100
commitf23369c8b19a2e0966e6dde843ab6920fe0b93df (patch)
treefe80b3e2b4a00719c18d7dc46ab489f6419926ae
parent6a3c34e6561ed471556564561473486f3a98dfeb (diff)
downloadApp-ArchLinux-PackagerTools-f23369c8b19a2e0966e6dde843ab6920fe0b93df.tar.gz
App-ArchLinux-PackagerTools-f23369c8b19a2e0966e6dde843ab6920fe0b93df.tar.xz
WIP Add configuration class
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--cpanfile1
-rw-r--r--lib/App/ArchLinux/PackagerTools.pm3
-rw-r--r--lib/App/ArchLinux/PackagerTools/Config.pm88
-rwxr-xr-xscript/perlpkg.pl4
4 files changed, 92 insertions, 4 deletions
diff --git a/cpanfile b/cpanfile
index 582ff7e..72ec877 100644
--- a/cpanfile
+++ b/cpanfile
@@ -1,5 +1,6 @@
requires 'CPAN::DistnameInfo';
requires 'Function::Parameters';
+requires 'Hash::Merge';
requires 'IPC::Run';
requires 'Log::Any';
requires 'Log::Any::Adapter';
diff --git a/lib/App/ArchLinux/PackagerTools.pm b/lib/App/ArchLinux/PackagerTools.pm
index 79b4787..a4cd69e 100644
--- a/lib/App/ArchLinux/PackagerTools.pm
+++ b/lib/App/ArchLinux/PackagerTools.pm
@@ -10,6 +10,7 @@ use Log::Any qw($log);
use App::ArchLinux::PackagerTools::Pacman;
use App::ArchLinux::PackagerTools::CPAN;
+use App::ArchLinux::PackagerTools::Config;
=encoding utf-8
@@ -37,6 +38,7 @@ Returns a new instance.
=cut
method new($class: $deps = {}) {
+ $deps->{config} //= App::ArchLinux::PackagerTools::Config->new();
$deps->{cpan} //= App::ArchLinux::PackagerTools::CPAN->new();
$deps->{pacman} //= App::ArchLinux::PackagerTools::Pacman->new({$deps->%{cpan}});
return $class->new_no_defaults($deps);
@@ -46,6 +48,7 @@ method new_no_defaults($class: $deps = {}) {
my $self = {};
bless $self, $class;
$self->{deps} = $deps;
+ $self->{config} = $deps->{config}->get_config();
return $self;
}
diff --git a/lib/App/ArchLinux/PackagerTools/Config.pm b/lib/App/ArchLinux/PackagerTools/Config.pm
new file mode 100644
index 0000000..a44c845
--- /dev/null
+++ b/lib/App/ArchLinux/PackagerTools/Config.pm
@@ -0,0 +1,88 @@
+package App::ArchLinux::PackagerTools::Config;
+use strictures;
+
+use autodie;
+use Function::Parameters;
+use Log::Any qw($log);
+use Hash::Merge;
+use Path::Tiny;
+use TOML qw(from_toml);
+
+=head1 NAME
+
+App::ArchLinux::PackagerTools::Config - ShortDesc
+
+=head1 SYNOPSIS
+
+use App::ArchLinux::PackagerTools::Config;
+
+# synopsis...
+
+=head1 DESCRIPTION
+
+# longer description...
+
+=head1 METHODS
+
+=head2 new
+
+ my $config = App::ArchLinux::PackagerTools::Config->new();
+
+Returns a new instance.
+
+=cut
+
+method new($class: $deps = {}) {
+ return $class->new_no_defaults($deps);
+}
+
+method new_no_defaults($class: $deps = {}) {
+ my $self = {};
+ bless $self, $class;
+ $self->{deps} = $deps;
+ return $self;
+}
+
+=head2 Public Methods
+
+=cut
+
+=head3 get_config
+
+ my $conf = $config->get_config();
+
+Return config content as a hash.
+
+=cut
+
+method get_config() {
+ my $config = $self->_get_default_config();
+
+ my $file = path(($ENV{XDG_CONFIG_HOME} // $ENV{HOME}."/.config")."/perlpkg/config.toml");
+ if ($file->exists) {
+ $log->debugf("Reading config file: %s", $file);
+ my $file_config = from_toml($file->slurp);
+ $config = merge($file_config, $config);
+
+ } else {
+ $log->debug("Config file not found. Returning default config");
+ }
+ return $config;
+}
+
+=head3 _get_default_config
+
+ my $default_conf = $config->_get_default_config();
+
+Return a hash with the default config values.
+
+=cut
+
+method _get_default_config() {
+ return {
+ };
+}
+
+1;
+
+__END__
diff --git a/script/perlpkg.pl b/script/perlpkg.pl
index 8c20f22..e6cac27 100755
--- a/script/perlpkg.pl
+++ b/script/perlpkg.pl
@@ -8,8 +8,6 @@ use strict;
use Function::Parameters;
use Log::Any::Adapter;
use Log::Log4perl qw(:easy);
-use Path::Tiny;
-use TOML qw(from_toml);
use App::ArchLinux::PackagerTools;
@@ -42,8 +40,6 @@ L<App::ArchLinux::PackagerTools>
=cut
-#my $config = from_toml(path(($ENV{XDG_CONFIG_HOME} // $ENV{HOME}."/.config")."/perlpkg/config.toml")->slurp);
-
Log::Log4perl->easy_init($ERROR);
if ($ARGV[0] // "" eq "--debug") {
Log::Log4perl->easy_init($TRACE);