diff options
author | Florian Pritz <bluewind@xinu.at> | 2018-09-09 11:14:52 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2018-09-09 15:45:11 +0200 |
commit | 0c56663e09dd80a2c5225446a46b5bd908eb829d (patch) | |
tree | b2a0f95727e64bc568612bfa66970cb6aba3d1e9 /lib | |
parent | 3c55b139aa0371e7bace5ef9b76ff3c15fddca88 (diff) | |
download | App-BorgRestore-0c56663e09dd80a2c5225446a46b5bd908eb829d.tar.gz App-BorgRestore-0c56663e09dd80a2c5225446a46b5bd908eb829d.tar.xz |
Settings: Add constructors
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/BorgRestore.pm | 2 | ||||
-rw-r--r-- | lib/App/BorgRestore/Settings.pm | 37 |
2 files changed, 27 insertions, 12 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm index d90afe2..327bb42 100644 --- a/lib/App/BorgRestore.pm +++ b/lib/App/BorgRestore.pm @@ -90,6 +90,8 @@ L<App::BorgRestore::DB> =cut method new($class: $deps = {}) { + $deps->{settings} //= App::BorgRestore::Settings->new(); + my $db_path = App::BorgRestore::Settings::get_db_path(); my $cache_size = $App::BorgRestore::Settings::sqlite_cache_size; diff --git a/lib/App/BorgRestore/Settings.pm b/lib/App/BorgRestore/Settings.pm index 31249c5..2aea1ae 100644 --- a/lib/App/BorgRestore/Settings.pm +++ b/lib/App/BorgRestore/Settings.pm @@ -118,6 +118,10 @@ See LICENSE for the full license text. =cut +method new($class: $deps = {}) { + return $class->new_no_defaults($deps); +} + our $borg_repo = "backup:borg-".hostname; our $cache_path_base; our @backup_prefixes = ( @@ -126,8 +130,27 @@ our @backup_prefixes = ( our $sqlite_cache_size = 102400; our $prepare_data_in_memory = 1; -if (defined $ENV{XDG_CACHE_HOME} or defined $ENV{HOME}) { - $cache_path_base = sprintf("%s/borg-restore.pl", $ENV{XDG_CACHE_HOME} // $ENV{HOME} ."/.cache"); +method new_no_defaults($class: $deps = {}) { + my $self = {}; + bless $self, $class; + $self->{deps} = $deps; + + + if (defined $ENV{XDG_CACHE_HOME} or defined $ENV{HOME}) { + $cache_path_base = sprintf("%s/borg-restore.pl", $ENV{XDG_CACHE_HOME} // $ENV{HOME} ."/.cache"); + } + + load_config_files(); + + if (not defined $cache_path_base) { + die "Error: \$cache_path_base is not defined. This is most likely because the\n" + ."environment variables \$HOME and \$XDG_CACHE_HOME are not set. Consider setting\n" + ."the path in the config file or ensure that the variables are set."; + } + + $cache_path_base = App::BorgRestore::Helper::untaint($cache_path_base, qr/.*/); + + return $self; } fun load_config_files() { @@ -150,16 +173,6 @@ fun load_config_files() { } } -load_config_files(); - -if (not defined $cache_path_base) { - die "Error: \$cache_path_base is not defined. This is most likely because the\n" - ."environment variables \$HOME and \$XDG_CACHE_HOME are not set. Consider setting\n" - ."the path in the config file or ensure that the variables are set."; -} - -$cache_path_base = App::BorgRestore::Helper::untaint($cache_path_base, qr/.*/); - fun get_cache_base_dir_path($path) { return "$cache_path_base/$path"; } |