File Coverage

blib/lib/Dist/Metadata/Zip.pm
Criterion Covered Total %
statement 27 27 100.0
branch 2 4 50.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 40 42 95.2


line stmt bran cond sub pod time code
1             # vim: set ts=2 sts=2 sw=2 expandtab smarttab:
2             #
3             # This file is part of Dist-Metadata
4             #
5             # This software is copyright (c) 2011 by Randy Stauner.
6             #
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             #
10 4     4   489 use strict;
  4         5  
  4         108  
11 4     4   13 use warnings;
  4         5  
  4         203  
12              
13             package Dist::Metadata::Zip;
14             our $AUTHORITY = 'cpan:RWSTAUNER';
15             # ABSTRACT: Enable Dist::Metadata for zip files
16             $Dist::Metadata::Zip::VERSION = '0.927';
17 4     4   2254 use Archive::Zip 1.30 ();
  4         179069  
  4         86  
18 4     4   40 use Carp (); # core
  4         5  
  4         57  
19              
20 4     4   12 use parent 'Dist::Metadata::Archive';
  4         5  
  4         26  
21              
22             push(@Dist::Metadata::CARP_NOT, __PACKAGE__);
23              
24             sub file_content {
25 22     22 1 30 my ($self, $file) = @_;
26 22         79 my ($content, $status) = $self->archive->contents( $self->full_path($file) );
27 22 50       11193 Carp::croak "Failed to get content of '$file' from archive"
28             if $status != Archive::Zip::AZ_OK();
29 22         118 return $content;
30             }
31              
32             sub find_files {
33 11     11 1 14 my ($self) = @_;
34             return
35 37         167 map { $_->fileName }
36 11         47 grep { !$_->isDirectory }
  37         238  
37             $self->archive->members;
38             }
39              
40             sub read_archive {
41 11     11 1 217 my ($self, $file) = @_;
42              
43 11         73 my $archive = Archive::Zip->new();
44 11 50       352 $archive->read($file) == Archive::Zip::AZ_OK()
45             or Carp::croak "Failed to read zip file!";
46              
47 11         9168 return $archive;
48             }
49              
50             1;
51              
52             __END__