blib/lib/PAR/Dist.pm

filter: Statementstmt 16.2% 87 / 534 Branchbran 8.7% 23 / 264 Conditioncond 7.1% 11 / 153 MC/DCmcdc 3.2% 3 / 92 Subroutinesub 27.5% 11 / 40 Podpod 100% 11 / 11 totaltotal 13.3% 146 / 1094 CC 204 SCAR 58.3
CC
204
Cov
13%
blib_to_par
1640.0
merge_par
240.0
_install_or_uninstall
211.1
CRAP 340.2
↑ Summary
1 package PAR::Dist;
2 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 require Exporter;
5 3 ▶use vars qw/$VERSION @ISA @EXPORT @EXPORT_OK $DEBUG/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 $VERSION = '0.53';
8 3 @ISA = 'Exporter';
9 3 @EXPORT = qw/
10 blib_to_par
11 install_par
12 uninstall_par
13 sign_par
14 verify_par
15 merge_par
16 remove_man
17 get_meta
18 generate_blib_stub
19 /;
20  
21 3 @EXPORT_OK = qw/
22 parse_dist_name
23 contains_binaries
24 /;
25  
26 3 $DEBUG = 0;
27  
28 3 ▶use Carp qw/carp croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 =head1 NAME
32  
33 PAR::Dist - Create and manipulate PAR distributions
34  
35 =head1 SYNOPSIS
36  
37 As a shell command:
38  
39 % perl -MPAR::Dist -eblib_to_par
40  
41 In programs:
42  
43 use PAR::Dist;
44  
45 my $dist = blib_to_par(); # make a PAR file using ./blib/
46 install_par($dist); # install it into the system
47 uninstall_par($dist); # uninstall it from the system
48 sign_par($dist); # sign it using Module::Signature
49 verify_par($dist); # verify it using Module::Signature
50  
51 install_par("http://foo.com/DBI-1.37-MSWin32-5.8.0.par"); # works too
52 install_par("http://foo.com/DBI-1.37"); # auto-appends archname + perlver
53 install_par("cpan://SMUELLER/PAR-Packer-0.975"); # uses CPAN author directory
54  
55 =head1 DESCRIPTION
56  
57 This module creates and manipulates I<PAR distributions>. They are
58 architecture-specific B<PAR> files, containing everything under F<blib/>
59 of CPAN distributions after their C<make> or C<Build> stage, a
60 F<META.yml> describing metadata of the original CPAN distribution,
61 and a F<MANIFEST> detailing all files within it. Digitally signed PAR
62 distributions will also contain a F<SIGNATURE> file.
63  
64 The naming convention for such distributions is:
65  
66 $NAME-$VERSION-$ARCH-$PERL_VERSION.par
67  
68 For example, C<PAR-Dist-0.01-i386-freebsd-5.8.0.par> corresponds to the
69 0.01 release of C<PAR-Dist> on CPAN, built for perl 5.8.0 running on
70 C<i386-freebsd>.
71  
72 =head1 FUNCTIONS
73  
74 Several functions are exported by default. Unless otherwise noted,
75 they can take either a hash of
76 named arguments, a single argument (taken as C<$path> by C<blib_to_par>
77 and C<$dist> by other functions), or no arguments (in which case
78 the first PAR file in the current directory is used).
79  
80 Therefore, under a directory containing only a single F<test.par>, all
81 invocations below are equivalent:
82  
83 % perl -MPAR::Dist -e"install_par( dist => 'test.par' )"
84 % perl -MPAR::Dist -e"install_par( 'test.par' )"
85 % perl -MPAR::Dist -einstall_par;
86  
87 If C<$dist> resembles a URL, C<LWP::Simple::mirror> is called to mirror it
88 locally under C<$ENV{PAR_TEMP}> (or C<$TEMP/par/> if unspecified), and the
89 function will act on the fetched local file instead. If the URL begins
90 with C<cpan://AUTHOR/>, it will be expanded automatically to the author's CPAN
91 directory (e.g. C<http://www.cpan.org/modules/by-authors/id/A/AU/AUTHOR/>).
92  
93 If C<$dist> does not have a file extension beginning with a letter or
94 underscore, a dash and C<$suffix> ($ARCH-$PERL_VERSION.par by default)
95 will be appended to it.
96  
97 =head2 blib_to_par
98  
99 Takes key/value pairs as parameters or a single parameter indicating the
100 path that contains the F<blib/> subdirectory.
101  
102 Builds a PAR distribution from the F<blib/> subdirectory under C<path>, or
103 under the current directory if unspecified. If F<blib/> does not exist,
104 it automatically runs F<Build>, F<make>, F<Build.PL> or F<Makefile.PL> to
105 create it.
106  
107 Returns the filename of the generated PAR distribution.
108  
109 Valid parameters are:
110  
111 =over 2
112  
113 =item path
114  
115 Sets the path which contains the F<blib/> subdirectory from which the PAR
116 distribution will be generated.
117  
118 =item name, version, suffix
119  
120 These attributes set the name, version and platform specific suffix
121 of the distribution. Name and version can be automatically
122 determined from the distributions F<META.yml> or F<Makefile.PL> files.
123  
124 The suffix is generated from your architecture name and your version of
125 perl by default.
126  
127 =item dist
128  
129 The output filename for the PAR distribution.
130  
131 =item quiet
132  
133 Set to true to suppress as much output as possible.
134  
135 =back
136  
137 =cut
138  
139 0 ▶sub blib_to_par {
Subroutine blib_to_par: not called CC=40 SCAR=74.0
Pod documented
140 0 ▶ @_ = (path => @_) if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
141  
142 0 my %args = @_;
143 0 require Config;
144  
145  
146 # don't use 'my $foo ... if ...' it creates a static variable!
147 0 ▶ my $quiet = $args{quiet} || 0;
Condition0%0/2
$args{'quiet'} || 0
l!l
00
MC/DC0%0/1
$args{'quiet'} || 0
$args{'quiet'}
Truth table0%0/2
A
A= $args{'quiet'}
Aresult
11
00
148 0 my $dist;
149 0 my $path = $args{path};
150 0 ▶ $dist = File::Spec->rel2abs($args{dist}) if $args{dist};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"dist"} 0 0 0
151 0 my $name = $args{name};
152 0 my $version = $args{version};
153 0 ▶ my $suffix = $args{suffix} || "$Config::Config{archname}-$Config::Config{version}.par";
Condition0%0/2
$args{'suffix'} || "$Config::Config{'archname'}-$Config::Config{'version'}.par"
l!l
00
MC/DC0%0/1
$args{'suffix'} || "$Config::Config{'archname'}-$Config::Config{'version'}.par"
$args{'suffix'}
Truth table0%0/2
A
A= $args{'suffix'}
Aresult
11
00
154 0 my $cwd;
155  
156 0 ▶ if (defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path) 0 0 0
157 0 require Cwd;
158 0 $cwd = Cwd::cwd();
159 0 chdir $path;
160 }
161  
162 0 ▶ _build_blib() unless -d "blib";
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 0 0
163  
164 0 my @files;
165 0 ▶ open MANIFEST, ">", File::Spec->catfile("blib", "MANIFEST") or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open MANIFEST, ">", "File::Spec"->catfile("blib", "MANIFEST") or die $! 0 0 0
166 0 ▶ open META, ">", File::Spec->catfile("blib", "META.yml") or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open META, ">", "File::Spec"->catfile("blib", "META.yml") or die $! 0 0 0
167  
168 0 require File::Find;
169 0 ▶ File::Find::find( sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
170 0 ▶ next unless $File::Find::name;
Branch: 1 branch
BranchTrueFalseTotal
unless $File::Find::name 0 0 0
171 0 ▶ (-r && !-d) and push ( @files, substr($File::Find::name, 5) );
Branch: 1 branch
BranchTrueFalseTotal
-r $_ and not -d $_ and push @files, substr($File::Find::name, 5) 0 0 0
Condition0%0/3
-r $_ and not -d $_
!ll&&!rl&&r
000
MC/DC0%0/2
-r $_ and not -d $_
-r $_ not -d $_
Truth table0%0/3
A and not(B)
A= -r $_B= not -d $_
ABresult
0X0
100
111
172 0 } , 'blib' );
173  
174 0 print MANIFEST join(
175 "\n",
176 ' <!-- accessible as jar:file:///NAME.par!/MANIFEST in compliant browsers -->',
177 (sort @files),
178 q( # <html><body onload="var X=document.body.innerHTML.split(/\n/);var Y='<iframe src=&quot;META.yml&quot; style=&quot;float:right;height:40%;width:40%&quot;></iframe><ul>';for(var x in X){if(!X[x].match(/^\s*#/)&&X[x].length)Y+='<li><a href=&quot;'+X[x]+'&quot;>'+X[x]+'</a>'}document.body.innerHTML=Y">)
179 );
180 0 close MANIFEST;
181  
182 # if MYMETA.yml exists, that takes precedence over META.yml
183 0 my $meta_file_name = "META.yml";
184 0 my $mymeta_file_name = "MYMETA.yml";
185 0 ▶ $meta_file_name = -s $mymeta_file_name ? $mymeta_file_name : $meta_file_name;
Branch: 1 branch
BranchTrueFalseTotal
-s $mymeta_file_name ? : 0 0 0
186 0 ▶ if (open(OLD_META, $meta_file_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open OLD_META, $meta_file_name) 0 0 0
187 0 ▶ while (<OLD_META>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline OLD_META)) 0 0 0
188 0 ▶ if (/^distribution_type:/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^distribution_type:/) { } 0 0 0
189 0 print META "distribution_type: par\n";
190 }
191 else {
192 0 print META $_;
193 }
194  
195 0 ▶ if (/^name:\s+(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^name:\s+(.*)/) { } 0 0 0
elsif (/^version:\s+(\S*)/) { } 0 0 0
196 0 ▶ $name ||= $1;
Condition0%0/3
$name ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= $1
$name $1
Truth table0%0/3
A ||= B
A= $nameB= $1
ABresult
1X1
011
000
197 0 $name =~ s/::/-/g;
198 }
199 elsif (/^version:\s+(\S*)/) {
200 0 ▶ $version ||= $1;
Condition0%0/3
$version ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$version ||= $1
$version $1
Truth table0%0/3
A ||= B
A= $versionB= $1
ABresult
1X1
011
000
201 0 $version =~ s/^['"]|['"]$//g;
202 }
203 }
204 0 close OLD_META;
205 0 close META;
206 }
207  
208 0 ▶ if ((!$name or !$version) and open(MAKEFILE, "Makefile")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $name && $version and open MAKEFILE, "Makefile") 0 0 0
Condition0%0/6
not $name && $version and open MAKEFILE, "Makefile"
!ll&&!rl&&r
000
$name && $version
!ll&&!rl&&r
000
MC/DC0%0/3
not $name && $version and open MAKEFILE, "Makefile"
$name $version open MAKEFILE, "Makefile"
Truth table0%0/5
not(A && B) and C
A= $nameB= $versionC= open MAKEFILE, "Makefile"
ABCresult
11X0
0X00
1000
0X11
1011
209 0 ▶ while (<MAKEFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline MAKEFILE)) 0 0 0
210 0 ▶ if (/^DISTNAME\s+=\s+(.*)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^DISTNAME\s+=\s+(.*)$/) { } 0 0 0
elsif (/^VERSION\s+=\s+(.*)$/) { } 0 0 0
211 0 ▶ $name ||= $1;
Condition0%0/3
$name ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= $1
$name $1
Truth table0%0/3
A ||= B
A= $nameB= $1
ABresult
1X1
011
000
212 }
213 elsif (/^VERSION\s+=\s+(.*)$/) {
214 0 ▶ $version ||= $1;
Condition0%0/3
$version ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$version ||= $1
$version $1
Truth table0%0/3
A ||= B
A= $versionB= $1
ABresult
1X1
011
000
215 }
216 }
217 }
218  
219 0 ▶ if (not defined($name) or not defined($version)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name and defined $version) 0 0 0
Condition0%0/3
defined $name and defined $version
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and defined $version
defined $name defined $version
Truth table0%0/3
A and B
A= defined $nameB= defined $version
ABresult
0X0
100
111
220 # could not determine name or version. Error.
221 0 my $what;
222 0 ▶ if (not defined $name) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $name) { } 0 0 0
elsif (not defined $version) { } 0 0 0
223 0 $what = 'name';
224 0 ▶ $what .= ' and version' if not defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
225 }
226 elsif (not defined $version) {
227 0 $what = 'version';
228 }
229  
230 0 carp("I was unable to determine the $what of the PAR distribution. Please create a Makefile or META.yml file from which we can infer the information or just specify the missing information as an option to blib_to_par.");
231 0 return();
232 }
233  
234 0 $name =~ s/\s+$//;
235 0 $version =~ s/\s+$//;
236  
237 0 my $file = "$name-$version-$suffix";
238 0 ▶ unlink $file if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 0 0 0
239  
240 0 ▶ print META << "YAML" if fileno(META);
Branch: 1 branch
BranchTrueFalseTotal
if fileno META 0 0 0
241 name: $name
242 version: '$version'
243 build_requires: {}
244 conflicts: {}
245 dist_name: $file
246 distribution_type: par
247 dynamic_config: 0
248 generated_by: 'PAR::Dist version $PAR::Dist::VERSION'
249 license: unknown
250 YAML
251 0 close META;
252  
253 0 mkdir('blib', 0777);
254 0 chdir('blib');
255 0 require Cwd;
256 0 my $zipoutfile = File::Spec->catfile(File::Spec->updir, $file);
257 0 _zip(dist => $zipoutfile);
258 0 chdir(File::Spec->updir);
259  
260 0 unlink File::Spec->catfile("blib", "MANIFEST");
261 0 unlink File::Spec->catfile("blib", "META.yml");
262  
263 0 ▶ $dist ||= File::Spec->catfile($cwd, $file) if $cwd;
Branch: 1 branch
BranchTrueFalseTotal
if $cwd 0 0 0
Condition0%0/3
$dist ||= "File::Spec"->catfile($cwd, $file)
l!l&&r!l&&!r
000
MC/DC0%0/2
$dist ||= "File::Spec"->catfile($cwd, $file)
$dist "File::Spec"->catfile($cwd, $file)
Truth table0%0/3
A ||= B
A= $distB= "File::Spec"->catfile($cwd, $file)
ABresult
1X1
011
000
264  
265 0 ▶ if ($dist and $file ne $dist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist and $file ne $dist) 0 0 0
Condition0%0/3
$dist and $file ne $dist
!ll&&!rl&&r
000
MC/DC0%0/2
$dist and $file ne $dist
$dist $file ne $dist
Truth table0%0/3
A and B
A= $distB= $file ne $dist
ABresult
0X0
100
111
266 0 ▶ if ( File::Copy::copy($file, $dist) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (File::Copy::copy($file, $dist)) { } 0 0 0
267 0 unlink $file;
268 } else {
269 0 die "Cannot copy $file: $!";
270 }
271  
272 0 $file = $dist;
273 }
274  
275 0 my $pathname = File::Spec->rel2abs($file);
276 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
277 0 $pathname =~ s!\\!/!g;
278 0 $pathname =~ s!:!|!g;
279 };
280 0 ▶ print << "." if !$quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 0 0
281 Successfully created binary distribution '$file'.
282 Its contents are accessible in compliant browsers as:
283 jar:file://$pathname!/MANIFEST
284 .
285  
286 0 ▶ chdir $cwd if $cwd;
Branch: 1 branch
BranchTrueFalseTotal
if $cwd 0 0 0
287 0 return $file;
288 }
289  
290 0 ▶sub _build_blib {
Subroutine _build_blib: not called CC=5 SCAR=34.0
291 0 ▶ if (-e 'Build') {
Branch: 4 branches
BranchTrueFalseTotal
if (-e 'Build') { } 0 0 0
elsif (-e 'Makefile') { } 0 0 0
elsif (-e 'Build.PL') { } 0 0 0
elsif (-e 'Makefile.PL') { } 0 0 0
292 0 _system_wrapper($^X, "Build");
293 }
294 elsif (-e 'Makefile') {
295 0 _system_wrapper($Config::Config{make});
296 }
297 elsif (-e 'Build.PL') {
298 0 _system_wrapper($^X, "Build.PL");
299 0 _system_wrapper($^X, "Build");
300 }
301 elsif (-e 'Makefile.PL') {
302 0 _system_wrapper($^X, "Makefile.PL");
303 0 _system_wrapper($Config::Config{make});
304 }
305 }
306  
307 =head2 install_par
308  
309 Installs a PAR distribution into the system, using
310 C<ExtUtils::Install::install_default>.
311  
312 If only a single parameter is given, it is treated as the value for the
313 C<dist> parameter.
314  
315 Valid named parameters are:
316  
317 =over 2
318  
319 =item dist
320  
321 The .par file to install. The heuristics outlined in the B<FUNCTIONS>
322 section above apply.
323  
324 =item prefix
325  
326 This string will be prepended to all installation paths.
327 If it isn't specified, the environment variable
328 C<PERL_INSTALL_ROOT> is used as a prefix.
329  
330 =item uninstall_shadows
331  
332 This corresponds to the C<uninstall_shadows> option of L<ExtUtils::Install>. Quoting its manual:
333 If C<uninstall_shadows> is set to true, any differing versions throughout C<@INC>
334 will be uninstalled. This is C<make install UNINST=1>.
335  
336 =item verbose
337  
338 This corresponds to the C<verbose> option of L<ExtUtils::Install>. According to its manual:
339 If C<verbose> is true, will print out each file removed. This is C<make install VERBINST=1>.
340 C<verbose> values going up to 5 show increasingly more diagnostics output.
341  
342 Default verbosity for PAR::Dist is 1.
343  
344 =back
345  
346 If you're just going to install into the running perl like everything else,
347 you can stop reading the rest of this section now.
348  
349 Additionally, you can use several parameters to change the default
350 installation destinations. You don't usually have to worry about this
351 unless you are installing into a user-local directory.
352 The following section outlines the parameter names and default settings:
353  
354 Parameter From To
355 inst_lib blib/lib $Config{installsitelib} (*)
356 inst_archlib blib/arch $Config{installsitearch}
357 inst_script blib/script $Config{installscript}
358 inst_bin blib/bin $Config{installbin}
359 inst_man1dir blib/man1 $Config{installman1dir}
360 inst_man3dir blib/man3 $Config{installman3dir}
361 packlist_read $Config{sitearchexp}/auto/$name/.packlist
362 packlist_write $Config{installsitearch}/auto/$name/.packlist
363  
364 The C<packlist_write> parameter is used to control where the F<.packlist>
365 file is written to. (Necessary for uninstallation.)
366 The C<packlist_read> parameter specifies a .packlist file to merge in if
367 it exists. By setting any of the above installation targets to C<undef>,
368 you can remove that target altogether. For example, passing
369 C<< inst_man1dir => undef, inst_man3dir => undef >> means that the contained
370 manual pages won't be installed. This is not available for the packlists.
371  
372 Again, the defaults will be the normal I<site> paths from C<%Config>.
373  
374 (*) If the C<.par>'s I<inst_archlib> section (normally C<blib/arch>)
375 isn't empty, the code in I<inst_lib> (normally C<blib/lib>) is also installed
376 into the I<inst_archlib> path. This makes sense for XS modules.
377 If, however, you override C<inst_lib>, this automatic conversion is
378 also overridden! You can use the named parameter
379 C<auto_inst_lib_conversion =E<gt> 1> to re-enable the conversion
380 for custom I<inst_lib>'s.
381  
382 Finally, you may specify a C<custom_targets> parameter. Its value should be
383 a reference to a hash of custom installation targets such as
384  
385 custom_targets => { 'blib/my_data' => '/some/path/my_data' }
386  
387 You can use this to install the F<.par> archives contents to arbitrary
388 locations.
389  
390 =cut
391  
392 0 ▶sub install_par {
Subroutine install_par: not called CC=1 SCAR=6.9
Pod documented
393 0 my %args = &_args;
394 0 _install_or_uninstall(%args, action => 'install');
395 }
396  
397 =head2 uninstall_par
398  
399 Uninstalls all previously installed contents of a PAR distribution,
400 using C<ExtUtils::Install::uninstall>.
401  
402 Takes almost the same parameters as C<install_par>, but naturally,
403 the installation target parameters do not apply. The only exception
404 to this is the C<packlist_read> parameter which specifies the
405 F<.packlist> file to read the list of installed files from.
406 It defaults to C<$Config::Config{installsitearch}/auto/$name/.packlist>.
407  
408 Additionally, the C<uninstall_shadows> parameter of C<install_par>
409 isn't available.
410  
411 =cut
412  
413 0 ▶sub uninstall_par {
Subroutine uninstall_par: not called CC=1 SCAR=6.9
Pod documented
414 0 my %args = &_args;
415 0 _install_or_uninstall(%args, action => 'uninstall');
416 }
417  
418 0 ▶sub _install_or_uninstall {
Subroutine _install_or_uninstall: not called CC=15 SCAR=53.5
419 0 my %args = &_args;
420 0 my $name = $args{name};
421 0 my $action = $args{action};
422  
423 0 my %ENV_copy = %ENV;
424 0 ▶ $ENV{PERL_INSTALL_ROOT} = $args{prefix} if defined $args{prefix};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"prefix"} 0 0 0
425  
426 0 require Cwd;
427 0 my $old_dir = Cwd::cwd();
428  
429 0 my ($dist, $tmpdir) = _unzip_to_tmpdir( dist => $args{dist}, subdir => 'blib' );
430  
431 0 ▶ if ( open (META, File::Spec->catfile('blib', 'META.yml')) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open META, "File::Spec"->catfile("blib", "META.yml")) 0 0 0
432 0 ▶ while (<META>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline META)) 0 0 0
433 0 ▶ next unless /^name:\s+(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^name:\s+(.*)/ 0 0 0
434 0 $name = $1;
435 0 $name =~ s/\s+$//;
436 0 last;
437 }
438 0 close META;
439 }
440 0 ▶ return if not defined $name or $name eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or $name eq "" 0 0 0
Condition0%0/3
not defined $name or $name eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $name or $name eq ""
not defined $name $name eq ""
Truth table0%0/3
not(A) or B
A= not defined $nameB= $name eq ""
ABresult
1X1
011
000
441  
442 0 ▶ if (-d 'script') {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "script") 0 0 0
443 0 require ExtUtils::MY;
444 0 ▶ foreach my $file (glob("script/*")) {
Subroutine BEGIN: called CC=1 SCAR=0.2
445 0 ▶ next unless -T $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -T $file 0 0 0
446 0 ExtUtils::MY->fixin($file);
447 0 chmod(0555, $file);
448 }
449 }
450  
451 0 $name =~ s{::|-}{/}g;
452 0 require ExtUtils::Install;
453  
454 0 ▶ if ($action eq 'install') {
Branch: 2 branches
BranchTrueFalseTotal
if ($action eq 'install') { } 0 0 0
elsif ($action eq 'uninstall') { } 0 0 0
455 0 my $target = _installation_target( File::Spec->curdir, $name, \%args );
456 0 ▶ my $custom_targets = $args{custom_targets} || {};
Condition0%0/2
$args{'custom_targets'} || {}
l!l
00
MC/DC0%0/1
$args{'custom_targets'} || {}
$args{'custom_targets'}
Truth table0%0/2
A
A= $args{'custom_targets'}
Aresult
11
00
457 0 $target->{$_} = $custom_targets->{$_} foreach keys %{$custom_targets};
458  
459 0 my $uninstall_shadows = $args{uninstall_shadows};
460 0 my $verbose = $args{verbose};
461 0 ExtUtils::Install::install($target, $verbose, 0, $uninstall_shadows);
462 }
463 elsif ($action eq 'uninstall') {
464 0 require Config;
465 0 my $verbose = $args{verbose};
466 ExtUtils::Install::uninstall(
467 0 ▶ $args{packlist_read}||"$Config::Config{installsitearch}/auto/$name/.packlist",
Condition0%0/2
$args{'packlist_read'} || "$Config::Config{'installsitearch'}/auto/$name/.packlist"
l!l
00
MC/DC0%0/1
$args{'packlist_read'} || "$Config::Config{'installsitearch'}/auto/$name/.packlist"
$args{'packlist_read'}
Truth table0%0/2
A
A= $args{'packlist_read'}
Aresult
11
00
468 $verbose
469 );
470 }
471  
472 0 %ENV = %ENV_copy;
473  
474 0 chdir($old_dir);
475 0 File::Path::rmtree([$tmpdir]);
476  
477 0 return 1;
478 }
479  
480 # Returns the default installation target as used by
481 # ExtUtils::Install::install(). First parameter should be the base
482 # directory containing the blib/ we're installing from.
483 # Second parameter should be the name of the distribution for the packlist
484 # paths. Third parameter may be a hash reference with user defined keys for
485 # the target hash. In fact, any contents that do not start with 'inst_' are
486 # skipped.
487 0 ▶sub _installation_target {
Subroutine _installation_target: not called CC=10 SCAR=47.0
488 0 require Config;
489 0 my $dir = shift;
490 0 my $name = shift;
491 0 ▶ my $user = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
492  
493 # accepted sources (and user overrides)
494 0 my %sources = (
495 inst_lib => File::Spec->catdir($dir,"blib","lib"),
496 inst_archlib => File::Spec->catdir($dir,"blib","arch"),
497 inst_bin => File::Spec->catdir($dir,'blib','bin'),
498 inst_script => File::Spec->catdir($dir,'blib','script'),
499 inst_man1dir => File::Spec->catdir($dir,'blib','man1'),
500 inst_man3dir => File::Spec->catdir($dir,'blib','man3'),
501 packlist_read => 'read',
502 packlist_write => 'write',
503 );
504  
505  
506 0 my $par_has_archlib = _directory_not_empty( $sources{inst_archlib} );
507  
508 # default targets
509 my $target = {
510 read => $Config::Config{sitearchexp}."/auto/$name/.packlist",
511 write => $Config::Config{installsitearch}."/auto/$name/.packlist",
512 $sources{inst_lib} =>
513 ($par_has_archlib
514 ? $Config::Config{installsitearch}
515 : $Config::Config{installsitelib}),
516 $sources{inst_archlib} => $Config::Config{installsitearch},
517 $sources{inst_bin} => $Config::Config{installbin} ,
518 $sources{inst_script} => $Config::Config{installscript},
519 $sources{inst_man1dir} => $Config::Config{installman1dir},
520 $sources{inst_man3dir} => $Config::Config{installman3dir},
521 0 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$par_has_archlib ? : 0 0 0
522  
523 # Included for future support for ${flavour}perl external lib installation
524 # if ($Config::Config{flavour_perl}) {
525 # my $ext = File::Spec->catdir($dir, 'blib', 'ext');
526 # # from => to
527 # $sources{inst_external_lib} = File::Spec->catdir($ext, 'lib');
528 # $sources{inst_external_bin} = File::Spec->catdir($ext, 'bin');
529 # $sources{inst_external_include} = File::Spec->catdir($ext, 'include');
530 # $sources{inst_external_src} = File::Spec->catdir($ext, 'src');
531 # $target->{ $sources{inst_external_lib} } = $Config::Config{flavour_install_lib};
532 # $target->{ $sources{inst_external_bin} } = $Config::Config{flavour_install_bin};
533 # $target->{ $sources{inst_external_include} } = $Config::Config{flavour_install_include};
534 # $target->{ $sources{inst_external_src} } = $Config::Config{flavour_install_src};
535 # }
536  
537 # insert user overrides
538 0 foreach my $key (keys %$user) {
539 0 my $value = $user->{$key};
540 0 ▶ if (not defined $value and $key ne 'packlist_read' and $key ne 'packlist_write') {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value and $key ne 'packlist_read' and $key ne 'packlist_write') { } 0 0 0
elsif (exists $sources{$key}) { } 0 0 0
Condition0%0/6
not defined $value and $key ne "packlist_read" and $key ne "packlist_write"
!ll&&!rl&&r
000
not defined $value and $key ne "packlist_read"
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $value and $key ne "packlist_read" and $key ne "packlist_write"
not defined $value $key ne "packlist_read" $key ne "packlist_write"
Truth table0%0/4
not(A) and B and C
A= not defined $valueB= $key ne "packlist_read"C= $key ne "packlist_write"
ABCresult
0XX0
10X0
1100
1111
541 # undef means "remove"
542 0 delete $target->{ $sources{$key} };
543 }
544 elsif (exists $sources{$key}) {
545 # overwrite stuff, don't let the user create new entries
546 0 $target->{ $sources{$key} } = $value;
547 }
548 }
549  
550 # apply the automatic inst_lib => inst_archlib conversion again
551 # if the user asks for it and there is an archlib in the .par
552 0 ▶ if ($user->{auto_inst_lib_conversion} and $par_has_archlib) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user->{"auto_inst_lib_conversion"} and $par_has_archlib) 0 0 0
Condition0%0/3
$user->{"auto_inst_lib_conversion"} and $par_has_archlib
!ll&&!rl&&r
000
MC/DC0%0/2
$user->{"auto_inst_lib_conversion"} and $par_has_archlib
$user->{"auto_inst_lib_conversion"} $par_has_archlib
Truth table0%0/3
A and B
A= $user->{"auto_inst_lib_conversion"}B= $par_has_archlib
ABresult
0X0
100
111
553 0 $target->{inst_lib} = $target->{inst_archlib};
554 }
555  
556 0 return $target;
557 }
558  
559 0 ▶sub _directory_not_empty {
Subroutine _directory_not_empty: not called CC=1 SCAR=6.9
560 0 require File::Find;
561 0 my($dir) = @_;
562 0 my $files = 0;
563 0 ▶ File::Find::find(sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
564 0 ▶ return if $_ eq ".exists";
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq ".exists" 0 0 0
565 0 ▶ if (-f) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $_) 0 0 0
566 0 $File::Find::prune++;
567 0 $files = 1;
568 }
569 0 }, $dir);
570 0 return $files;
571 }
572  
573 =head2 sign_par
574  
575 Digitally sign a PAR distribution using C<gpg> or B<Crypt::OpenPGP>,
576 via B<Module::Signature>.
577  
578 =cut
579  
580 0 ▶sub sign_par {
Subroutine sign_par: not called CC=1 SCAR=6.9
Pod documented
581 0 my %args = &_args;
582 0 _verify_or_sign(%args, action => 'sign');
583 }
584  
585 =head2 verify_par
586  
587 Verify the digital signature of a PAR distribution using C<gpg> or
588 B<Crypt::OpenPGP>, via B<Module::Signature>.
589  
590 Returns a boolean value indicating whether verification passed; C<$!>
591 is set to the return code of C<Module::Signature::verify>.
592  
593 =cut
594  
595 0 ▶sub verify_par {
Subroutine verify_par: not called CC=1 SCAR=6.9
Pod documented
596 0 my %args = &_args;
597 0 $! = _verify_or_sign(%args, action => 'verify');
598 0 return ( $! == Module::Signature::SIGNATURE_OK() );
599 }
600  
601 =head2 merge_par
602  
603 I<Note:> Since version 0.32 of PAR::Dist, this function requires a YAML
604 reader. The order of precedence is:
605  
606 YAML:XS YAML YAML::Syck YAML::Tiny
607  
608 Merges two or more PAR distributions into one. First argument must
609 be the name of the distribution you want to merge all others into.
610 Any following arguments will be interpreted as the file names of
611 further PAR distributions to merge into the first one.
612  
613 merge_par('foo.par', 'bar.par', 'baz.par')
614  
615 This will merge the distributions C<foo.par>, C<bar.par> and C<baz.par>
616 into the distribution C<foo.par>. C<foo.par> will be overwritten!
617  
618 The original META.yml of C<foo.par> is retained, but augmented with any
619 C<provides>, C<requires>, C<recommends>, C<build_requires>, and
620 C<configure_requires> sections from the other C<.par> files.
621  
622 =cut
623  
624 0 ▶sub merge_par {
Subroutine merge_par: not called CC=15 SCAR=54.8
Pod documented
625 0 my $base_par = shift;
626 0 my @additional_pars = @_;
627 0 require Cwd;
628 0 require File::Copy;
629 0 require File::Path;
630 0 require File::Find;
631  
632 # parameter checking
633 0 ▶ if (not defined $base_par) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_par) 0 0 0
634 0 croak "First argument to merge_par() must be the .par archive to modify.";
635 }
636  
637 0 ▶ if (not -f $base_par or not -r _ or not -w _) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $base_par and -r _ and -w _) 0 0 0
Condition0%0/6
-f $base_par and -r _ and -w _
!ll&&!rl&&r
000
-f $base_par and -r _
!ll&&!rl&&r
000
MC/DC0%0/3
-f $base_par and -r _ and -w _
-f $base_par -r _ -w _
Truth table0%0/4
A and B and C
A= -f $base_parB= -r _C= -w _
ABCresult
0XX0
10X0
1100
1111
638 0 croak "'$base_par' is not a file or you do not have enough permissions to read and modify it.";
639 }
640  
641 0 foreach (@additional_pars) {
642 0 ▶ if (not -f $_ or not -r _) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $_ and -r _) 0 0 0
Condition0%0/3
-f $_ and -r _
!ll&&!rl&&r
000
MC/DC0%0/2
-f $_ and -r _
-f $_ -r _
Truth table0%0/3
A and B
A= -f $_B= -r _
ABresult
0X0
100
111
643 0 croak "'$_' is not a file or you do not have enough permissions to read it.";
644 }
645 }
646  
647 # The unzipping will change directories. Remember old dir.
648 0 my $old_cwd = Cwd::cwd();
649  
650 # Unzip the base par to a temp. dir.
651 0 (undef, my $base_dir) = _unzip_to_tmpdir(
652 dist => $base_par, subdir => 'blib'
653 );
654 0 my $blibdir = File::Spec->catdir($base_dir, 'blib');
655  
656 # move the META.yml to the (main) temp. dir.
657 0 my $main_meta_file = File::Spec->catfile($base_dir, 'META.yml');
658 0 File::Copy::move(
659 File::Spec->catfile($blibdir, 'META.yml'),
660 $main_meta_file
661 );
662 # delete (incorrect) MANIFEST
663 0 unlink File::Spec->catfile($blibdir, 'MANIFEST');
664  
665 # extract additional pars and merge
666 0 foreach my $par (@additional_pars) {
667 # restore original directory because the par path
668 # might have been relative!
669 0 chdir($old_cwd);
670 0 (undef, my $add_dir) = _unzip_to_tmpdir(
671 dist => $par
672 );
673  
674 # merge the meta (at least the provides info) into the main meta.yml
675 0 my $meta_file = File::Spec->catfile($add_dir, 'META.yml');
676 0 ▶ if (-f $meta_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $meta_file) 0 0 0
677 0 _merge_meta($main_meta_file, $meta_file);
678 }
679  
680 0 my @files;
681 my @dirs;
682 # I hate File::Find
683 # And I hate writing portable code, too.
684 File::Find::find(
685 0 ▶ {wanted =>sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
686 0 my $file = $File::Find::name;
687 0 ▶ push @files, $file if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 0 0 0
688 0 ▶ push @dirs, $file if -d _;
Branch: 1 branch
BranchTrueFalseTotal
if -d _ 0 0 0
689 }},
690 0 $add_dir
691 );
692 0 my ($vol, $subdir, undef) = File::Spec->splitpath( $add_dir, 1);
693 0 my @dir = File::Spec->splitdir( $subdir );
694  
695 # merge directory structure
696 0 foreach my $dir (@dirs) {
697 0 my ($v, $d, undef) = File::Spec->splitpath( $dir, 1 );
698 0 my @d = File::Spec->splitdir( $d );
699 0 shift @d foreach @dir; # remove tmp dir from path
700 0 my $target = File::Spec->catdir( $blibdir, @d );
701 0 mkdir($target);
702 }
703  
704 # merge files
705 0 foreach my $file (@files) {
706 0 my ($v, $d, $f) = File::Spec->splitpath( $file );
707 0 my @d = File::Spec->splitdir( $d );
708 0 shift @d foreach @dir; # remove tmp dir from path
709 0 my $target = File::Spec->catfile(
710 File::Spec->catdir( $blibdir, @d ),
711 $f
712 );
713 0 ▶ File::Copy::copy($file, $target)
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy($file, $target) or die "Could not copy '${file}' to '${target}': $!" 0 0 0
714 or die "Could not copy '$file' to '$target': $!";
715  
716 }
717 0 chdir($old_cwd);
718 0 File::Path::rmtree([$add_dir]);
719 }
720  
721 # delete (copied) MANIFEST and META.yml
722 0 unlink File::Spec->catfile($blibdir, 'MANIFEST');
723 0 unlink File::Spec->catfile($blibdir, 'META.yml');
724  
725 0 chdir($base_dir);
726 0 my $resulting_par_file = Cwd::abs_path(blib_to_par(quiet => 1));
727 0 chdir($old_cwd);
728 0 File::Copy::move($resulting_par_file, $base_par);
729  
730 0 File::Path::rmtree([$base_dir]);
731 }
732  
733  
734 0 ▶sub _merge_meta {
Subroutine _merge_meta: not called CC=9 SCAR=45.0
735 0 my $meta_orig_file = shift;
736 0 my $meta_extra_file = shift;
737 0 ▶ return() if not defined $meta_orig_file or not -f $meta_orig_file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $meta_orig_file and -f $meta_orig_file 0 0 0
Condition0%0/3
defined $meta_orig_file and -f $meta_orig_file
!ll&&!rl&&r
000
MC/DC0%0/2
defined $meta_orig_file and -f $meta_orig_file
defined $meta_orig_file -f $meta_orig_file
Truth table0%0/3
A and B
A= defined $meta_orig_fileB= -f $meta_orig_file
ABresult
0X0
100
111
738 0 ▶ return 1 if not defined $meta_extra_file or not -f $meta_extra_file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $meta_extra_file and -f $meta_extra_file 0 0 0
Condition0%0/3
defined $meta_extra_file and -f $meta_extra_file
!ll&&!rl&&r
000
MC/DC0%0/2
defined $meta_extra_file and -f $meta_extra_file
defined $meta_extra_file -f $meta_extra_file
Truth table0%0/3
A and B
A= defined $meta_extra_fileB= -f $meta_extra_file
ABresult
0X0
100
111
739  
740 0 my $yaml_functions = _get_yaml_functions();
741  
742 die "Cannot merge META.yml files without a YAML reader/writer"
743 if !exists $yaml_functions->{LoadFile}
744 0 ▶ or !exists $yaml_functions->{DumpFile};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $yaml_functions->{"LoadFile"} and exists $yaml_functions->{"DumpFile"} 0 0 0
Condition0%0/3
exists $yaml_functions->{"LoadFile"} and exists $yaml_functions->{"DumpFile"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $yaml_functions->{"LoadFile"} and exists $yaml_functions->{"DumpFile"}
exists $yaml_functions->{"LoadFile"} exists $yaml_functions->{"DumpFile"}
Truth table0%0/3
A and B
A= exists $yaml_functions->{"LoadFile"}B= exists $yaml_functions->{"DumpFile"}
ABresult
0X0
100
111
745  
746 0 my $orig_meta = $yaml_functions->{LoadFile}->($meta_orig_file);
747 0 my $extra_meta = $yaml_functions->{LoadFile}->($meta_extra_file);
748  
749 # I seem to remember there was this incompatibility between the different
750 # YAML implementations with regards to "document" handling:
751 0 ▶ my $orig_tree = (ref($orig_meta) eq 'ARRAY' ? $orig_meta->[0] : $orig_meta);
Branch: 1 branch
BranchTrueFalseTotal
ref $orig_meta eq 'ARRAY' ? : 0 0 0
752 0 ▶ my $extra_tree = (ref($extra_meta) eq 'ARRAY' ? $extra_meta->[0] : $extra_meta);
Branch: 1 branch
BranchTrueFalseTotal
ref $extra_meta eq 'ARRAY' ? : 0 0 0
753  
754 0 _merge_provides($orig_tree, $extra_tree);
755 0 _merge_requires($orig_tree, $extra_tree);
756  
757 0 $yaml_functions->{DumpFile}->($meta_orig_file, $orig_meta);
758  
759 0 return 1;
760 }
761  
762 # merge the two-level provides sections of META.yml
763 0 ▶sub _merge_provides {
Subroutine _merge_provides: not called CC=5 SCAR=34.0
764 0 my $orig_hash = shift;
765 0 my $extra_hash = shift;
766  
767 0 ▶ return() if not exists $extra_hash->{provides};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $extra_hash->{"provides"} 0 0 0
768 0 ▶ $orig_hash->{provides} ||= {};
Condition0%0/2
$orig_hash->{"provides"} ||= {}
l!l
00
MC/DC0%0/1
$orig_hash->{"provides"} ||= {}
$orig_hash->{"provides"}
Truth table0%0/2
A
A= $orig_hash->{"provides"}
Aresult
11
00
769  
770 0 my $orig_provides = $orig_hash->{provides};
771 0 my $extra_provides = $extra_hash->{provides};
772  
773 # two level clone is enough wrt META spec 1.4
774 # overwrite the original provides since we're also overwriting the files.
775 0 foreach my $module (keys %$extra_provides) {
776 0 my $extra_mod_hash = $extra_provides->{$module};
777 0 my %mod_hash;
778 0 $mod_hash{$_} = $extra_mod_hash->{$_} for keys %$extra_mod_hash;
779 0 $orig_provides->{$module} = \%mod_hash;
780 }
781 }
782  
783 # merge the single-level requires-like sections of META.yml
784 0 ▶sub _merge_requires {
Subroutine _merge_requires: not called CC=5 SCAR=34.0
785 0 my $orig_hash = shift;
786 0 my $extra_hash = shift;
787  
788 0 foreach my $type (qw(requires build_requires configure_requires recommends)) {
789 0 ▶ next if not exists $extra_hash->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $extra_hash->{$type} 0 0 0
790 0 ▶ $orig_hash->{$type} ||= {};
Condition0%0/2
$orig_hash->{$type} ||= {}
l!l
00
MC/DC0%0/1
$orig_hash->{$type} ||= {}
$orig_hash->{$type}
Truth table0%0/2
A
A= $orig_hash->{$type}
Aresult
11
00
791  
792 # one level clone is enough wrt META spec 1.4
793 0 foreach my $module (keys %{ $extra_hash->{$type} }) {
794 # FIXME there should be a version comparison here, BUT how are we going to do that without a guaranteed version.pm?
795 0 $orig_hash->{$type}{$module} = $extra_hash->{$type}{$module}; # assign version and module name
796 }
797 }
798 }
799  
800 =head2 remove_man
801  
802 Remove the man pages from a PAR distribution. Takes one named
803 parameter: I<dist> which should be the name (and path) of the
804 PAR distribution file. The calling conventions outlined in
805 the C<FUNCTIONS> section above apply.
806  
807 The PAR archive will be
808 extracted, stripped of all C<man\d?> and C<html> subdirectories
809 and then repackaged into the original file.
810  
811 =cut
812  
813 0 ▶sub remove_man {
Subroutine remove_man: not called CC=6 SCAR=37.4
Pod documented
814 0 my %args = &_args;
815 0 my $par = $args{dist};
816 0 require Cwd;
817 0 require File::Copy;
818 0 require File::Path;
819 0 require File::Find;
820  
821 # parameter checking
822 0 ▶ if (not defined $par) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $par) 0 0 0
823 0 croak "First argument to remove_man() must be the .par archive to modify.";
824 }
825  
826 0 ▶ if (not -f $par or not -r _ or not -w _) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $par and -r _ and -w _) 0 0 0
Condition0%0/6
-f $par and -r _ and -w _
!ll&&!rl&&r
000
-f $par and -r _
!ll&&!rl&&r
000
MC/DC0%0/3
-f $par and -r _ and -w _
-f $par -r _ -w _
Truth table0%0/4
A and B and C
A= -f $parB= -r _C= -w _
ABCresult
0XX0
10X0
1100
1111
827 0 croak "'$par' is not a file or you do not have enough permissions to read and modify it.";
828 }
829  
830 # The unzipping will change directories. Remember old dir.
831 0 my $old_cwd = Cwd::cwd();
832  
833 # Unzip the base par to a temp. dir.
834 0 (undef, my $base_dir) = _unzip_to_tmpdir(
835 dist => $par, subdir => 'blib'
836 );
837 0 my $blibdir = File::Spec->catdir($base_dir, 'blib');
838  
839 # move the META.yml to the (main) temp. dir.
840 0 File::Copy::move(
841 File::Spec->catfile($blibdir, 'META.yml'),
842 File::Spec->catfile($base_dir, 'META.yml')
843 );
844 # delete (incorrect) MANIFEST
845 0 unlink File::Spec->catfile($blibdir, 'MANIFEST');
846  
847 0 ▶ opendir DIRECTORY, 'blib' or die $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir DIRECTORY, "blib" or die $! 0 0 0
848 0 my @dirs = grep { /^blib\/(?:man\d*|html)$/ }
849 0 grep { -d $_ }
850 0 map { File::Spec->catfile('blib', $_) }
851 readdir DIRECTORY;
852 0 close DIRECTORY;
853  
854 0 File::Path::rmtree(\@dirs);
855  
856 0 chdir($base_dir);
857 0 my $resulting_par_file = Cwd::abs_path(blib_to_par());
858 0 chdir($old_cwd);
859 0 File::Copy::move($resulting_par_file, $par);
860  
861 0 File::Path::rmtree([$base_dir]);
862 }
863  
864  
865 =head2 get_meta
866  
867 Opens a PAR archive and extracts the contained META.yml file.
868 Returns the META.yml file as a string.
869  
870 Takes one named parameter: I<dist>. If only one parameter is
871 passed, it is treated as the I<dist> parameter. (Have a look
872 at the description in the C<FUNCTIONS> section above.)
873  
874 Returns undef if no PAR archive or no META.yml within the
875 archive were found.
876  
877 =cut
878  
879 0 ▶sub get_meta {
Subroutine get_meta: not called CC=5 SCAR=34.0
Pod documented
880 0 my %args = &_args;
881 0 my $dist = $args{dist};
882 0 ▶ return undef if not defined $dist or not -r $dist;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dist and -r $dist 0 0 0
Condition0%0/3
defined $dist and -r $dist
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dist and -r $dist
defined $dist -r $dist
Truth table0%0/3
A and B
A= defined $distB= -r $dist
ABresult
0X0
100
111
883 0 require Cwd;
884 0 require File::Path;
885  
886 # The unzipping will change directories. Remember old dir.
887 0 my $old_cwd = Cwd::cwd();
888  
889 # Unzip the base par to a temp. dir.
890 0 (undef, my $base_dir) = _unzip_to_tmpdir(
891 dist => $dist, subdir => 'blib'
892 );
893 0 my $blibdir = File::Spec->catdir($base_dir, 'blib');
894  
895 0 my $meta = File::Spec->catfile($blibdir, 'META.yml');
896  
897 0 ▶ if (not -r $meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $meta) 0 0 0
898 0 return undef;
899 }
900  
901 0 ▶ open FH, '<', $meta
Branch: 1 branch
BranchTrueFalseTotal
open FH, "<", $meta or die "Could not open file '${meta}' for reading: $!" 0 0 0
902 or die "Could not open file '$meta' for reading: $!";
903  
904 0 local $/ = undef;
905 0 my $meta_text = <FH>;
906 0 close FH;
907  
908 0 chdir($old_cwd);
909  
910 0 File::Path::rmtree([$base_dir]);
911  
912 0 return $meta_text;
913 }
914  
915  
916  
917 0 ▶sub _unzip {
Subroutine _unzip: not called CC=9 SCAR=45.0
918 0 my %args = &_args;
919 0 my $dist = $args{dist};
920 0 ▶ my $path = $args{path} || File::Spec->curdir;
Condition0%0/3
$args{'path'} || 'File::Spec'->curdir
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'path'} || 'File::Spec'->curdir
$args{'path'} 'File::Spec'->curdir
Truth table0%0/3
A || B
A= $args{'path'}B= 'File::Spec'->curdir
ABresult
1X1
011
000
921 0 ▶ return unless -f $dist;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $dist 0 0 0
922  
923 # Try fast unzipping first
924 0 ▶ if (eval { require Archive::Unzip::Burst; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Archive::Unzip::Burst; 1 } }) 0 0 0
925 0 my $return = !Archive::Unzip::Burst::unzip($dist, $path);
926 0 ▶ return if $return; # true return value == error (a la system call)
Branch: 1 branch
BranchTrueFalseTotal
if $return 0 0 0
927 }
928 # Then slow unzipping
929 0 ▶ if (eval { require Archive::Zip; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Archive::Zip; 1 } }) { } 0 0 0
930 0 my $zip = Archive::Zip->new;
931 0 local %SIG;
932 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
933 0 ▶ return unless $zip->read($dist) == Archive::Zip::AZ_OK()
Branch: 1 branch
BranchTrueFalseTotal
unless $zip->read($dist) == Archive::Zip::AZ_OK() and $zip->extractTree("", "$path/") == Archive::Zip::AZ_OK() 0 0 0
Condition0%0/3
$zip->read($dist) == Archive::Zip::AZ_OK() and $zip->extractTree("", "$path/") == Archive::Zip::AZ_OK()
!ll&&!rl&&r
000
MC/DC0%0/2
$zip->read($dist) == Archive::Zip::AZ_OK() and $zip->extractTree("", "$path/") == Archive::Zip::AZ_OK()
$zip->read($dist) == Archive::Zip::AZ_OK() $zip->extractTree("", "$path/") == Archive::Zip::AZ_OK()
Truth table0%0/3
A and B
A= $zip->read($dist) == Archive::Zip::AZ_OK()B= $zip->extractTree("", "$path/") == Archive::Zip::AZ_OK()
ABresult
0X0
100
111
934 and $zip->extractTree('', "$path/") == Archive::Zip::AZ_OK();
935 }
936 # Then fall back to the system
937 else {
938 0 undef $!;
939 0 ▶ if (_system_wrapper(unzip => $dist, '-d', $path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_system_wrapper("unzip", $dist, "-d", $path)) 0 0 0
940 0 die "Failed to unzip '$dist' to path '$path': Could neither load "
941 . "Archive::Zip nor (successfully) run the system 'unzip' (unzip said: $!)";
942 }
943 }
944  
945 0 return 1;
946 }
947  
948 0 ▶sub _zip {
Subroutine _zip: not called CC=4 SCAR=30.0
949 0 my %args = &_args;
950 0 my $dist = $args{dist};
951  
952 0 ▶ if (eval { require Archive::Zip; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Archive::Zip; 1 } }) { } 0 0 0
953 0 my $zip = Archive::Zip->new;
954 0 $zip->addTree( File::Spec->curdir, '' );
955 0 ▶ $zip->writeToFileNamed( $dist ) == Archive::Zip::AZ_OK() or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$zip->writeToFileNamed($dist) == Archive::Zip::AZ_OK() or die $! 0 0 0
956 }
957 else {
958 0 undef $!;
959 0 ▶ if (_system_wrapper(qw(zip -r), $dist, File::Spec->curdir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_system_wrapper(("zip", "-r"), $dist, "File::Spec"->curdir)) 0 0 0
960 0 die "Failed to zip '" .File::Spec->curdir(). "' to '$dist': Could neither load "
961 . "Archive::Zip nor (successfully) run the system 'zip' (zip said: $!)";
962 }
963 }
964 0 return 1;
965 }
966  
967  
968 # This sub munges the arguments to most of the PAR::Dist functions
969 # into a hash. On the way, it downloads PAR archives as necessary, etc.
970 0 ▶sub _args {
Subroutine _args: not called CC=11 SCAR=48.8
971 # default to the first .par in the CWD
972 0 ▶ if (not @_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
973 0 @_ = (glob('*.par'))[0];
974 }
975  
976 # single argument => it's a distribution file name or URL
977 0 ▶ @_ = (dist => @_) if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
978  
979 0 my %args = @_;
980 0 ▶ $args{name} ||= $args{dist};
Condition0%0/3
$args{"name"} ||= $args{"dist"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"name"} ||= $args{"dist"}
$args{"name"} $args{"dist"}
Truth table0%0/3
A ||= B
A= $args{"name"}B= $args{"dist"}
ABresult
1X1
011
000
981  
982 # If we are installing from an URL, we want to munge the
983 # distribution name so that it is in form "Module-Name"
984 0 ▶ if (defined $args{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"name"}) 0 0 0
985 0 $args{name} =~ s/^\w+:\/\///;
986 0 my @elems = parse_dist_name($args{name});
987 # @elems is name, version, arch, perlversion
988 0 ▶ if (defined $elems[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $elems[0]) { } 0 0 0
989 0 $args{name} = $elems[0];
990 }
991 else {
992 0 $args{name} =~ s/^.*\/([^\/]+)$/$1/;
993 0 $args{name} =~ s/^([0-9A-Za-z_-]+)-\d+\..+$/$1/;
994 }
995 }
996  
997 # append suffix if there is none
998 0 ▶ if ($args{dist} and not $args{dist} =~ /\.[a-zA-Z_][^.]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"dist"} and not $args{"dist"} =~ /\.[a-zA-Z_][^.]*$/) 0 0 0
Condition0%0/3
$args{"dist"} and not $args{"dist"} =~ /\.[a-zA-Z_][^.]*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"dist"} and not $args{"dist"} =~ /\.[a-zA-Z_][^.]*$/
$args{"dist"} not $args{"dist"} =~ /\.[a-zA-Z_][^.]*$/
Truth table0%0/3
A and not(B)
A= $args{"dist"}B= not $args{"dist"} =~ /\.[a-zA-Z_][^.]*$/
ABresult
0X0
100
111
999 0 require Config;
1000 0 my $suffix = $args{suffix};
1001 0 ▶ $suffix ||= "$Config::Config{archname}-$Config::Config{version}.par";
Condition0%0/2
$suffix ||= qq[$Config::Config{"archname"}-$Config::Config{"version"}.par]
l!l
00
MC/DC0%0/1
$suffix ||= qq[$Config::Config{"archname"}-$Config::Config{"version"}.par]
$suffix
Truth table0%0/2
A
A= $suffix
Aresult
11
00
1002 0 $args{dist} .= "-$suffix";
1003 }
1004  
1005 # download if it's an URL
1006 0 ▶ if ($args{dist} and $args{dist} =~ m!^\w+://!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"dist"} and $args{"dist"} =~ m[^\w+://]) 0 0 0
Condition0%0/3
$args{"dist"} and $args{"dist"} =~ m[^\w+://]
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"dist"} and $args{"dist"} =~ m[^\w+://]
$args{"dist"} $args{"dist"} =~ m[^\w+://]
Truth table0%0/3
A and B
A= $args{"dist"}B= $args{"dist"} =~ m[^\w+://]
ABresult
0X0
100
111
1007 $args{dist} = _fetch(dist => $args{dist})
1008 0 }
1009  
1010 0 return %args;
1011 }
1012  
1013  
1014 # Download PAR archive, but only if necessary (mirror!)
1015 3 my %escapes;
1016 0 ▶sub _fetch {
Subroutine _fetch: not called CC=8 SCAR=42.8
1017 0 my %args = @_;
1018  
1019 0 ▶ if ($args{dist} =~ s/^file:\/\///) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"dist"} =~ s[^file://][]) 0 0 0
1020 0 ▶ return $args{dist} if -e $args{dist};
Branch: 1 branch
BranchTrueFalseTotal
if -e $args{"dist"} 0 0 0
1021 0 return;
1022 }
1023 0 require LWP::Simple;
1024  
1025 0 ▶ $ENV{PAR_TEMP} ||= File::Spec->catdir(File::Spec->tmpdir, 'par');
Condition0%0/3
$ENV{"PAR_TEMP"} ||= "File::Spec"->catdir("File::Spec"->tmpdir, "par")
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"PAR_TEMP"} ||= "File::Spec"->catdir("File::Spec"->tmpdir, "par")
$ENV{"PAR_TEMP"} "File::Spec"->catdir("File::Spec"->tmpdir, "par")
Truth table0%0/3
A ||= B
A= $ENV{"PAR_TEMP"}B= "File::Spec"->catdir("File::Spec"->tmpdir, "par")
ABresult
1X1
011
000
1026 0 mkdir $ENV{PAR_TEMP}, 0777;
1027 0 ▶ %escapes = map { chr($_) => sprintf("%%%02X", $_) } 0..255 unless %escapes;
Branch: 1 branch
BranchTrueFalseTotal
unless %escapes 0 0 0
1028  
1029 0 $args{dist} =~ s{^cpan://((([a-zA-Z])[a-zA-Z])[-_a-zA-Z]+)/}
1030 {http://www.cpan.org/modules/by-authors/id/\U$3/$2/$1\E/};
1031  
1032 0 my $file = $args{dist};
1033 0 $file =~ s/([^\w\.])/$escapes{$1}/g;
1034 0 $file = File::Spec->catfile( $ENV{PAR_TEMP}, $file);
1035 0 my $rc = LWP::Simple::mirror( $args{dist}, $file );
1036  
1037 0 ▶ if (!LWP::Simple::is_success($rc) and $rc != 304) {
Branch: 1 branch
BranchTrueFalseTotal
if (not LWP::Simple::is_success($rc) and $rc != 304) 0 0 0
Condition0%0/3
not LWP::Simple::is_success($rc) and $rc != 304
!ll&&!rl&&r
000
MC/DC0%0/2
not LWP::Simple::is_success($rc) and $rc != 304
not LWP::Simple::is_success($rc) $rc != 304
Truth table0%0/3
not(A) and B
A= not LWP::Simple::is_success($rc)B= $rc != 304
ABresult
0X0
100
111
1038 0 die "Error $rc: ", LWP::Simple::status_message($rc), " ($args{dist})\n";
1039 }
1040  
1041 0 ▶ return $file if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 0 0 0
1042 0 return;
1043 }
1044  
1045 0 ▶sub _verify_or_sign {
Subroutine _verify_or_sign: not called CC=12 SCAR=50.5
1046 0 my %args = &_args;
1047  
1048 0 require File::Path;
1049 0 require Module::Signature;
1050 0 ▶ die "Module::Signature version 0.25 required"
Branch: 1 branch
BranchTrueFalseTotal
unless "Module::Signature"->VERSION >= "0.25" 0 0 0
1051 unless Module::Signature->VERSION >= 0.25;
1052  
1053 0 require Cwd;
1054 0 my $cwd = Cwd::cwd();
1055 0 my $action = $args{action};
1056 0 my ($dist, $tmpdir) = _unzip_to_tmpdir($args{dist});
1057 0 ▶ $action ||= (-e 'SIGNATURE' ? 'verify' : 'sign');
Branch: 1 branch
BranchTrueFalseTotal
-e 'SIGNATURE' ? : 0 0 0
Condition0%0/3
$action ||= -e "SIGNATURE" ? "verify" : "sign"
l!l&&r!l&&!r
000
MC/DC0%0/2
$action ||= -e "SIGNATURE" ? "verify" : "sign"
$action -e "SIGNATURE" ? "verify" : "sign"
Truth table0%0/3
A ||= B
A= $actionB= -e "SIGNATURE" ? "verify" : "sign"
ABresult
1X1
011
000
1058  
1059 0 ▶ if ($action eq 'sign') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "sign") 0 0 0
1060 0 ▶ open FH, '>SIGNATURE' unless -e 'SIGNATURE';
Branch: 1 branch
BranchTrueFalseTotal
unless -e "SIGNATURE" 0 0 0
1061 0 ▶ open FH, 'MANIFEST' or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open FH, "MANIFEST" or die $! 0 0 0
1062  
1063 0 local $/;
1064 0 my $out = <FH>;
1065 0 ▶ if ($out !~ /^SIGNATURE(?:\s|$)/m) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($out =~ /^SIGNATURE(?:\s|$)/m) 0 0 0
1066 0 $out =~ s/^(?!\s)/SIGNATURE\n/m;
1067 0 ▶ open FH, '>MANIFEST' or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open FH, ">MANIFEST" or die $! 0 0 0
1068 0 print FH $out;
1069 }
1070 0 close FH;
1071  
1072 0 ▶ $args{overwrite} = 1 unless exists $args{overwrite};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"overwrite"} 0 0 0
1073 0 ▶ $args{skip} = 0 unless exists $args{skip};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"skip"} 0 0 0
1074 }
1075  
1076 0 my $rv = Module::Signature->can($action)->(%args);
1077 0 ▶ _zip(dist => $dist) if $action eq 'sign';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "sign" 0 0 0
1078 0 File::Path::rmtree([$tmpdir]);
1079  
1080 0 chdir($cwd);
1081 0 return $rv;
1082 }
1083  
1084 0 ▶sub _unzip_to_tmpdir {
Subroutine _unzip_to_tmpdir: not called CC=3 SCAR=24.8
1085 0 my %args = &_args;
1086  
1087 0 require File::Temp;
1088 0 require Cwd;
1089  
1090 0 my $dist = File::Spec->rel2abs($args{dist});
1091 0 ▶ my $tmpdir = File::Temp::tempdir("parXXXXX", TMPDIR => 1, CLEANUP => 1)
Branch: 1 branch
BranchTrueFalseTotal
my $tmpdir = File::Temp::tempdir("parXXXXX", "TMPDIR", 1, "CLEANUP", 1) or die "Could not create temporary directory: $!" 0 0 0
1092 or die "Could not create temporary directory: $!";
1093 0 $tmpdir = Cwd::abs_path($tmpdir); # symlinks cause Archive::Zip issues on some systems
1094 0 my $path = $tmpdir;
1095 0 ▶ $path = File::Spec->catdir($tmpdir, $args{subdir}) if defined $args{subdir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"subdir"} 0 0 0
1096  
1097 0 _unzip(dist => $dist, path => $path);
1098  
1099 0 chdir $tmpdir;
1100 0 return ($dist, $tmpdir);
1101 }
1102  
1103  
1104  
1105 =head2 parse_dist_name
1106  
1107 First argument must be a distribution file name. The file name
1108 is parsed into I<distribution name>, I<distribution version>,
1109 I<architecture name>, and I<perl version>.
1110  
1111 Returns the results as a list in the above order.
1112 If any or all of the above cannot be determined, returns undef instead
1113 of the undetermined elements.
1114  
1115 Supported formats are:
1116  
1117 Math-Symbolic-0.502-x86_64-linux-gnu-thread-multi-5.8.7
1118  
1119 Math-Symbolic-0.502
1120  
1121 The ".tar.gz" or ".par" extensions as well as any
1122 preceding paths are stripped before parsing. Starting with C<PAR::Dist>
1123 0.22, versions containing a preceding C<v> are parsed correctly.
1124  
1125 This function is not exported by default.
1126  
1127 =cut
1128  
1129 5 ▶sub parse_dist_name {
Subroutine parse_dist_name: called CC=11 SCAR=24.1
Pod documented
1130 5 my $file = shift;
1131 5 ▶ return(undef, undef, undef, undef) if not defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 5 5
1132  
1133 5 (undef, undef, $file) = File::Spec->splitpath($file);
1134  
1135 5 my $version = qr/v?(?:\d+(?:_\d+)?|\d*(?:\.\d+(?:_\d+)?)+)/;
1136 5 $file =~ s/\.(?:par|tar\.gz|tar)$//i;
1137 5 my @elem = split /-/, $file;
1138 5 my (@dn, $dv, @arch, $pv);
1139 5 ▶ while (@elem) {
Branch: 1 branch
BranchTrueFalseTotal
if (@elem) 14 0 14
1140 14 my $e = shift @elem;
1141 14 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /^$version$/o and not @elem && $elem[0] =~ /^$version$/o) 5 9 14
Condition100%6/6
$e =~ /^$version$/o and not @elem && $elem[0] =~ /^$version$/o
!ll&&!rl&&r
815
@elem && $elem[0] =~ /^$version$/o
!ll&&!rl&&r
141
MC/DC100%3/3
$e =~ /^$version$/o and not @elem && $elem[0] =~ /^$version$/o
$e =~ /^$version$/o @elem $elem[0] =~ /^$version$/o
Truth table100%4/4
A and not(B && C)
A= $e =~ /^$version$/oB= @elemC= $elem[0] =~ /^$version$/o
ABCresult
0XX0
1110
10X1
1101
1142 $e =~ /^$version$/o
1143 and not(# if not next token also a version
1144 # (assumes an arch string doesnt start with a version...)
1145 @elem and $elem[0] =~ /^$version$/o
1146 )
1147 ) {
1148 5 $dv = $e;
1149 5 last;
1150 }
1151 9 push @dn, $e;
1152 }
1153  
1154 5 my $dn;
1155 5 ▶ $dn = join('-', @dn) if @dn;
Branch: 1 branch
BranchTrueFalseTotal
if @dn 5 0 5
1156  
1157 5 ▶ if (not @elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@elem) 1 4 5
1158 1 return( $dn, $dv, undef, undef);
1159 }
1160  
1161 4 ▶ while (@elem) {
Branch: 1 branch
BranchTrueFalseTotal
if (@elem) 21 0 21
1162 21 my $e = shift @elem;
1163 21 ▶ if ($e =~ /^(?:$version|any_version)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /^(?:$version|any_version)$/) 4 17 21
1164 4 $pv = $e;
1165 4 last;
1166 }
1167 17 push @arch, $e;
1168 }
1169  
1170 4 my $arch;
1171 4 ▶ $arch = join('-', @arch) if @arch;
Branch: 1 branch
BranchTrueFalseTotal
if @arch 4 0 4
1172  
1173 4 return($dn, $dv, $arch, $pv);
1174 }
1175  
1176 =head2 generate_blib_stub
1177  
1178 Creates a F<blib/lib> subdirectory in the current directory
1179 and prepares a F<META.yml> with meta information for a
1180 new PAR distribution. First argument should be the name of the
1181 PAR distribution in a format understood by C<parse_dist_name()>.
1182 Alternatively, named arguments resembling those of
1183 C<blib_to_par> are accepted.
1184  
1185 After running C<generate_blib_stub> and injecting files into
1186 the F<blib> directory, you can create a PAR distribution
1187 using C<blib_to_par>.
1188 This function is useful for creating custom PAR distributions
1189 from scratch. (I.e. not from an unpacked CPAN distribution)
1190 Example:
1191  
1192 use PAR::Dist;
1193 use File::Copy 'copy';
1194  
1195 generate_blib_stub(
1196 name => 'MyApp', version => '1.00'
1197 );
1198 copy('MyApp.pm', 'blib/lib/MyApp.pm');
1199 blib_to_par(); # generates the .par file!
1200  
1201 C<generate_blib_stub> will not overwrite existing files.
1202  
1203 =cut
1204  
1205 0 ▶sub generate_blib_stub {
Subroutine generate_blib_stub: not called CC=12 SCAR=50.5
Pod documented
1206 0 my %args = &_args;
1207 0 my $dist = $args{dist};
1208 0 require Config;
1209  
1210 0 my $name = $args{name};
1211 0 my $version = $args{version};
1212 0 my $suffix = $args{suffix};
1213  
1214 0 my ($parse_name, $parse_version, $archname, $perlversion)
1215 = parse_dist_name($dist);
1216  
1217 0 ▶ $name ||= $parse_name;
Condition0%0/3
$name ||= $parse_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= $parse_name
$name $parse_name
Truth table0%0/3
A ||= B
A= $nameB= $parse_name
ABresult
1X1
011
000
1218 0 ▶ $version ||= $parse_version;
Condition0%0/3
$version ||= $parse_version
l!l&&r!l&&!r
000
MC/DC0%0/2
$version ||= $parse_version
$version $parse_version
Truth table0%0/3
A ||= B
A= $versionB= $parse_version
ABresult
1X1
011
000
1219 0 ▶ $suffix = "$archname-$perlversion"
Branch: 1 branch
BranchTrueFalseTotal
if !defined($suffix) || $suffix eq "" and $archname and $perlversion 0 0 0
Condition0%0/9
!defined($suffix) || $suffix eq "" and $archname and $perlversion
!ll&&!rl&&r
000
!defined($suffix) || $suffix eq "" and $archname
!ll&&!rl&&r
000
not defined $suffix or $suffix eq ""
l!l&&r!l&&!r
000
MC/DC0%0/4
!defined($suffix) || $suffix eq "" and $archname and $perlversion
not defined $suffix $suffix eq "" $archname $perlversion
Truth table0%0/7
not(A) or B and C and D
A= not defined $suffixB= $suffix eq ""C= $archnameD= $perlversion
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
1220 if (not defined $suffix or $suffix eq '')
1221 and $archname and $perlversion;
1222  
1223 0 ▶ $suffix ||= "$Config::Config{archname}-$Config::Config{version}";
Condition0%0/2
$suffix ||= qq[$Config::Config{"archname"}-$Config::Config{"version"}]
l!l
00
MC/DC0%0/1
$suffix ||= qq[$Config::Config{"archname"}-$Config::Config{"version"}]
$suffix
Truth table0%0/2
A
A= $suffix
Aresult
11
00
1224 0 ▶ if ( grep { not defined $_ } ($name, $version, $suffix) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not defined $_;} $name, $version, $suffix) 0 0 0
1225 0 warn "Could not determine distribution meta information from distribution name '$dist'";
1226 0 return();
1227 }
1228 0 $suffix =~ s/\.par$//;
1229  
1230 0 ▶ if (not -f 'META.yml') {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "META.yml") 0 0 0
1231 0 ▶ open META, '>', 'META.yml'
Branch: 1 branch
BranchTrueFalseTotal
open META, ">", "META.yml" or die "Could not open META.yml file for writing: $!" 0 0 0
1232 or die "Could not open META.yml file for writing: $!";
1233 0 ▶ print META << "YAML" if fileno(META);
Branch: 1 branch
BranchTrueFalseTotal
if fileno META 0 0 0
1234 name: $name
1235 version: '$version'
1236 build_requires: {}
1237 conflicts: {}
1238 dist_name: $name-$version-$suffix.par
1239 distribution_type: par
1240 dynamic_config: 0
1241 generated_by: 'PAR::Dist version $PAR::Dist::VERSION'
1242 license: unknown
1243 YAML
1244 0 close META;
1245 }
1246  
1247 0 mkdir('blib');
1248 0 mkdir(File::Spec->catdir('blib', 'lib'));
1249 0 mkdir(File::Spec->catdir('blib', 'script'));
1250  
1251 0 return 1;
1252 }
1253  
1254  
1255 =head2 contains_binaries
1256  
1257 This function is not exported by default.
1258  
1259 Opens a PAR archive tries to determine whether that archive
1260 contains platform-specific binary code.
1261  
1262 Takes one named parameter: I<dist>. If only one parameter is
1263 passed, it is treated as the I<dist> parameter. (Have a look
1264 at the description in the C<FUNCTIONS> section above.)
1265  
1266 Throws a fatal error if the PAR archive could not be found.
1267  
1268 Returns one if the PAR was found to contain binary code
1269 and zero otherwise.
1270  
1271 =cut
1272  
1273 0 ▶sub contains_binaries {
Subroutine contains_binaries: not called CC=4 SCAR=30.0
Pod documented
1274 0 require File::Find;
1275 0 my %args = &_args;
1276 0 my $dist = $args{dist};
1277 0 ▶ return undef if not defined $dist or not -r $dist;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dist and -r $dist 0 0 0
Condition0%0/3
defined $dist and -r $dist
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dist and -r $dist
defined $dist -r $dist
Truth table0%0/3
A and B
A= defined $distB= -r $dist
ABresult
0X0
100
111
1278 0 require Cwd;
1279 0 require File::Path;
1280  
1281 # The unzipping will change directories. Remember old dir.
1282 0 my $old_cwd = Cwd::cwd();
1283  
1284 # Unzip the base par to a temp. dir.
1285 0 (undef, my $base_dir) = _unzip_to_tmpdir(
1286 dist => $dist, subdir => 'blib'
1287 );
1288 0 my $blibdir = File::Spec->catdir($base_dir, 'blib');
1289 0 my $archdir = File::Spec->catdir($blibdir, 'arch');
1290  
1291 0 my $found = 0;
1292  
1293 File::Find::find(
1294 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1295 0 ▶ $found++ if -f $_ and not /^\.exists$/;
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ and not /^\.exists$/ 0 0 0
Condition0%0/3
-f $_ and not /^\.exists$/
!ll&&!rl&&r
000
MC/DC0%0/2
-f $_ and not /^\.exists$/
-f $_ not /^\.exists$/
Truth table0%0/3
A and not(B)
A= -f $_B= not /^\.exists$/
ABresult
0X0
100
111
1296 },
1297 0 $archdir
1298 );
1299  
1300 0 chdir($old_cwd);
1301  
1302 0 File::Path::rmtree([$base_dir]);
1303  
1304 0 ▶ return $found ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 0 0 0
1305 }
1306  
1307 0 ▶sub _system_wrapper {
Subroutine _system_wrapper: not called CC=2 SCAR=17.9
1308 0 ▶ if ($DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PAR::Dist::DEBUG) 0 0 0
1309 0 Carp::cluck("Running system call '@_' from:");
1310 }
1311 0 return system(@_);
1312 }
1313  
1314 # stolen from Module::Install::Can
1315 # very much internal and subject to change or removal
1316 1 ▶sub _MI_can_run {
Subroutine _MI_can_run: called CC=6 SCAR=19.9
1317 1 require ExtUtils::MakeMaker;
1318 1 my ($cmd) = @_;
1319  
1320 1 my $_cmd = $cmd;
1321 1 ▶ return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
Branch: 1 branch
BranchTrueFalseTotal
if -x $_cmd or $_cmd = "MM"->maybe_command($_cmd) 0 1 1
Condition33%1/3
-x $_cmd or $_cmd = "MM"->maybe_command($_cmd)
l!l&&r!l&&!r
001
MC/DC0%0/2
-x $_cmd or $_cmd = "MM"->maybe_command($_cmd)
-x $_cmd $_cmd = "MM"->maybe_command($_cmd)
Truth table33%1/3
A or B
A= -x $_cmdB= $_cmd = "MM"->maybe_command($_cmd)
ABresult
1X1
011
000
1322  
1323 1 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
1324 11 my $abs = File::Spec->catfile($dir, $cmd);
1325 11 ▶ return $abs if (-x $abs or $abs = MM->maybe_command($abs));
Branch: 1 branch
BranchTrueFalseTotal
if -x $abs or $abs = "MM"->maybe_command($abs) 0 11 11
Condition33%1/3
-x $abs or $abs = "MM"->maybe_command($abs)
l!l&&r!l&&!r
0011
MC/DC0%0/2
-x $abs or $abs = "MM"->maybe_command($abs)
-x $abs $abs = "MM"->maybe_command($abs)
Truth table33%1/3
A or B
A= -x $absB= $abs = "MM"->maybe_command($abs)
ABresult
1X1
011
000
1326 }
1327  
1328 1 return;
1329 }
1330  
1331  
1332 # Tries to load any YAML reader writer I know of
1333 # returns nothing on failure or hash reference containing
1334 # a subset of Load, Dump, LoadFile, DumpFile
1335 # entries with sub references on success.
1336 1 ▶sub _get_yaml_functions {
Subroutine _get_yaml_functions: called CC=8 SCAR=21.4
1337 # reasoning for the ranking here:
1338 # - XS is the de-facto standard nowadays.
1339 # - YAML.pm is slow and aging
1340 # - syck is fast and reasonably complete
1341 # - Tiny is only a very small subset
1342 # - Parse... is only a reader and only deals with the same subset as ::Tiny
1343 1 my @modules = qw(YAML::XS YAML YAML::Tiny YAML::Syck Parse::CPAN::Meta);
1344  
1345 1 my %yaml_functions;
1346 1 foreach my $module (@modules) {
1347 2 eval "require $module;";
1348 2 ▶ if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 1 1 2
1349 1 ▶ warn "PAR::Dist testers/debug info: Using '$module' as YAML implementation" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PAR::Dist::DEBUG 1 0 1
1350 1 foreach my $sub (qw(Load Dump LoadFile DumpFile)) {
1351 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1352 4 my $subref = *{"${module}::$sub"}{CODE};
1353 4 ▶ if (defined $subref and ref($subref) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subref and ref $subref eq "CODE") 4 0 4
Condition33%1/3
defined $subref and ref $subref eq "CODE"
!ll&&!rl&&r
004
MC/DC0%0/2
defined $subref and ref $subref eq "CODE"
defined $subref ref $subref eq "CODE"
Truth table33%1/3
A and B
A= defined $subrefB= ref $subref eq "CODE"
ABresult
0X0
100
111
1354 4 $yaml_functions{$sub} = $subref;
1355 }
1356 }
1357 1 $yaml_functions{yaml_provider} = $module;
1358 1 last;
1359 }
1360 } # end foreach module candidates
1361 1 ▶ if (not keys %yaml_functions) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %yaml_functions) 0 1 1
1362 0 warn "Cannot find a working YAML reader/writer implementation. Tried to load all of '@modules'";
1363 }
1364 1 return(\%yaml_functions);
1365 }
1366  
1367 1 ▶sub _check_tools {
Subroutine _check_tools: called CC=11 SCAR=33.1
1368 1 my $tools = _get_yaml_functions();
1369 1 ▶ if ($DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PAR::Dist::DEBUG) 1 0 1
1370 1 foreach (qw/Load Dump LoadFile DumpFile/) {
1371 4 ▶ warn "No YAML support for $_ found.\n" if not defined $tools->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tools->{$_} 0 4 4
1372 }
1373 }
1374  
1375 1 $tools->{zip} = undef;
1376 # A::Zip 1.28 was a broken release...
1377 0 ▶ if (eval {require Archive::Zip; 1;} and $Archive::Zip::VERSION ne '1.28') {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require Archive::Zip; 1 } } and $Archive::Zip::VERSION ne '1.28') { } 0 1 1
elsif (_MI_can_run('zip') and _MI_can_run('unzip')) { } 0 1 1
Condition33%1/3
eval { do { require Archive::Zip; 1 } } and $Archive::Zip::VERSION ne "1.28"
!ll&&!rl&&r
100
MC/DC0%0/2
eval { do { require Archive::Zip; 1 } } and $Archive::Zip::VERSION ne "1.28"
eval { do { require Archive::Zip; 1 } } $Archive::Zip::VERSION ne "1.28"
Truth table33%1/3
A and B
A= eval { do { require Archive::Zip; 1 } }B= $Archive::Zip::VERSION ne "1.28"
ABresult
0X0
100
111
1378 0 ▶ warn "Using Archive::Zip as ZIP tool.\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PAR::Dist::DEBUG 0 0 0
1379 0 $tools->{zip} = 'Archive::Zip';
1380 }
1381 ▶ elsif (_MI_can_run("zip") and _MI_can_run("unzip")) {
Condition33%1/3
_MI_can_run("zip") and _MI_can_run("unzip")
!ll&&!rl&&r
100
MC/DC0%0/2
_MI_can_run("zip") and _MI_can_run("unzip")
_MI_can_run("zip") _MI_can_run("unzip")
Truth table33%1/3
A and B
A= _MI_can_run("zip")B= _MI_can_run("unzip")
ABresult
0X0
100
111
1382 0 ▶ warn "Using zip/unzip as ZIP tool.\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PAR::Dist::DEBUG 0 0 0
1383 0 $tools->{zip} = 'zip';
1384 }
1385 else {
1386 1 ▶ warn "Found neither Archive::Zip (version != 1.28) nor ZIP/UNZIP as valid ZIP tools.\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PAR::Dist::DEBUG 1 0 1
1387 1 $tools->{zip} = undef;
1388 }
1389  
1390 1 return $tools;
1391 }
1392  
1393 3 1;
1394  
1395 =head1 SEE ALSO
1396  
1397 L<PAR>, L<ExtUtils::Install>, L<Module::Signature>, L<LWP::Simple>
1398  
1399 =head1 AUTHORS
1400  
1401 Audrey Tang E<lt>cpan@audreyt.orgE<gt> 2003-2007
1402  
1403 Steffen Mueller E<lt>smueller@cpan.orgE<gt> 2005-2011
1404  
1405 PAR has a mailing list, E<lt>par@perl.orgE<gt>, that you can write to;
1406 send an empty mail to E<lt>par-subscribe@perl.orgE<gt> to join the list
1407 and participate in the discussion.
1408 Archives of the mailing list are available at
1409 E<lt>https://www.mail-archive.com/par@perl.org/E<gt> or E<lt>https://groups.google.com/g/perl.parE<gt>.
1410  
1411 Please send bug reports to E<lt>https://github.com/rschupp/PAR-Dist/issuesE<gt>.
1412  
1413 =head1 COPYRIGHT
1414  
1415 Copyright 2003-2011 by Audrey Tang E<lt>autrijus@autrijus.orgE<gt>.
1416  
1417 This program is free software; you can redistribute it and/or modify it
1418 under the same terms as Perl itself.
1419  
1420 See L<http://www.perl.com/perl/misc/Artistic.html>
1421  
1422 =cut
↑ Summary