summaryrefslogtreecommitdiffstats
path: root/lib/App/BorgRestore.pm
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-03-03 00:15:29 +0100
committerFlorian Pritz <bluewind@xinu.at>2017-03-03 00:20:55 +0100
commit40b675d89f6842da2bac7d503ee4154d20abe412 (patch)
tree9129dff70d9c68277f473b90abe959eb8b260e77 /lib/App/BorgRestore.pm
parentea7b9ccd31eda9ec803cebe3e29509a9458757b5 (diff)
downloadApp-BorgRestore-40b675d89f6842da2bac7d503ee4154d20abe412.tar.gz
App-BorgRestore-40b675d89f6842da2bac7d503ee4154d20abe412.tar.xz
Support dependency injection of Borg class
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App/BorgRestore.pm')
-rw-r--r--lib/App/BorgRestore.pm8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm
index d66b7a4..400c2fd 100644
--- a/lib/App/BorgRestore.pm
+++ b/lib/App/BorgRestore.pm
@@ -60,11 +60,13 @@ Florian Pritz E<lt>bluewind@xinu.atE<gt>
sub new {
my $class = shift;
my $opts = shift;
+ my $deps = shift;
my $self = {};
bless $self, $class;
$self->{opts} = $opts;
+ $self->{borg} = $deps->{borg} // App::BorgRestore::Borg->new();
return $self;
}
@@ -199,7 +201,7 @@ sub restore {
$final_destination = App::BorgRestore::Helper::untaint($final_destination, qr(.*));
$self->debug("Removing ".$final_destination);
File::Path::remove_tree($final_destination);
- App::BorgRestore::Borg::restore($components_to_strip, $archive_name, $path);
+ $self->{borg}->restore($components_to_strip, $archive_name, $path);
}
sub get_cache_dir {
@@ -312,7 +314,7 @@ sub handle_added_archives {
$self->debug(sprintf("Adding archive %s", $archive));
- my $proc = App::BorgRestore::Borg::list_archive($archive, \*OUT);
+ my $proc = $self->{borg}->list_archive($archive, \*OUT);
while (<OUT>) {
# roll our own parsing of timestamps for speed since we will be parsing
# a huge number of lines here
@@ -341,7 +343,7 @@ sub handle_added_archives {
sub build_archive_cache {
my $self = shift;
- my $borg_archives = App::BorgRestore::Borg::borg_list();
+ my $borg_archives = $self->{borg}->borg_list();
my $db_path = $self->get_cache_path('archives.db');
# ensure the cache directory exists