| 1 | # PANT::Zip - Provide support for zip archives | ||||||||||
| 2 | |||||||||||
| 3 | package PANT::Zip; | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Cwd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use XML::Writer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Archive::Zip qw( :ERROR_CODES :CONSTANTS );; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | our @ISA = qw(Exporter); | |||||||||
| 15 | |||||||||||
| 16 | # Items to export into callers namespace by default. Note: do not export | ||||||||||
| 17 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||
| 18 | # Do not simply export all your public functions/methods/constants. | ||||||||||
| 19 | |||||||||||
| 20 | # This allows declaration use PANT ':all'; | ||||||||||
| 21 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||
| 22 | # will save memory. | ||||||||||
| 23 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||
| 24 | |||||||||||
| 25 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 26 | |||||||||||
| 27 | 1 | our @EXPORT = qw( ); | |||||||||
| 28 | |||||||||||
| 29 | 1 | our $VERSION = '0.04'; | |||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | 1 | my($clsname, $writer, $zipname, @rest) =@_; | |||||||||
| 34 | 1 | my $self = { | |||||||||
| 35 | writer=>$writer, | ||||||||||
| 36 | name=>$zipname, | ||||||||||
| 37 | zip=>Archive::Zip->new(), | ||||||||||
| 38 | compression=>9, | ||||||||||
| 39 | @rest, | ||||||||||
| 40 | }; | ||||||||||
| 41 | 1 | bless $self, $clsname; | |||||||||
| 42 | 1 | return $self; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub Compression { | ||||||||
|
Subroutine
Compression: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | 0 | my $self = shift; | |||||||||
| 47 | 0 | my $oval = $self->{compression}; | |||||||||
| 48 | 0 | $self->{compression} = shift; | |||||||||
| 49 | 0 | return $oval; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | ▶ | sub AddFile { | ||||||||
|
Subroutine
AddFile: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 53 | 1 | my($self, $name, $newname) = @_; | |||||||||
| 54 | 1 | my $writer = $self->{writer}; | |||||||||
| 55 | 1 | my $zip = $self->{zip}; | |||||||||
| 56 | 1 | ▶ | my $extra = $newname ? " as $newname" : ""; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 1 | $writer->dataElement('li', "Adding file $name$extra to zip archive $self->{name}\n"); | |||||||||
| 58 | 1 | ▶ | return 1 if ($self->{dryrun}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 1 | return $zip->addFile($name, $newname); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | ▶ | sub AddTree { | ||||||||
|
Subroutine
AddTree: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 63 | 1 | my($self, $name, $newname, $func) = @_; | |||||||||
| 64 | 1 | my $writer = $self->{writer}; | |||||||||
| 65 | 1 | my $zip = $self->{zip}; | |||||||||
| 66 | 1 | ▶ | my $extra = $newname ? " as $newname" : ""; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 1 | $writer->dataElement('li', "Adding tree $name$extra to zip archive $self->{name}\n"); | |||||||||
| 68 | 1 | ▶ | return 1 if ($self->{dryrun}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 1 | return $zip->addTree($name, $newname, $func) == AZ_OK; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 1 | ▶ | sub Close { | ||||||||
|
Subroutine
Close: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 73 | 1 | my($self) = @_; | |||||||||
| 74 | 1 | my $writer = $self->{writer}; | |||||||||
| 75 | 1 | my $zip = $self->{zip}; | |||||||||
| 76 | 1 | foreach my $zm ($zip->members()) { | |||||||||
| 77 | 10 | $zm->desiredCompressionLevel($self->{compression}); | |||||||||
| 78 | } | ||||||||||
| 79 | 1 | $writer->dataElement('li', "Writing out zip file $self->{name}\n"); | |||||||||
| 80 | 1 | ▶ | return 1 if ($self->{dryrun}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 1 | return $zip->writeToFileNamed($self->{name}) == AZ_OK; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 1 | 1; | |||||||||
| 85 | __END__ | ||||||||||