File Coverage

blib/lib/Archive/Any/Create/Tar.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod 0 5 0.0
total 32 39 82.0


line stmt bran cond sub pod time code
1             package Archive::Any::Create::Tar;
2 1     1   9 use strict;
  1         2  
  1         51  
3              
4 1     1   6 use Archive::Tar;
  1         3  
  1         434  
5              
6             sub init {
7 2     2 0 5 my $self = shift;
8 2         3 my($opt) = @_;
9 2         13 $self->{tar} = Archive::Tar->new;
10 2         36 $self->{comp} = $opt->{comp};
11             }
12              
13             sub container {
14 2     2 0 3 my $self = shift;
15 2         4 my($dir) = @_;
16 2         8 $self->{container} = $dir;
17             }
18              
19             sub add_file {
20 4     4 0 7 my $self = shift;
21 4         6 my($file, $data) = @_;
22 4         15 $self->{tar}->add_data($file, $data);
23             }
24              
25             sub write_file {
26 1     1 0 1 my $self = shift;
27 1         3 return $self->write_filehandle(@_); # Accepts files or handles
28             }
29              
30             sub write_filehandle {
31 2     2 0 3 my $self = shift;
32 2         3 my($fh) = @_;
33 2 50       8 my $comp = $self->{comp} ? COMPRESS_GZIP : undef;
34 2 50       10 $self->{tar}->write($fh, $comp, $self->{container})
35             or throw Archive::Any::Create::Error(error => $self->{tar}->error);
36 2         4830 1;
37             }
38              
39             1;