blib/lib/PAR/Repository/Zip.pm

filter: Statementstmt 67.1% 45 / 67 Branchbran 26.9% 7 / 26 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 69.2% 9 / 13 Podpod n/a totaltotal 51.2% 62 / 121 CC 17 SCAR 22.3
CC
17
Cov
52%
_unzip_dist_to_path
30.0
_unzip_dist_to_tmpdir
12.0
_unzip_file
6.1
CRAP 9.3
« blib/lib/PAR/Repository.pm ↑ Summary blib/lib/PAR/Repository/DBM.pm »
1 package PAR::Repository::Zip;
2  
3 22 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 22 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 #use File::Path qw/rmtree/;
11 #use ExtUtils::Manifest;
12 #require ExtUtils::MM;
13 22 ▶use Archive::Zip;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 22 our $VERSION = '0.20';
16  
17 =head1 NAME
18  
19 PAR::Repository::Zip - ZIP file handling routines for PAR::Repository
20  
21 =head1 SYNOPSIS
22  
23 use PAR::Repository;
24 ...
25  
26 =head1 DESCRIPTION
27  
28 This module is for internal use only.
29 It contains code for dealing with ZIP files. .par archives
30 are ZIP files.
31  
32 B<All methods here-in are considered private methods (note the
33 underscores in the names). Do not use outside of PAR::Repository.>
34 (Of course, you are free to copy the source code (see license).)
35  
36 =head2 EXPORT
37  
38 None.
39  
40 =head1 METHODS
41  
42 Following is a list of class and instance methods.
43 (Instance methods until otherwise mentioned.)
44  
45 There is no C<PAR::Repository::Zip> object.
46 L<PAR::Repository> inherits from this class.
47  
48 =cut
49  
50 =head2 _unzip_dist_to_path
51  
52 First argument should be path and file name of a .par
53 distribution. Second argument may be a path to unzip the
54 distribution to. (Defaults to current working directory.)
55  
56 Unzips the distribution to the specified directory and returns
57 the directory name. Returns the empty list on failure.
58  
59 =cut
60  
61 0 ▶sub _unzip_dist_to_path {
Subroutine _unzip_dist_to_path: not called CC=5 SCAR=34.0
62 0 my $self = shift;
63 0 $self->verbose(2, "Entering _unzip_to_path()");
64 0 my $dist = shift;
65 0 ▶ my $path = shift || File::Spec->curdir;
Condition0%0/3
shift() || 'File::Spec'->curdir
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || 'File::Spec'->curdir
shift() 'File::Spec'->curdir
Truth table0%0/3
A || B
A= shift()B= 'File::Spec'->curdir
ABresult
1X1
011
000
66 0 ▶ return unless -f $dist;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $dist 0 0 0
67  
68 0 my $zip = Archive::Zip->new;
69 0 local %SIG;
70 0 ▶ $SIG{__WARN__} = sub { print STDERR $_[0] unless $_[0] =~ /\bstat\b/ };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /\bstat\b/ 0 0 0
71 return
72 0 ▶ unless $zip->read($dist) == Archive::Zip::AZ_OK()
Branch: 1 branch
BranchTrueFalseTotal
unless $zip->read($dist) == 0 and $zip->extractTree("", "$path/") == 0 0 0 0
Condition0%0/3
$zip->read($dist) == 0 and $zip->extractTree("", "$path/") == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$zip->read($dist) == 0 and $zip->extractTree("", "$path/") == 0
$zip->read($dist) == 0 $zip->extractTree("", "$path/") == 0
Truth table0%0/3
A and B
A= $zip->read($dist) == 0B= $zip->extractTree("", "$path/") == 0
ABresult
0X0
100
111
73 and $zip->extractTree('', "$path/") == Archive::Zip::AZ_OK();
74 0 return $path;
75 }
76  
77 =head2 _unzip_dist_to_tmpdir
78  
79 Creates a temporary directory and extracts a .par/zip archive into it.
80 First argument must be the archive file and (optional) second argument may
81 be a sub directory (of the temp dir) to extract into. This is mainly intended for
82 C<blib/> sub directories.
83  
84 =cut
85  
86 0 ▶sub _unzip_dist_to_tmpdir {
Subroutine _unzip_dist_to_tmpdir: not called CC=3 SCAR=24.8
87 0 my $self = shift;
88 0 $self->verbose(2, "Entering _unzip_dist_to_tmpdir()");
89 0 my $dist = File::Spec->rel2abs(shift);
90 0 my $subdir = shift;
91 0 ▶ my $tmpdir = File::Temp::mkdtemp(File::Spec->catdir(File::Spec->tmpdir, "parXXXXX")) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
my $tmpdir = File::Temp::mkdtemp("File::Spec"->catdir("File::Spec"->tmpdir, "parXXXXX")) or die $! 0 0 0
92 0 my $path = $tmpdir;
93 0 ▶ $path = File::Spec->catdir($tmpdir, $subdir) if defined $subdir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $subdir 0 0 0
94 0 $self->_unzip_dist_to_path($dist, $path);
95  
96 0 chdir $tmpdir;
97 0 return ($dist, $tmpdir);
98 }
99  
100 =head2 _zip_file
101  
102 Callable as class or instance method.
103  
104 Zips the file given as first argument to the file
105 given as second argument. If there is no second argument,
106 zips to "file1.zip" where "file1" was the first argument.
107  
108 Returns the name of the zip file.
109  
110 Optional third argument is the zip member name to use.
111  
112 =cut
113  
114 227 ▶sub _zip_file {
Subroutine _zip_file: called CC=5 SCAR=16.5
115 227 my $class = shift;
116 227 my $file = shift;
117 227 ▶ return unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 227 227
118 227 my $target = shift;
119 227 my $member_name = shift;
120 227 ▶ $member_name = $file if not defined $member_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $member_name 0 227 227
121 227 ▶ $target = $file.'.zip' if not defined $target;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target 0 227 227
122  
123 227 my $zip = Archive::Zip->new;
124 227 my $member = $zip->addFile( $file, $member_name );
125 227 $member->desiredCompressionLevel( Archive::Zip::COMPRESSION_LEVEL_BEST_COMPRESSION() );
126 227 ▶ $zip->writeToFileNamed( $target ) == Archive::Zip::AZ_OK() or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$zip->writeToFileNamed($target) == 0 or die $! 227 0 227
127
128 227 return $target;
129 }
130  
131 =head2 _unzip_file
132  
133 Unzips the file given as first argument to the file
134 given as second argument.
135 If a third argument is used, the zip member of that name
136 is extracted. If the zip member name is omitted, it is
137 set to the target file name.
138  
139 Returns the name of the unzipped file.
140  
141 =cut
142  
143 182 ▶sub _unzip_file {
Subroutine _unzip_file: called CC=5 SCAR=18.0
144 182 my $class = shift;
145 182 my $file = shift;
146 182 my $target = shift;
147 182 my $member = shift;
148 182 ▶ $member = $target if not defined $member;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $member 0 182 182
149 182 ▶ return unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 182 182
150  
151 182 my $zip = Archive::Zip->new;
152 182 local %SIG;
153 0 ▶ $SIG{__WARN__} = sub { print STDERR $_[0] unless $_[0] =~ /\bstat\b/ };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /\bstat\b/ 0 0 0
154
155 182 ▶ return unless $zip->read($file) == Archive::Zip::AZ_OK()
Branch: 1 branch
BranchTrueFalseTotal
unless $zip->read($file) == 0 and $zip->extractMember($member, $target) == 0 0 182 182
Condition33%1/3
$zip->read($file) == 0 and $zip->extractMember($member, $target) == 0
!ll&&!rl&&r
00182
MC/DC0%0/2
$zip->read($file) == 0 and $zip->extractMember($member, $target) == 0
$zip->read($file) == 0 $zip->extractMember($member, $target) == 0
Truth table33%1/3
A and B
A= $zip->read($file) == 0B= $zip->extractMember($member, $target) == 0
ABresult
0X0
100
111
156 and $zip->extractMember($member, $target) == Archive::Zip::AZ_OK();
157  
158 182 return $target;
159 }
160  
161  
162  
163 22 1;
164 __END__
« blib/lib/PAR/Repository.pm ↑ Summary blib/lib/PAR/Repository/DBM.pm »