File Coverage

blib/lib/Archive/Any/Create/Zip.pm
Criterion Covered Total %
statement 27 27 100.0
branch 3 6 50.0
condition n/a
subroutine 7 7 100.0
pod 0 5 0.0
total 37 45 82.2


line stmt bran cond sub pod time code
1             package Archive::Any::Create::Zip;
2 1     1   6 use strict;
  1         2  
  1         49  
3              
4 1     1   6 use Archive::Zip qw(:ERROR_CODES);
  1         1  
  1         583  
5              
6             sub init {
7 2     2 0 3 my $self = shift;
8 2         4 my($opt) = @_;
9 2         10 $self->{zip} = Archive::Zip->new;
10             }
11              
12             sub container {
13 2     2 0 3 my $self = shift;
14 2         4 my($dir) = @_;
15 2         4 $self->{container} = $dir;
16 2         10 $self->{zip}->addDirectory("$dir/");
17             }
18              
19             sub add_file {
20 4     4 0 7 my $self = shift;
21 4         5 my($file, $data) = @_;
22 4 50       17 $file = "$self->{container}/$file" if $self->{container};
23 4         15 $self->{zip}->addString($data, $file);
24             }
25              
26             sub write_file {
27 1     1 0 2 my $self = shift;
28 1         2 my($file) = @_;
29 1         7 my $err = $self->{zip}->writeToFileNamed($file);
30 1 50       1906 $err == AZ_OK
31             or throw Archive::Any::Create::Error(error => "write_file failed ($err)");
32 1         5 1;
33             }
34              
35             sub write_filehandle {
36 1     1 0 1 my $self = shift;
37 1         2 my($fh) = @_;
38 1         4 my $err = $self->{zip}->writeToFileHandle($fh);
39 1 50       1279 $err == AZ_OK
40             or throw Archive::Any::Create::Error(error => "write_filehandle failed ($err)");
41 1         3 1;
42             }
43              
44             1;