File Coverage

blib/lib/Brackup/DecryptedFile.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 4 50.0
condition 2 6 33.3
subroutine 7 7 100.0
pod 0 2 0.0
total 35 43 81.4


line stmt bran cond sub pod time code
1             package Brackup::DecryptedFile;
2              
3 13     13   70 use strict;
  13         29  
  13         510  
4 13     13   79 use warnings;
  13         25  
  13         526  
5 13     13   142 use Carp qw(croak);
  13         24  
  13         602  
6 13     13   7620 use Brackup::Decrypt;
  13         37  
  13         2831  
7              
8             sub new {
9 13     13 0 59 my ($class, %opts) = @_;
10 13         64 my $self = bless {}, $class;
11              
12 13         88 $self->{original_file} = delete $opts{filename}; # filename we're restoring from
13              
14 13 50 33     398 die "File $self->{original_file} does not exist"
15             unless $self->{original_file} && -f $self->{original_file};
16 13 50       52 croak("Unknown options: " . join(', ', keys %opts)) if %opts;
17              
18             # decrypted_file might be undef if no decryption was needed.
19 13         96 $self->{decrypted_file} = Brackup::Decrypt::decrypt_file_if_needed($self->{original_file});
20              
21 13         234 return $self;
22             }
23              
24             sub name {
25 13     13 0 33 my $self = shift;
26 13   33     422 return $self->{decrypted_file} || $self->{original_file};
27             }
28              
29             sub DESTROY {
30 13     13   253 my $self = shift;
31 13         68 unlink(grep { $_ } ($self->{decrypted_file}));
  13         603  
32             }
33              
34             1;