File Coverage

blib/lib/Archive/Peek/Zip.pm
Criterion Covered Total %
statement 35 35 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 2 3 66.6
total 49 51 96.0


line stmt bran cond sub pod time code
1             package Archive::Peek::Zip;
2 1     1   8 use Moo;
  1         3  
  1         11  
3 1     1   369 use Carp qw(confess);
  1         3  
  1         77  
4 1     1   815 use Archive::Zip qw(AZ_OK);
  1         70053  
  1         103  
5 1     1   582 use Archive::Zip::MemberRead;
  1         1764  
  1         355  
6             extends 'Archive::Peek';
7              
8             sub zip {
9 3     3 0 6 my $self = shift;
10 3         20 my $filename = $self->filename;
11 3         26 my $zip = Archive::Zip->new();
12 3 100       150 unless ( $zip->read( $filename->stringify ) == AZ_OK ) {
13 1         756 confess("Error reading $filename");
14             }
15 2         9744 return $zip;
16             }
17              
18             sub files {
19 2     2 1 690 my $self = shift;
20 2         10 my $zip = $self->zip;
21              
22 1         7 my @members = $zip->members();
23 1         12 my @files = sort map { $_->fileName } grep { !$_->isDirectory } @members;
  4         33  
  8         65  
24 1         54 return @files;
25             }
26              
27             sub file {
28 1     1 1 5 my ( $self, $filename ) = @_;
29 1         5 my $zip = $self->zip;
30              
31 1         14 my $fh = Archive::Zip::MemberRead->new( $zip, $filename );
32 1         1439 my $file = '';
33 1         3 while (1) {
34 2         10 my $read = $fh->read( my $buffer, 1024 );
35 2 50       339 die "FATAL ERROR reading my secrets !\n" if ( !defined($read) );
36 2 100       7 last if ( !$read );
37 1         4 $file .= $buffer;
38             }
39 1         36 return $file;
40             }
41              
42             1;