From dd551123400beb2e1ec0048d2ed19d82af3cc102 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 17 Dec 2018 16:34:49 +0100 Subject: Config: Load config from file only once Signed-off-by: Florian Pritz --- lib/App/ArchLinux/PackagerTools/Config.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/App') diff --git a/lib/App/ArchLinux/PackagerTools/Config.pm b/lib/App/ArchLinux/PackagerTools/Config.pm index a58e82d..531e517 100644 --- a/lib/App/ArchLinux/PackagerTools/Config.pm +++ b/lib/App/ArchLinux/PackagerTools/Config.pm @@ -42,6 +42,7 @@ method new_no_defaults($class: $context, $deps = {}) { my $self = {}; bless $self, $class; $self->{deps} = $deps; + $self->{config} = $self->_load_config(); $context->{$class} = $self; return $self; } @@ -59,8 +60,24 @@ Return config content as a hash. =cut method get_config() { - my $config = $self->_get_default_config(); + return $self->{config}; +} + +=head2 Private Methods + +=cut + +=head3 _load_config + my $conf = $config->_load_config(); + +Load configuration from config file. You should use get_config() instead since +that returns a cached in-memory copy. + +=cut + +method _load_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); -- cgit v1.2.3-24-g4f1b