blib/lib/PAR/Dist.pm

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