From 40b675d89f6842da2bac7d503ee4154d20abe412 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 3 Mar 2017 00:15:29 +0100 Subject: Support dependency injection of Borg class Signed-off-by: Florian Pritz --- lib/App/BorgRestore.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/App/BorgRestore.pm') 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 Ebluewind@xinu.atE 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 () { # 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 -- cgit v1.2.3-24-g4f1b