File Coverage

blib/lib/Dist/Metadata/Zip.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 4 50.0
condition n/a
subroutine 9 9 100.0
pod 3 3 100.0
total 42 44 95.4


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   858 use strict;
  4         13  
  4         402  
11 4     4   23 use warnings;
  4         11  
  4         305  
12              
13             package Dist::Metadata::Zip;
14             {
15             $Dist::Metadata::Zip::VERSION = '0.925';
16             }
17             BEGIN {
18 4     4   104 $Dist::Metadata::Zip::AUTHORITY = 'cpan:RWSTAUNER';
19             }
20             # ABSTRACT: Enable Dist::Metadata for zip files
21              
22 4     4   6560 use Archive::Zip 1.30 ();
  4         258856  
  4         104  
23 4     4   40 use Carp (); # core
  4         9  
  4         139  
24              
25 4     4   24 use parent 'Dist::Metadata::Archive';
  4         10  
  4         50  
26              
27             push(@Dist::Metadata::CARP_NOT, __PACKAGE__);
28              
29             sub file_content {
30 22     22 1 52 my ($self, $file) = @_;
31 22         126 my ($content, $status) = $self->archive->contents( $self->full_path($file) );
32 22 50       26204 Carp::croak "Failed to get content of '$file' from archive"
33             if $status != Archive::Zip::AZ_OK();
34 22         170 return $content;
35             }
36              
37             sub find_files {
38 11     11 1 25 my ($self) = @_;
39             return
40 37         299 map { $_->fileName }
  37         390  
41 11         68 grep { !$_->isDirectory }
42             $self->archive->members;
43             }
44              
45             sub read_archive {
46 11     11 1 462 my ($self, $file) = @_;
47              
48 11         89 my $archive = Archive::Zip->new();
49 11 50       505 $archive->read($file) == Archive::Zip::AZ_OK()
50             or Carp::croak "Failed to read zip file!";
51              
52 11         20320 return $archive;
53             }
54              
55             1;
56              
57             __END__