PAR.pm

filter: Statementstmt 60.6% 264 / 435 Branchbran 37.8% 81 / 214 Conditioncond 29.5% 31 / 105 MC/DCmcdc 6.6% 4 / 60 Subroutinesub 78.4% 40 / 51 Podpod 0.0% 0 / 6 totaltotal 48.2% 420 / 871 SCAR 81.5
CC
162
Cov
50%
unpar
215.0
_import_repository
156.0
import
96.8
CRAP 3468.7
↑ Summary PAR/Heavy.pm »
1 package PAR;
2 $PAR::VERSION = '1.018';
3  
4 8 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # If the 'prefork' module is available, we
11 # register various run-time loaded modules with it.
12 # That way, there is more shared memory in a forking
13 # environment.
14 BEGIN {
15 4 ▶ if (eval 'require prefork') {
Subroutine BEGIN: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require prefork") 0 4 4
16 0 prefork->import($_) for qw/
17 Archive::Zip
18 File::Glob
19 File::Spec
20 File::Temp
21 Fcntl
22 LWP::Simple
23 PAR::Heavy
24 /;
25 # not including Archive::Unzip::Burst which only makes sense
26 # in the context of a PAR::Packer'ed executable anyway.
27 }
28 }
29  
30 4 ▶use PAR::SetupProgname;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 4 ▶use PAR::SetupTemp;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 =head1 NAME
34  
35 PAR - Perl Archive Toolkit
36  
37 =head1 SYNOPSIS
38  
39 (If you want to make an executable that contains all module, scripts and
40 data files, please consult the L<pp> utility instead. L<pp> used to be
41 part of the PAR distribution but is now shipped as part of the L<PAR::Packer>
42 distribution instead.)
43  
44 Following examples assume a F<foo.par> file in Zip format.
45  
46 To use F<Hello.pm> from F<./foo.par>:
47  
48 % perl -MPAR=./foo.par -MHello
49 % perl -MPAR=./foo -MHello # the .par part is optional
50  
51 Same thing, but search F<foo.par> in C<@INC>:
52  
53 % perl -MPAR -Ifoo.par -MHello
54 % perl -MPAR -Ifoo -MHello # ditto
55  
56 Following paths inside the PAR file are searched:
57  
58 /lib/
59 /arch/
60 /i386-freebsd/ # i.e. $Config{archname}
61 /5.8.0/ # i.e. $Config{version}
62 /5.8.0/i386-freebsd/ # both of the above
63 /
64  
65 PAR files may also (recursively) contain other PAR files.
66 All files under following paths will be considered as PAR
67 files and searched as well:
68  
69 /par/i386-freebsd/ # i.e. $Config{archname}
70 /par/5.8.0/ # i.e. $Config{version}
71 /par/5.8.0/i386-freebsd/ # both of the above
72 /par/
73  
74 Run F<script/test.pl> or F<test.pl> from F<foo.par>:
75  
76 % perl -MPAR foo.par test.pl # only when $0 ends in '.par'
77  
78 However, if the F<.par> archive contains either F<script/main.pl> or
79 F<main.pl>, then it is used instead:
80  
81 % perl -MPAR foo.par test.pl # runs main.pl; @ARGV is 'test.pl'
82  
83 Use in a program:
84  
85 use PAR 'foo.par';
86 use Hello; # reads within foo.par
87  
88 # PAR::read_file() returns a file inside any loaded PARs
89 my $conf = PAR::read_file('data/MyConfig.yaml');
90  
91 # PAR::par_handle() returns an Archive::Zip handle
92 my $zip = PAR::par_handle('foo.par')
93 my $src = $zip->memberNamed('lib/Hello.pm')->contents;
94  
95 You can also use wildcard characters:
96  
97 use PAR '/home/foo/*.par'; # loads all PAR files in that directory
98  
99 Since version 0.950, you can also use a different syntax for loading
100 F<.par> archives:
101  
102 use PAR { file => 'foo.par' }, { file => 'otherfile.par' };
103  
104 Why? Because you can also do this:
105  
106 use PAR { file => 'foo.par, fallback => 1 };
107 use Foo::Bar;
108  
109 Foo::Bar will be searched in the system libs first and loaded from F<foo.par>
110 if it wasn't found!
111  
112 use PAR { file => 'foo.par', run => 'myscript' };
113  
114 This will load F<foo.par> as usual and then execute the F<script/myscript>
115 file from the archive. Note that your program will not regain control. When
116 F<script/myscript> exits, so does your main program. To make this more useful,
117 you can defer this to runtime: (otherwise equivalent)
118  
119 require PAR;
120 PAR->import( { file => 'foo.par', run => 'myscript' } );
121  
122 If you have L<PAR::Repository::Client> installed, you can do this:
123  
124 use PAR { repository => 'http://foo/bar/' };
125 use Module; # not locally installed!
126  
127 And PAR will fetch any modules you don't have from the specified PAR
128 repository. For details on how this works, have a look at the SEE ALSO
129 section below. Instead of an URL or local path, you can construct an
130 L<PAR::Repository::Client> object manually and pass that to PAR.
131 If you specify the C<install =E<gt> 1> option in the C<use PAR>
132 line above, the distribution containing C<Module> will be permanently
133 installed on your system. (C<use PAR { repository =E<gt> 'http://foo/bar', install =E<gt> 1 };>)
134  
135 Furthermore, there is an C<upgrade =E<gt> 1> option that checks for upgrades
136 in the repository in addition to installing. Please note that an upgraded
137 version of a module is only loaded on the next run of your application.
138  
139 Adding the C<dependencies =E<gt> 1> option will enable PAR::Repository::Client's
140 static dependency resolution (PAR::Repository::Client 0.23 and up).
141  
142 Finally, you can combine the C<run> and C<repository>
143 options to run an application directly from a repository! (And you can add
144 the C<install> option, too.)
145  
146 use PAR { repository => 'http://foo/bar/', run => 'my_app' };
147 # Will not reach this point as we executed my_app,
148  
149 =head1 DESCRIPTION
150  
151 This module lets you use special zip files, called B<P>erl B<Ar>chives, as
152 libraries from which Perl modules can be loaded.
153  
154 It supports loading XS modules by overriding B<DynaLoader> bootstrapping
155 methods; it writes shared object file to a temporary file at the time it
156 is needed.
157  
158 A F<.par> file is mostly a zip of the F<blib/> directory after the build
159 process of a CPAN distribution. To generate a F<.par> file yourself, all
160 you have to do is compress the modules under F<arch/> and F<lib/>, e.g.:
161  
162 % perl Makefile.PL
163 % make
164 % cd blib
165 % zip -r mymodule.par arch/ lib/
166  
167 Afterward, you can just use F<mymodule.par> anywhere in your C<@INC>,
168 use B<PAR>, and it will Just Work. Support for generating F<.par> files
169 is going to be in the next (beyond 0.2805) release of Module::Build.
170  
171 For convenience, you can set the C<PERL5OPT> environment variable to
172 C<-MPAR> to enable C<PAR> processing globally (the overhead is small
173 if not used); setting it to C<-MPAR=/path/to/mylib.par> will load a
174 specific PAR file. Alternatively, consider using the F<par.pl> utility
175 bundled with the L<PAR::Packer> distribution, or using the
176 self-contained F<parl> utility which is also distributed with L<PAR::Packer>
177 on machines without PAR.pm installed.
178  
179 Note that self-containing scripts and executables created with F<par.pl>
180 and F<pp> may also be used as F<.par> archives:
181  
182 % pp -o packed.exe source.pl # generate packed.exe (see PAR::Packer)
183 % perl -MPAR=packed.exe other.pl # this also works
184 % perl -MPAR -Ipacked.exe other.pl # ditto
185  
186 Please see L</SYNOPSIS> for most typical use cases.
187  
188 =head1 NOTES
189  
190 Settings in F<META.yml> packed inside the PAR file may affect PAR's
191 operation. For example, F<pp> provides the C<-C> (C<--clean>) option
192 to control the default behavior of temporary file creation.
193  
194 Currently, F<pp>-generated PAR files may attach four PAR-specific
195 attributes in F<META.yml>:
196  
197 par:
198 clean: 0 # default value of PAR_CLEAN
199 signature: '' # key ID of the SIGNATURE file
200 verbatim: 0 # was packed prerequisite's PODs preserved?
201 version: x.xx # PAR.pm version that generated this PAR
202  
203 User-defined environment variables, like I<PAR_GLOBAL_CLEAN>, always
204 overrides the ones set in F<META.yml>. The algorithm for generating
205 caching/temporary directory is as follows:
206  
207 =over 4
208  
209 =item *
210  
211 If I<PAR_GLOBAL_TEMP> is specified, use it as the cache directory for
212 extracted libraries, and do not clean it up after execution.
213  
214 =item *
215  
216 If I<PAR_GLOBAL_TEMP> is not set, but I<PAR_GLOBAL_CLEAN> is specified, set
217 I<PAR_GLOBAL_TEMP> to C<I<TEMP>/par-I<USERHEX>/temp-I<PID>/>, cleaning it
218 after execution.
219  
220 =item *
221  
222 If both are not set, use C<I<TEMP>/par-I<USERHEX>/cache-I<HASH>/> as the
223 I<PAR_GLOBAL_TEMP>, reusing any existing files inside.
224  
225 =back
226  
227 Here is a description of the variables the previous paths.
228  
229 =over 4
230  
231 =item *
232  
233 I<TEMP> is a temporary directory, which can be set via
234 C<$ENV{PAR_GLOBAL_TMPDIR}>,
235 C<$ENV{TMPDIR}>, C<$ENV{TEMPDIR}>, C<$ENV{TEMP}>
236 or C<$ENV{TMP}>, in that order of priority.
237 If none of those are set, I<C:\TEMP>, I</tmp> are checked. If neither
238 of them exists, I<.> is used.
239  
240 =item *
241  
242 I<USERHEX> is derived from the user name, or SYSTEM if none can be found.
243 On Win32, this is C<$Win32::LoginName>.
244 On Unix, this is C<$ENV{USERNAME}> or C<$ENV{USER}>.
245 Encode the raw bytes of the user name each as two hex digits
246 to obtain I<USERHEX>.
247  
248 =item *
249  
250 I<PID> is the process ID. Forked children use the parent's PID.
251  
252 =item *
253  
254 I<HASH> is a crypto-hash of the entire par file or executable,
255 calculated at creation time. This value can be overloaded with C<pp>'s
256 --tempdir parameter.
257  
258 =back
259  
260 By default, PAR strips POD sections from bundled modules. In case
261 that causes trouble, you can turn this off by setting the
262 environment variable C<PAR_VERBATIM> to C<1>.
263  
264 =head2 import options
265  
266 When you "use PAR {...}" or call PAR->import({...}), the following
267 options are available.
268  
269 PAR->import({ file => 'foo.par' });
270 # or
271 PAR->import({ repository => 'http://foo/bar/' });
272  
273 =over
274  
275 =item file
276  
277 The par filename.
278  
279 You must pass I<one> option of either 'file' or 'repository'.
280  
281 =item repository
282  
283 A par repository (exclusive of file)
284  
285 =item fallback
286  
287 Search the system C<@INC> before the par.
288  
289 Off by default for loading F<.par> files via C<file => ...>.
290 On by default for PAR repositories.
291  
292 To prefer loading modules from a repository over the locally
293 installed modules, you can load the repository as follows:
294  
295 use PAR { repository => 'http://foo/bar/', fallback => 0 };
296  
297 =item run
298  
299 The name of a script to run in the par. Exits when done.
300  
301 =item no_shlib_unpack
302  
303 Skip unpacking bundled dynamic libraries from shlib/$archname. The
304 client may have them installed, or you may wish to cache them yourself.
305 In either case, they must end up in the standard install location (such
306 as /usr/local/lib/) or in $ENV{PAR_TEMP} I<before> you require the
307 module which needs them. If they are not accessible before you require
308 the dependent module, perl will die with a message such as "cannot open
309 shared object file..."
310  
311 =back
312  
313 =cut
314  
315 4 ▶use Fcntl ':flock';
Subroutine BEGIN: called CC=1 SCAR=0.0
316 4 ▶use Archive::Zip qw( :ERROR_CODES );
Subroutine BEGIN: called CC=1 SCAR=0.0
317  
318 4 ▶use vars qw(@PAR_INC); # explicitly stated PAR library files (preferred)
Subroutine BEGIN: called CC=1 SCAR=0.0
319 4 ▶use vars qw(@PAR_INC_LAST); # explicitly stated PAR library files (fallback)
Subroutine BEGIN: called CC=1 SCAR=0.0
320 4 ▶use vars qw(%PAR_INC); # sets {$par}{$file} for require'd modules
Subroutine BEGIN: called CC=1 SCAR=0.0
321 4 ▶use vars qw(@LibCache %LibCache); # I really miss pseudohash.
Subroutine BEGIN: called CC=1 SCAR=0.0
322 4 ▶use vars qw($LastAccessedPAR $LastTempFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
323 4 ▶use vars qw(@RepositoryObjects); # If we have PAR::Repository::Client support, we
Subroutine BEGIN: called CC=1 SCAR=0.0
324 # put the ::Client objects in here.
325 4 ▶use vars qw(@PriorityRepositoryObjects); # repositories which are preferred over local stuff
Subroutine BEGIN: called CC=1 SCAR=0.0
326 4 ▶use vars qw(@UpgradeRepositoryObjects); # If we have PAR::Repository::Client's in upgrade mode
Subroutine BEGIN: called CC=1 SCAR=0.0
327 # put the ::Client objects in here *as well*.
328 4 ▶use vars qw(%FileCache); # The Zip-file file-name-cache
Subroutine BEGIN: called CC=1 SCAR=0.0
329 # Layout:
330 # $FileCache{$ZipObj}{$FileName} = $Member
331 4 ▶use vars qw(%ArchivesExtracted); # Associates archive-zip-object => full extraction path
Subroutine BEGIN: called CC=1 SCAR=0.0
332  
333 my $ver = $Config{version};
334 my $arch = $Config{archname};
335 my $progname = $ENV{PAR_PROGNAME} || $0;
336 my $is_insensitive_fs = (
337 -s $progname
338 and (-s lc($progname) || -1) == (-s uc($progname) || -1)
339 and (-s lc($progname) || -1) == -s $progname
340 );
341  
342 # lexical for import(), and _import_foo() functions to control unpar()
343 my %unpar_options;
344  
345 # called on "use PAR"
346 sub import {
347 7 ▶ my $class = shift;
Subroutine import: called CC=20 SCAR=45.7
348  
349 7 PAR::SetupProgname::set_progname();
350 7 PAR::SetupTemp::set_par_temp_env();
351  
352 7 ▶ $progname = $ENV{PAR_PROGNAME} ||= $0;
Condition66%2/3
$ENV{"PAR_PROGNAME"} ||= $0
l!l&&r!l&&!r
340
MC/DC0%0/2
$ENV{"PAR_PROGNAME"} ||= $0
$ENV{"PAR_PROGNAME"} $0
Truth table66%2/3
A ||= B
A= $ENV{"PAR_PROGNAME"}B= $0
ABresult
1X1
011
000
353 7 ▶ $is_insensitive_fs = (-s $progname and (-s lc($progname) || -1) == (-s uc($progname) || -1));
Condition42%3/7
-s $progname && (-s lc $progname || -1) == (-s uc $progname || -1)
!ll&&!rl&&r
070
-s lc $progname || -1
l!l
70
-s uc $progname || -1
l!l
07
MC/DC0%0/2
-s $progname && (-s lc $progname || -1) == (-s uc $progname || -1)
-s $progname -s lc $progname
MC/DC0%0/1
-s uc $progname || -1
-s uc $progname
Truth table33%1/3
A && B
A= -s $prognameB= -s lc $progname
ABresult
0X0
100
111
Truth table50%1/2
A
A= -s uc $progname
Aresult
11
00
354  
355 7 my @args = @_;
356  
357 # Insert PAR hook in @INC.
358 7 ▶ unshift @INC, \&find_par unless grep { $_ eq \&find_par } @INC;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq \&PAR::find_par;} @INC 4 3 7
359 7 ▶ push @INC, \&find_par_last unless grep { $_ eq \&find_par_last } @INC;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq \&PAR::find_par_last;} @INC 4 3 7
360  
361 # process args to use PAR 'foo.par', { opts }, ...;
362 7 foreach my $par (@args) {
363 4 ▶ if (ref($par) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $par eq 'HASH') { } 3 1 4
elsif ($par =~ /[?*{}\[\]]/) { } 0 1 1
364 # we have been passed a hash reference
365 3 _import_hash_ref($par);
366 }
367 elsif ($par =~ /[?*{}\[\]]/) {
368 # implement globbing for PAR archives
369 0 require File::Glob;
370 0 foreach my $matched (File::Glob::glob($par)) {
371 0 push @PAR_INC, unpar($matched, undef, undef, 1);
372 }
373 }
374 else {
375 # ordinary string argument => file
376 1 push @PAR_INC, unpar($par, undef, undef, 1);
377 }
378 }
379  
380 6 ▶ return if $PAR::__import;
Branch: 1 branch
BranchTrueFalseTotal
if $PAR::__import 0 6 6
381 6 local $PAR::__import = 1;
382  
383 6 require PAR::Heavy;
384 6 PAR::Heavy::_init_dynaloader();
385  
386 # The following code is executed for the case where the
387 # running program is itself a PAR archive.
388 # ==> run script/main.pl
389 6 ▶ if (unpar($progname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unpar($progname)) 0 6 6
390 # XXX - handle META.yml here!
391 0 push @PAR_INC, unpar($progname, undef, undef, 1);
392  
393 0 _extract_inc($progname);
394 0 ▶ if ($LibCache{$progname}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PAR::LibCache{$progname}) 0 0 0
395 # XXX bad: this us just a good guess
396 0 require File::Spec;
397 0 $ArchivesExtracted{$progname} = File::Spec->catdir($ENV{PAR_TEMP}, 'inc');
398 }
399  
400 0 my $zip = $LibCache{$progname};
401 0 my $member = _first_member( $zip,
402 "script/main.pl",
403 "main.pl",
404 );
405  
406 0 ▶ if ($progname and !$member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($progname and not $member) 0 0 0
Condition0%0/3
$progname and not $member
!ll&&!rl&&r
000
MC/DC0%0/2
$progname and not $member
$progname not $member
Truth table0%0/3
A and not(B)
A= $prognameB= not $member
ABresult
0X0
100
111
407 0 require File::Spec;
408 0 my @path = File::Spec->splitdir($progname);
409 0 my $filename = pop @path;
410 0 $member = _first_member( $zip,
411 "script/".$filename,
412 "script/".$filename.".pl",
413 $filename,
414 $filename.".pl",
415 )
416 }
417  
418 # finally take $ARGV[0] as the hint for file to run
419 0 ▶ if (defined $ARGV[0] and !$member) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ARGV[0] and not $member) 0 0 0
Condition0%0/3
defined $ARGV[0] and not $member
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ARGV[0] and not $member
defined $ARGV[0] not $member
Truth table0%0/3
A and not(B)
A= defined $ARGV[0]B= not $member
ABresult
0X0
100
111
420 0 ▶ $member = _first_member( $zip,
Branch: 1 branch
BranchTrueFalseTotal
$member = _first_member($zip, "script/$ARGV[0]", "script/$ARGV[0].pl", $ARGV[0], "$ARGV[0].pl") or die qq[PAR.pm: Can't open perl script "$ARGV[0]": No such file or directory] 0 0 0
421 "script/$ARGV[0]",
422 "script/$ARGV[0].pl",
423 $ARGV[0],
424 "$ARGV[0].pl",
425 ) or die qq(PAR.pm: Can't open perl script "$ARGV[0]": No such file or directory);
426 0 shift @ARGV;
427 }
428  
429  
430 0 ▶ if (!$member) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($member) 0 0 0
431 0 die "Usage: $0 script_file_name.\n";
432 }
433  
434 0 _run_member($member);
435 }
436 }
437  
438  
439 # import() helper for the "use PAR {...};" syntax.
440 sub _import_hash_ref {
441 3 ▶ my $opt = shift;
Subroutine _import_hash_ref: called CC=18 SCAR=39.2
442  
443 # hash slice assignment -- pass all of the options into unpar
444 3 local @unpar_options{keys(%$opt)} = values(%$opt);
445  
446 # check for incompatible options:
447 3 ▶ if ( exists $opt->{repository} and exists $opt->{file} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $opt->{'repository'} and exists $opt->{'file'}) { } 0 3 3
elsif (exists $opt->{'file'} and exists $opt->{'install'} || exists $opt->{'upgrade'}) { } 0 3 3
elsif (not exists $opt->{'repository'} || exists $opt->{'file'}) { } 0 3 3
Condition33%1/3
exists $opt->{"repository"} and exists $opt->{"file"}
!ll&&!rl&&r
300
MC/DC0%0/2
exists $opt->{"repository"} and exists $opt->{"file"}
exists $opt->{"repository"} exists $opt->{"file"}
Truth table33%1/3
A and B
A= exists $opt->{"repository"}B= exists $opt->{"file"}
ABresult
0X0
100
111
448 0 croak("Invalid PAR loading options. Cannot have a 'repository' and 'file' option at the same time.");
449 }
450 ▶ elsif (
Condition33%2/6
exists $opt->{"file"} and exists $opt->{"install"} || exists $opt->{"upgrade"}
!ll&&!rl&&r
030
exists $opt->{"install"} or exists $opt->{"upgrade"}
l!l&&r!l&&!r
003
MC/DC0%0/3
exists $opt->{"file"} and exists $opt->{"install"} || exists $opt->{"upgrade"}
exists $opt->{"file"} exists $opt->{"install"} exists $opt->{"upgrade"}
Truth table25%1/4
A and B or C
A= exists $opt->{"file"}B= exists $opt->{"install"}C= exists $opt->{"upgrade"}
ABCresult
0XX0
1000
11X1
1011
451 exists $opt->{file}
452 and (exists $opt->{install} or exists $opt->{upgrade})
453 ) {
454 0 ▶ my $e = exists($opt->{install}) ? 'install' : 'upgrade';
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'install'} ? : 0 0 0
455 0 croak("Invalid PAR loading options. Cannot combine 'file' and '$e' options.");
456 }
457 ▶ elsif ( not exists $opt->{repository} and not exists $opt->{file} ) {
Condition33%1/3
exists $opt->{'repository'} || exists $opt->{'file'}
l!l&&r!l&&!r
030
MC/DC0%0/2
exists $opt->{'repository'} || exists $opt->{'file'}
exists $opt->{'repository'} exists $opt->{'file'}
Truth table33%1/3
A || B
A= exists $opt->{'repository'}B= exists $opt->{'file'}
ABresult
1X1
011
000
458 0 croak("Invalid PAR loading options. Need at least one of 'file' or 'repository' options.");
459 }
460  
461 # load from file
462 3 ▶ if (exists $opt->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt->{'file'}) { } 3 0 3
463 croak("Cannot load undefined PAR archive")
464 3 ▶ if not defined $opt->{file};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{"file"} 0 3 3
465  
466 # for files, we default to loading from PAR archive first
467 3 my $fallback = $opt->{fallback};
468 3 ▶ $fallback = 0 if not defined $fallback;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fallback 2 1 3
469  
470 3 ▶ if (not $fallback) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fallback) { } 2 1 3
471 # load from this PAR arch preferably
472 2 push @PAR_INC, unpar($opt->{file}, undef, undef, 1);
473 }
474 else {
475 # load from this PAR arch as fallback
476 1 push @PAR_INC_LAST, unpar($opt->{file}, undef, undef, 1);
477 }
478  
479 }
480 else {
481 # Deal with repositories elsewhere
482 0 my $client = _import_repository($opt);
483 0 ▶ return() if not $client;
Branch: 1 branch
BranchTrueFalseTotal
unless $client 0 0 0
484  
485 0 ▶ if (defined $opt->{run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"run"}) 0 0 0
486 # run was specified
487 # run the specified script from the repository
488 0 $client->run_script( $opt->{run} );
489 0 return 1;
490 }
491  
492 0 return 1;
493 }
494  
495 # run was specified
496 # run the specified script from inside the PAR file.
497 3 ▶ if (defined $opt->{run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"run"}) 1 2 3
498 1 my $script = $opt->{run};
499 1 require PAR::Heavy;
500 1 PAR::Heavy::_init_dynaloader();
501  
502 # XXX - handle META.yml here!
503 1 _extract_inc($opt->{file});
504  
505 1 my $zip = $LibCache{$opt->{file}};
506 1 ▶ my $member = _first_member( $zip,
Branch: 1 branch
BranchTrueFalseTotal
!($script =~ m[^script/]) ? : 1 0 1
507 (($script !~ /^script\//) ? ("script/$script", "script/$script.pl") : ()),
508 $script,
509 "$script.pl",
510 );
511  
512 1 ▶ if (not defined $member) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $member) 0 1 1
513 0 croak("Cannot run script '$script' from PAR file '$opt->{file}'. Script couldn't be found in PAR file.");
514 }
515  
516 1 _run_member_from_par($member);
517 }
518  
519 2 return();
520 }
521  
522  
523 # This sub is invoked by _import_hash_ref if a {repository}
524 # option is found
525 # Returns the repository client object on success.
526 sub _import_repository {
527 0 ▶ my $opt = shift;
Subroutine _import_repository: not called CC=12 SCAR=50.5
528 0 my $url = $opt->{repository};
529  
530 0 eval "require PAR::Repository::Client; 1;";
531 0 ▶ if ($@ or not eval PAR::Repository::Client->VERSION >= 0.04) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not eval "PAR::Repository::Client"->VERSION >= "0.04") 0 0 0
Condition0%0/3
$@ or not eval "PAR::Repository::Client"->VERSION >= "0.04"
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not eval "PAR::Repository::Client"->VERSION >= "0.04"
$@ not eval "PAR::Repository::Client"->VERSION >= "0.04"
Truth table0%0/3
A or not(B)
A= $@B= not eval "PAR::Repository::Client"->VERSION >= "0.04"
ABresult
1X1
011
000
532 0 croak "In order to use the 'use PAR { repository => 'url' };' syntax, you need to install the PAR::Repository::Client module (version 0.04 or later) from CPAN. This module does not seem to be installed as indicated by the following error message: $@";
533 }
534  
535 0 ▶ if ($opt->{upgrade} and not eval PAR::Repository::Client->VERSION >= 0.22) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"upgrade"} and not eval "PAR::Repository::Client"->VERSION >= "0.22") 0 0 0
Condition0%0/3
$opt->{"upgrade"} and not eval "PAR::Repository::Client"->VERSION >= "0.22"
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->{"upgrade"} and not eval "PAR::Repository::Client"->VERSION >= "0.22"
$opt->{"upgrade"} not eval "PAR::Repository::Client"->VERSION >= "0.22"
Truth table0%0/3
A and not(B)
A= $opt->{"upgrade"}B= not eval "PAR::Repository::Client"->VERSION >= "0.22"
ABresult
0X0
100
111
536 0 croak "In order to use the 'upgrade' option, you need to install the PAR::Repository::Client module (version 0.22 or later) from CPAN";
537 }
538  
539 0 ▶ if ($opt->{dependencies} and not eval PAR::Repository::Client->VERSION >= 0.23) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"dependencies"} and not eval "PAR::Repository::Client"->VERSION >= "0.23") 0 0 0
Condition0%0/3
$opt->{"dependencies"} and not eval "PAR::Repository::Client"->VERSION >= "0.23"
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->{"dependencies"} and not eval "PAR::Repository::Client"->VERSION >= "0.23"
$opt->{"dependencies"} not eval "PAR::Repository::Client"->VERSION >= "0.23"
Truth table0%0/3
A and not(B)
A= $opt->{"dependencies"}B= not eval "PAR::Repository::Client"->VERSION >= "0.23"
ABresult
0X0
100
111
540 0 croak "In order to use the 'dependencies' option, you need to install the PAR::Repository::Client module (version 0.23 or later) from CPAN";
541 }
542  
543 0 my $obj;
544  
545 # Support existing clients passed in as objects.
546 0 ▶ if (ref($url) and UNIVERSAL::isa($url, 'PAR::Repository::Client')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $url and UNIVERSAL::isa($url, 'PAR::Repository::Client')) { } 0 0 0
Condition0%0/3
ref $url and UNIVERSAL::isa($url, "PAR::Repository::Client")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $url and UNIVERSAL::isa($url, "PAR::Repository::Client")
ref $url UNIVERSAL::isa($url, "PAR::Repository::Client")
Truth table0%0/3
A and B
A= ref $urlB= UNIVERSAL::isa($url, "PAR::Repository::Client")
ABresult
0X0
100
111
547 0 $obj = $url;
548 }
549 else {
550 $obj = PAR::Repository::Client->new(
551 uri => $url,
552 auto_install => $opt->{install},
553 auto_upgrade => $opt->{upgrade},
554 static_dependencies => $opt->{dependencies},
555 0 );
556 }
557  
558 0 ▶ if (exists($opt->{fallback}) and not $opt->{fallback}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt->{'fallback'} and not $opt->{'fallback'}) { } 0 0 0
Condition0%0/3
exists $opt->{"fallback"} and not $opt->{"fallback"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt->{"fallback"} and not $opt->{"fallback"}
exists $opt->{"fallback"} not $opt->{"fallback"}
Truth table0%0/3
A and not(B)
A= exists $opt->{"fallback"}B= not $opt->{"fallback"}
ABresult
0X0
100
111
559 0 unshift @PriorityRepositoryObjects, $obj; # repository beats local stuff
560 } else {
561 0 push @RepositoryObjects, $obj; # local stuff beats repository
562 }
563 # these are tracked separately so we can check for upgrades early
564 0 ▶ push @UpgradeRepositoryObjects, $obj if $opt->{upgrade};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"upgrade"} 0 0 0
565  
566 0 return $obj;
567 }
568  
569 # Given an Archive::Zip obj and a list of files/paths,
570 # this function returns the Archive::Zip::Member for the
571 # first of the files found in the ZIP. If none is found,
572 # returns the empty list.
573 sub _first_member {
574 7 ▶ my $zip = shift;
Subroutine _first_member: called CC=3 SCAR=11.0
575 7 foreach my $name (@_) {
576 23 my $member = _cached_member_named($zip, $name);
577 23 ▶ return $member if $member;
Branch: 1 branch
BranchTrueFalseTotal
if $member 4 19 23
578 }
579 3 return;
580 }
581  
582 # Given an Archive::Zip object, this finds the first
583 # Archive::Zip member whose file name matches the
584 # regular expression
585 sub _first_member_matching {
586 0 ▶ my $zip = shift;
Subroutine _first_member_matching: not called CC=4 SCAR=30.0
587 0 my $regex = shift;
588  
589 0 my $cache = $FileCache{$zip};
590 0 ▶ $cache = $FileCache{$zip} = _make_file_cache($zip) if not $cache;
Branch: 1 branch
BranchTrueFalseTotal
unless $cache 0 0 0
591  
592 0 foreach my $name (keys %$cache) {
593 0 ▶ if ($name =~ $regex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /$regex/) 0 0 0
594 0 return $cache->{$name};
595 }
596 }
597  
598 0 return();
599 }
600  
601  
602 sub _run_member_from_par {
603 1 ▶ my $member = shift;
Subroutine _run_member_from_par: called CC=3 SCAR=11.1
604 my (undef, $filename) = _tempfile(
605 sub {
606 1 ▶ my $fh = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
607 1 my $file = $member->fileName;
608 1 print $fh "package main;\n",
609 "#line 1 \"$file\"\n";
610 1 ▶ $member->extractToFileHandle($fh) == AZ_OK
Branch: 1 branch
BranchTrueFalseTotal
$member->extractToFileHandle($fh) == 0 or die "Can't extract ${file}: $!" 0 1 1
611 or die "Can't extract $file: $!";
612 },
613 1 $member->crc32String . ".pl");
614  
615 1 $ENV{PAR_0} = $filename; # for Pod::Usage
616 1 { do $filename;
617 1 ▶ CORE::exit($1) if ($@ =~/^_TK_EXIT_\((\d+)\)/);
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /^_TK_EXIT_\((\d+)\)/ 0 1 1
618 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
619 1 exit;
620 }
621 }
622  
623 sub _run_member {
624 0 ▶ my $member = shift;
Subroutine _run_member: not called CC=3 SCAR=24.8
625 my ($fh, $filename) = _tempfile(
626 sub {
627 0 ▶ my $fh = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
628 0 my $file = $member->fileName;
629 0 print $fh "package main;\n",
630 "#line 1 \"$file\"\n";
631 0 ▶ $member->extractToFileHandle($fh) == AZ_OK
Branch: 1 branch
BranchTrueFalseTotal
$member->extractToFileHandle($fh) == 0 or die "Can't extract ${file}: $!" 0 0 0
632 or die "Can't extract $file: $!";
633 },
634 0 $member->crc32String . ".pl");
635  
636 # NOTE: Perl 5.14.x will print the infamous warning
637 # "Use of uninitialized value in do "file" at .../PAR.pm line 636"
638 # when $INC{main} exists, but is undef, when "do 'main'" is called.
639 # This typically happens at the second invocation of _run_member()
640 # when running a packed executable (the first invocation is for the
641 # generated script/main.pl, the second for the packed script itself).
642 # Hence shut the warning up by assigning something to $INC{main}.
643 # 5.14.x is the only Perl version since 5.8.1 that shows this behaviour.
644 0 ▶ unshift @INC, sub { shift @INC; $INC{$_[1]} = $filename; return $fh };
Subroutine __ANON__: not called CC=1 SCAR=6.9
645  
646 0 $ENV{PAR_0} = $filename; # for Pod::Usage
647 0 { do 'main';
648 0 ▶ CORE::exit($1) if ($@ =~/^_TK_EXIT_\((\d+)\)/);
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /^_TK_EXIT_\((\d+)\)/ 0 0 0
649 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
650 0 exit;
651 }
652 }
653  
654 sub _run_external_file {
655 0 ▶ my $filename = shift;
Subroutine _run_external_file: not called CC=5 SCAR=34.0
656 0 ▶ open my $ffh, '<', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $ffh, "<", $filename or die qq[Can't open perl script "$filename": $!] 0 0 0
657 or die "Can't open perl script \"$filename\": $!";
658  
659 my $string = "package main;\n" .
660 "#line 1 \"$filename\"\n" .
661 0 do { local $/ = undef; <$ffh> };
662 0 close $ffh;
663  
664 0 ▶ open my $fh, '<', \$string
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", \$string or die "Can't open file handle to string: $!" 0 0 0
665 or die "Can't open file handle to string: $!";
666  
667 0 ▶ unshift @INC, sub { shift @INC; return $fh };
Subroutine __ANON__: not called CC=1 SCAR=6.9
668  
669 0 $ENV{PAR_0} = $filename; # for Pod::Usage
670 0 { do 'main';
671 0 ▶ CORE::exit($1) if ($@ =~/^_TK_EXIT_\((\d+)\)/);
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /^_TK_EXIT_\((\d+)\)/ 0 0 0
672 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
673 0 exit;
674 }
675 }
676  
677 # extract the contents of a .par (or .exe) or any
678 # Archive::Zip handle to the PAR_TEMP/inc directory.
679 # returns that directory.
680 sub _extract_inc {
681 1 ▶ my $file_or_azip_handle = shift;
Subroutine _extract_inc: called CC=14 SCAR=28.2
682 1 ▶ my $dlext = defined($Config{dlext}) ? $Config{dlext} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $PAR::Config{'dlext'} ? : 1 0 1
683 1 ▶ my $is_handle = ref($file_or_azip_handle) && $file_or_azip_handle->isa('Archive::Zip::Archive');
Condition33%1/3
ref $file_or_azip_handle && $file_or_azip_handle->isa('Archive::Zip::Archive')
!ll&&!rl&&r
100
MC/DC0%0/2
ref $file_or_azip_handle && $file_or_azip_handle->isa('Archive::Zip::Archive')
ref $file_or_azip_handle $file_or_azip_handle->isa('Archive::Zip::Archive')
Truth table33%1/3
A && B
A= ref $file_or_azip_handleB= $file_or_azip_handle->isa('Archive::Zip::Archive')
ABresult
0X0
100
111
684  
685 1 require File::Spec;
686  
687 1 my $inc = File::Spec->catdir($PAR::SetupTemp::PARTemp, "inc");
688 1 my $inc_lock = "$inc.lock";
689  
690 1 my $canary = File::Spec->catfile($PAR::SetupTemp::PARTemp, $PAR::SetupTemp::Canary);
691  
692 # acquire the "wanna extract inc" lock
693 1 ▶ open my $lock, ">", $inc_lock or die qq[can't open "$inc_lock": $!];
Branch: 1 branch
BranchTrueFalseTotal
open my $lock, ">", $inc_lock or die qq[can't open "$inc_lock": $!] 0 1 1
694 1 flock($lock, LOCK_EX);
695  
696 1 ▶ unless (-d $inc && -e $canary)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $inc and -e $canary) 1 0 1
Condition33%1/3
-d $inc and -e $canary
!ll&&!rl&&r
100
MC/DC0%0/2
-d $inc and -e $canary
-d $inc -e $canary
Truth table33%1/3
A and B
A= -d $incB= -e $canary
ABresult
0X0
100
111
697 {
698 1 mkdir($inc, 0755);
699  
700 EXTRACT: {
701 1 my $zip;
702 1 ▶ if ($is_handle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_handle) { } 0 1 1
703 0 $zip = $file_or_azip_handle;
704 } else {
705 # First try to unzip the *fast* way.
706 1 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Archive::Unzip::Burst; Archive::Unzip::Burst::unzip($file_or_azip_handle, $inc) == 0 } } and last EXTRACT 0 1 1
707 1 require Archive::Unzip::Burst;
708 0 Archive::Unzip::Burst::unzip($file_or_azip_handle, $inc) == AZ_OK;
709 } and last EXTRACT;
710  
711 # Either failed to load Archive::Unzip::Burst or
712 # Archive::Unzip::Burst::unzip failed: fallback to slow way.
713 1 ▶ open my $fh, '<', $file_or_azip_handle
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file_or_azip_handle or die "Cannot find '${file_or_azip_handle}': $!" 0 1 1
714 or die "Cannot find '$file_or_azip_handle': $!";
715 1 binmode($fh);
716 1 bless($fh, 'IO::File');
717  
718 # Temporarily increase Archive::Zip::ChunkSize so that we may find
719 # the EOCD even if stuff has been appended (e.g.by OSX codesign)
720 # to the zip/executable.
721 1 Archive::Zip::setChunkSize(-s $fh);
722 1 $zip = Archive::Zip->new;
723 1 ▶ $zip->readFromFileHandle($fh, $file_or_azip_handle) == AZ_OK
Branch: 1 branch
BranchTrueFalseTotal
$zip->readFromFileHandle($fh, $file_or_azip_handle) == 0 or die "Read '${file_or_azip_handle}' error: $!" 0 1 1
724 or die "Read '$file_or_azip_handle' error: $!";
725 1 Archive::Zip::setChunkSize(64 * 1024);
726 }
727  
728 1 for ( $zip->memberNames() ) {
729 7 s{^/}{};
730 7 my $outfile = File::Spec->catfile($inc, $_);
731 7 ▶ next if -e $outfile and not -w _;
Branch: 1 branch
BranchTrueFalseTotal
if -e $outfile and not -w _ 0 7 7
Condition33%1/3
-e $outfile and not -w _
!ll&&!rl&&r
700
MC/DC0%0/2
-e $outfile and not -w _
-e $outfile not -w _
Truth table33%1/3
A and not(B)
A= -e $outfileB= not -w _
ABresult
0X0
100
111
732 7 $zip->extractMember($_, $outfile);
733 # Unfortunately Archive::Zip doesn't have an option
734 # NOT to restore member timestamps when extracting, hence set
735 # it to "now" (making it younger than the canary file).
736 7 utime(undef, undef, $outfile);
737 }
738 }
739  
740 1 ▶ $ArchivesExtracted{$is_handle ? $file_or_azip_handle->fileName() : $file_or_azip_handle} = $inc;
Branch: 1 branch
BranchTrueFalseTotal
$is_handle ? : 0 1 1
741  
742 # touch (and back-date) canary file
743 1 open my $fh, ">", $canary;
744 1 print $fh <<'...';
745 This file is used as "canary in the coal mine" to detect when
746 files in PAR's cache area are being removed by some clean up
747 mechanism (probably based on file modification times).
748 ...
749 1 close $fh;
750 1 my $dateback = time() - $PAR::SetupTemp::CanaryDateBack;
751 1 utime($dateback, $dateback, $canary);
752 }
753  
754 # release the "wanna extract inc" lock
755 1 flock($lock, LOCK_UN);
756 1 close $lock;
757  
758 # add the freshly extracted directories to @INC,
759 # but make sure there's no duplicates
760 1 my %inc_exists = map { ($_, 1) } @INC;
761 1 unshift @INC, grep !exists($inc_exists{$_}),
762 grep -d,
763 map File::Spec->catdir($inc, @$_),
764 [ 'lib' ], [ 'arch' ], [ $arch ],
765 [ $ver ], [ $ver, $arch ], [];
766  
767 1 return $inc;
768 }
769  
770  
771 # This is the hook placed in @INC for loading PAR's
772 # before any other stuff in @INC
773 sub find_par {
774 22 ▶ my @args = @_;
Subroutine find_par: called CC=8 SCAR=34.1
Pod undocumented
775  
776 # if there are repositories in upgrade mode, check them
777 # first. If so, this is expensive, of course!
778 22 ▶ if (@UpgradeRepositoryObjects) {
Branch: 1 branch
BranchTrueFalseTotal
if (@PAR::UpgradeRepositoryObjects) 0 22 22
779 0 my $module = $args[1];
780 0 $module =~ s/\.pm$//;
781 0 $module =~ s/\//::/g;
782 0 foreach my $client (@UpgradeRepositoryObjects) {
783 0 my $local_file = $client->upgrade_module($module);
784  
785 # break the require if upgrade_module has been required already
786 # to avoid infinite recursion
787 0 ▶ if (exists $INC{$args[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$args[1]}) 0 0 0
788 # Oh dear. Check for the possible return values of the INC sub hooks in
789 # perldoc -f require before trying to understand this.
790 # Then, realize that if you pass undef for the file handle, perl (5.8.9)
791 # does NOT use the subroutine. Thus the hacky GLOB ref.
792 0 my $line = 1;
793 4 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
794 0 ▶ return (\*I_AM_NOT_HERE, sub {$line ? ($_="1;",$line=0,return(1)) : ($_="",return(0))});
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$line ? : 0 0 0
795 }
796  
797 # Note: This is likely not necessary as the module has been installed
798 # into the system by upgrade_module if it was available at all.
799 # If it was already loaded, this will not be reached (see return right above).
800 # If it could not be loaded from the system and neither found in the repository,
801 # we simply want to have the normal error message, too!
802 #
803 #if ($local_file) {
804 # # XXX load with fallback - is that right?
805 # return _find_par_internals([$PAR_INC_LAST[-1]], @args);
806 #}
807 }
808 }
809 22 my $rv = _find_par_internals(\@PAR_INC, @args);
810  
811 22 ▶ return $rv if defined $rv or not @PriorityRepositoryObjects;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rv or not @PAR::PriorityRepositoryObjects 22 0 22
Condition66%2/3
defined $rv or not @PAR::PriorityRepositoryObjects
l!l&&r!l&&!r
1210
MC/DC0%0/2
defined $rv or not @PAR::PriorityRepositoryObjects
defined $rv not @PAR::PriorityRepositoryObjects
Truth table66%2/3
A or not(B)
A= defined $rvB= not @PAR::PriorityRepositoryObjects
ABresult
1X1
011
000
812  
813 # the repositories that are preferred over locally installed modules
814 0 my $module = $args[1];
815 0 $module =~ s/\.pm$//;
816 0 $module =~ s/\//::/g;
817 0 foreach my $client (@PriorityRepositoryObjects) {
818 0 my $local_file = $client->get_module($module, 0); # 1 == fallback
819 0 ▶ if ($local_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_file) 0 0 0
820 # Not loaded as fallback (cf. PRIORITY) thus look at PAR_INC
821 # instead of PAR_INC_LAST
822 0 return _find_par_internals([$PAR_INC[-1]], @args);
823 }
824 }
825 0 return();
826 }
827  
828 # This is the hook placed in @INC for loading PAR's
829 # AFTER any other stuff in @INC
830 # It also deals with loading from repositories as a
831 # fallback-fallback ;)
832 sub find_par_last {
833 3 ▶ my @args = @_;
Subroutine find_par_last: called CC=5 SCAR=23.7
Pod undocumented
834 # Try the local PAR files first
835 3 my $rv = _find_par_internals(\@PAR_INC_LAST, @args);
836 3 ▶ return $rv if defined $rv;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rv 1 2 3
837  
838 # No repositories => return
839 2 ▶ return $rv if not @RepositoryObjects;
Branch: 1 branch
BranchTrueFalseTotal
unless @PAR::RepositoryObjects 2 0 2
840  
841 0 my $module = $args[1];
842 0 $module =~ s/\.pm$//;
843 0 $module =~ s/\//::/g;
844 0 foreach my $client (@RepositoryObjects) {
845 0 my $local_file = $client->get_module($module, 1); # 1 == fallback
846 0 ▶ if ($local_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_file) 0 0 0
847 # Loaded as fallback thus look at PAR_INC_LAST
848 0 return _find_par_internals([$PAR_INC_LAST[-1]], @args);
849 }
850 }
851 0 return $rv;
852 }
853  
854  
855 # This routine implements loading modules from PARs
856 # both for loading PARs preferably or as fallback.
857 # To distinguish the cases, the first parameter should
858 # be a reference to the corresponding @PAR_INC* array.
859 sub _find_par_internals {
860 25 ▶ my ($INC_ARY, $self, $file, $member_only) = @_;
Subroutine _find_par_internals: called CC=11 SCAR=33.7
861  
862 25 my $scheme;
863 25 ▶ foreach (@$INC_ARY ? @$INC_ARY : @INC) {
Branch: 1 branch
BranchTrueFalseTotal
@$INC_ARY ? : 5 20 25
864 208 my $path = $_;
865 208 ▶ if ($] < 5.008001) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.008001") 0 208 208
866 # reassemble from "perl -Ischeme://path" autosplitting
867 0 ▶ $path = "$scheme:$path" if !@$INC_ARY
Branch: 1 branch
BranchTrueFalseTotal
if not @$INC_ARY and $path and $path =~ m[//] and $scheme and $scheme =~ /^\w+$/ 0 0 0
Condition0%0/12
not @$INC_ARY and $path and $path =~ m[//] and $scheme and $scheme =~ /^\w+$/
!ll&&!rl&&r
000
not @$INC_ARY and $path and $path =~ m[//] and $scheme
!ll&&!rl&&r
000
not @$INC_ARY and $path and $path =~ m[//]
!ll&&!rl&&r
000
not @$INC_ARY and $path
!ll&&!rl&&r
000
MC/DC0%0/5
not @$INC_ARY and $path and $path =~ m[//] and $scheme and $scheme =~ /^\w+$/
not @$INC_ARY $path $path =~ m[//] $scheme $scheme =~ /^\w+$/
Truth table0%0/6
not(A) and B and C and D and E
A= not @$INC_ARYB= $pathC= $path =~ m[//]D= $schemeE= $scheme =~ /^\w+$/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
868 and $path and $path =~ m!//!
869 and $scheme and $scheme =~ /^\w+$/;
870 0 $scheme = $path;
871 }
872 208 ▶ my $rv = unpar($path, $file, $member_only, 1) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = unpar($path, $file, $member_only, 1) or next 206 2 208
873 2 $PAR_INC{$path}{$file} = 1;
874 2 ▶ $INC{$file} = $LastTempFile if (lc($file) =~ /^(?!tk).*\.pm$/);
Branch: 1 branch
BranchTrueFalseTotal
if lc($file) =~ /^(?!tk).*\.pm$/ 2 0 2
875 2 return $rv;
876 }
877  
878 23 return;
879 }
880  
881 sub reload_libs {
882 0 ▶ my @par_files = @_;
Subroutine reload_libs: not called CC=5 SCAR=34.0
Pod undocumented
883 0 ▶ @par_files = sort keys %LibCache unless @par_files;
Branch: 1 branch
BranchTrueFalseTotal
unless @par_files 0 0 0
884  
885 0 foreach my $par (@par_files) {
886 0 ▶ my $inc_ref = $PAR_INC{$par} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $inc_ref = $PAR::PAR_INC{$par} or next 0 0 0
887 0 delete $LibCache{$par};
888 0 delete $FileCache{$par};
889 0 foreach my $file (sort keys %$inc_ref) {
890 0 delete $INC{$file};
891 0 require $file;
892 }
893 }
894 }
895  
896 #sub find_zip_member {
897 # my $file = pop;
898 #
899 # foreach my $zip (@LibCache) {
900 # my $member = _first_member($zip, $file) or next;
901 # return $member;
902 # }
903 #
904 # return;
905 #}
906  
907 sub read_file {
908 1 ▶ my $file = pop;
Subroutine read_file: called CC=3 SCAR=11.7
Pod undocumented
909  
910 1 foreach my $zip (@LibCache) {
911 1 ▶ my $member = _first_member($zip, $file) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $member = _first_member($zip, $file) or next 0 1 1
912 1 return scalar $member->contents;
913 }
914  
915 0 return;
916 }
917  
918 sub par_handle {
919 1 ▶ my $par = pop;
Subroutine par_handle: called CC=1 SCAR=0.0
Pod undocumented
920 1 return $LibCache{$par};
921 }
922  
923 my %escapes;
924 sub unpar {
925 218 ▶ my ($par, $file, $member_only, $allow_other_ext) = @_;
Subroutine unpar: called CC=38 SCAR=53.7
Pod undocumented
926 218 ▶ return if not defined $par;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $par 0 218 218
927 218 my $zip = $LibCache{$par};
928 218 my @rv = $par;
929  
930 # a guard against (currently unimplemented) recursion
931 218 ▶ return if $PAR::__unpar;
Branch: 1 branch
BranchTrueFalseTotal
if $PAR::__unpar 0 218 218
932 218 local $PAR::__unpar = 1;
933  
934 218 ▶ unless ($zip) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zip) 211 7 218
935 # URL use case ==> download
936 211 ▶ if ($par =~ m!^\w+://!) {
Branch: 3 branches
BranchTrueFalseTotal
if ($par =~ m[^\w+://]) { } 0 211 211
elsif (ref $par eq 'SCALAR') { } 0 211 211
elsif (not +($allow_other_ext || $par =~ /\.par\z/i) && -f $par) { } 209 2 211
937 0 require File::Spec;
938 0 require LWP::Simple;
939  
940 # reflector support
941 0 ▶ $par .= "pm=$file" if $par =~ /[?&;]/;
Branch: 1 branch
BranchTrueFalseTotal
if $par =~ /[?&;]/ 0 0 0
942  
943 # prepare cache directory
944 0 ▶ $ENV{PAR_CACHE} ||= '_par';
Condition0%0/2
$ENV{"PAR_CACHE"} ||= "_par"
l!l
00
MC/DC0%0/1
$ENV{"PAR_CACHE"} ||= "_par"
$ENV{"PAR_CACHE"}
Truth table0%0/2
A
A= $ENV{"PAR_CACHE"}
Aresult
11
00
945 0 mkdir $ENV{PAR_CACHE}, 0777;
946 0 ▶ if (!-d $ENV{PAR_CACHE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $ENV{"PAR_CACHE"}) 0 0 0
947 0 $ENV{PAR_CACHE} = File::Spec->catdir(File::Spec->tmpdir, 'par');
948 0 mkdir $ENV{PAR_CACHE}, 0777;
949 0 ▶ return unless -d $ENV{PAR_CACHE};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $ENV{"PAR_CACHE"} 0 0 0
950 }
951  
952 # Munge URL into local file name
953 # FIXME: This might result in unbelievably long file names!
954 # I have run into the file/path length limitations of linux
955 # with similar code in PAR::Repository::Client.
956 # I suspect this is even worse on Win32.
957 # -- Steffen
958 0 my $file = $par;
959 0 ▶ if (!%escapes) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%escapes) 0 0 0
960 0 $escapes{chr($_)} = sprintf("%%%02X", $_) for 0..255;
961 }
962 {
963 0 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.2
964 0 $file =~ s/([^\w\.])/$escapes{$1}/g;
965 }
966  
967 0 $file = File::Spec->catfile( $ENV{PAR_CACHE}, $file);
968 0 LWP::Simple::mirror( $par, $file );
969 0 ▶ return unless -e $file and -f _;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file and -f _ 0 0 0
Condition0%0/3
-e $file and -f _
!ll&&!rl&&r
000
MC/DC0%0/2
-e $file and -f _
-e $file -f _
Truth table0%0/3
A and B
A= -e $fileB= -f _
ABresult
0X0
100
111
970 0 $par = $file;
971 }
972 # Got the .par as a string. (reference to scalar, of course)
973 elsif (ref($par) eq 'SCALAR') {
974 ($par, undef) = _tempfile(sub {
975 0 ▶ my $fh = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
976 0 print $fh $$par;
977 0 });
978 }
979 # If the par is not a valid .par file name and we're being strict
980 # about this, then also check whether "$par.par" exists
981 ▶ elsif (!(($allow_other_ext or $par =~ /\.par\z/i) and -f $par)) {
Condition83%5/6
($allow_other_ext || $par =~ /\.par\z/i) && -f $par
!ll&&!rl&&r
62032
$allow_other_ext or $par =~ /\.par\z/i
l!l&&r!l&&!r
20506
MC/DC66%2/3
($allow_other_ext || $par =~ /\.par\z/i) && -f $par
$allow_other_ext $par =~ /\.par\z/i -f $par
Truth table60%3/5
A or B && C
A= $allow_other_extB= $par =~ /\.par\z/iC= -f $par
ABCresult
00X0
1X00
0100
1X11
0111
982 209 $par .= ".par";
983 209 ▶ return unless -f $par;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $par 209 0 209
984 }
985  
986 2 require Archive::Zip;
987 2 $zip = Archive::Zip->new;
988  
989 2 my @file;
990 2 ▶ if (!ref $par) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $par) 2 0 2
991 2 @file = $par;
992  
993 2 open my $fh, '<', $par;
994 2 binmode($fh);
995  
996 2 $par = $fh;
997 2 bless($par, 'IO::File');
998 }
999  
1000 2 ▶ Archive::Zip::setErrorHandler(sub {});
Subroutine __ANON__: not called CC=1 SCAR=0.0
1001 2 my $rv = $zip->readFromFileHandle($par, @file);
1002 2 Archive::Zip::setErrorHandler(undef);
1003 2 ▶ return unless $rv == AZ_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $rv == 0 0 2 2
1004  
1005 2 push @LibCache, $zip;
1006 2 $LibCache{$_[0]} = $zip;
1007 2 $FileCache{$_[0]} = _make_file_cache($zip);
1008  
1009 # only recursive case -- appears to be unused and unimplemented
1010 2 foreach my $member ( _cached_members_matching($zip,
1011 "^par/(?:$Config{version}/)?(?:$Config{archname}/)?"
1012 ) ) {
1013 0 ▶ next if $member->isDirectory;
Branch: 1 branch
BranchTrueFalseTotal
if $member->isDirectory 0 0 0
1014 0 my $content = $member->contents();
1015 0 ▶ next unless $content =~ /^PK\003\004/;
Branch: 1 branch
BranchTrueFalseTotal
unless $content =~ /^PK\003\004/ 0 0 0
1016 0 push @rv, unpar(\$content, undef, undef, 1);
1017 }
1018  
1019 # extract all shlib dlls from the .par to $ENV{PAR_TEMP}
1020 # Intended to fix problem with Alien::wxWidgets/Wx...
1021 # NOTE auto/foo/foo.so|dll will get handled by the dynaloader
1022 # hook, so no need to pull it out here.
1023 # Allow this to be disabled so caller can do their own caching
1024 # via import({no_shlib_unpack => 1, file => foo.par})
1025 2 ▶ if(not $unpar_options{no_shlib_unpack} and defined $ENV{PAR_TEMP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $unpar_options{"no_shlib_unpack"} and defined $ENV{"PAR_TEMP"}) 2 0 2
Condition33%1/3
not $unpar_options{"no_shlib_unpack"} and defined $ENV{"PAR_TEMP"}
!ll&&!rl&&r
002
MC/DC0%0/2
not $unpar_options{"no_shlib_unpack"} and defined $ENV{"PAR_TEMP"}
not $unpar_options{"no_shlib_unpack"} defined $ENV{"PAR_TEMP"}
Truth table33%1/3
not(A) and B
A= not $unpar_options{"no_shlib_unpack"}B= defined $ENV{"PAR_TEMP"}
ABresult
0X0
100
111
1026 2 my @members = _cached_members_matching( $zip,
1027 qr#^shlib/$Config{archname}/.*\.\Q$Config{dlext}\E(?:\.|$)#
1028 );
1029 2 foreach my $member (@members) {
1030 0 ▶ next if $member->isDirectory;
Branch: 1 branch
BranchTrueFalseTotal
if $member->isDirectory 0 0 0
1031 0 my $member_name = $member->fileName;
1032 0 ▶ next unless $member_name =~ m{
Branch: 1 branch
BranchTrueFalseTotal
unless $member_name =~ m[ \/([^/]+)$ ]x or $member_name =~ m[ ^([^/]+)$ ] 0 0 0
Condition0%0/3
$member_name =~ m[ \/([^/]+)$ ]x or $member_name =~ m[ ^([^/]+)$ ]
l!l&&r!l&&!r
000
MC/DC0%0/2
$member_name =~ m[ \/([^/]+)$ ]x or $member_name =~ m[ ^([^/]+)$ ]
$member_name =~ m[ \/([^/]+)$ ]x $member_name =~ m[ ^([^/]+)$ ]
Truth table0%0/3
A or B
A= $member_name =~ m[ \/([^/]+)$ ]xB= $member_name =~ m[ ^([^/]+)$ ]
ABresult
1X1
011
000
1033 \/([^/]+)$
1034 }x
1035 or $member_name =~ m{
1036 ^([^/]+)$
1037 };
1038 0 my $extract_name = $1;
1039 0 my $dest_name = File::Spec->catfile($ENV{PAR_TEMP}, $extract_name);
1040 # but don't extract it if we've already got one
1041 0 ▶ unless (-e $dest_name)
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dest_name) 0 0 0
1042 {
1043 0 ▶ $member->extractToFileNamed($dest_name) == AZ_OK
Branch: 1 branch
BranchTrueFalseTotal
$member->extractToFileNamed($dest_name) == 0 or die "Can't extract ${member_name}: $!" 0 0 0
1044 or die "Can't extract $member_name: $!";
1045 }
1046 }
1047 }
1048  
1049 # Now push this path into usual library search paths
1050 2 my $separator = $Config{path_sep};
1051 2 my $tempdir = $ENV{PAR_TEMP};
1052 2 foreach my $key (qw(
1053 LD_LIBRARY_PATH
1054 LIB_PATH
1055 LIBRARY_PATH
1056 PATH
1057 DYLD_LIBRARY_PATH
1058 )) {
1059 10 ▶ if (defined $ENV{$key} and $ENV{$key} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{$key} and $ENV{$key} ne '') { } 2 8 10
Condition66%2/3
defined $ENV{$key} and $ENV{$key} ne ""
!ll&&!rl&&r
802
MC/DC50%1/2
defined $ENV{$key} and $ENV{$key} ne ""
defined $ENV{$key} $ENV{$key} ne ""
Truth table66%2/3
A and B
A= defined $ENV{$key}B= $ENV{$key} ne ""
ABresult
0X0
100
111
1060 # Check whether it's already in the path. If so, don't
1061 # append the PAR temp dir in order not to overflow the
1062 # maximum length for ENV vars.
1063 $ENV{$key} .= $separator . $tempdir
1064 2 ▶ unless grep { $_ eq $tempdir } split $separator, $ENV{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $tempdir;} split(/$separator/, $ENV{$key}, 0) 2 0 2
1065 }
1066 else {
1067 8 $ENV{$key} = $tempdir;
1068 }
1069 }
1070 }
1071  
1072 9 $LastAccessedPAR = $zip;
1073  
1074 9 ▶ return @rv unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 4 5 9
1075  
1076 5 ▶ my $member = _first_member($zip,
Branch: 1 branch
BranchTrueFalseTotal
my $member = _first_member($zip, "lib/$file", "arch/$file", "$arch/$file", "$ver/$file", "$ver/$arch/$file", $file) or return 3 2 5
1077 "lib/$file",
1078 "arch/$file",
1079 "$arch/$file",
1080 "$ver/$file",
1081 "$ver/$arch/$file",
1082 $file,
1083 ) or return;
1084  
1085 2 ▶ return $member if $member_only;
Branch: 1 branch
BranchTrueFalseTotal
if $member_only 0 2 2
1086  
1087 (my $fh, $LastTempFile) = _tempfile(
1088 sub {
1089 2 ▶ my $fh = shift;
Subroutine __ANON__: called CC=2 SCAR=7.1
1090 2 my $file = $member->fileName;
1091 2 ▶ $member->extractToFileHandle($fh) == AZ_OK
Branch: 1 branch
BranchTrueFalseTotal
$member->extractToFileHandle($fh) == 0 or die "Can't extract ${file}: $!" 0 2 2
1092 or die "Can't extract $file: $!";
1093 },
1094 2 $member->crc32String . ".pm");
1095  
1096 2 return $fh;
1097 }
1098  
1099 sub _tempfile {
1100 3 ▶ my ($callback, $name) = @_;
Subroutine _tempfile: called CC=10 SCAR=31.5
1101  
1102 3 ▶ if ($ENV{PAR_CLEAN} or !defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PAR_CLEAN"} or not defined $name) 0 3 3
Condition33%1/3
$ENV{"PAR_CLEAN"} or not defined $name
l!l&&r!l&&!r
003
MC/DC0%0/2
$ENV{"PAR_CLEAN"} or not defined $name
$ENV{"PAR_CLEAN"} not defined $name
Truth table33%1/3
A or not(B)
A= $ENV{"PAR_CLEAN"}B= not defined $name
ABresult
1X1
011
000
1103 0 require File::Temp;
1104  
1105 0 ▶ if (defined &File::Temp::tempfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &File::Temp::tempfile) 0 0 0
1106 # under Win32, the file is created with O_TEMPORARY,
1107 # and will be deleted by the C runtime; having File::Temp
1108 # delete it has the only effect of giving ugly warnings
1109 0 ▶ my ($fh, $filename) = File::Temp::tempfile(
Branch: 1 branch
BranchTrueFalseTotal
() = File::Temp::tempfile("DIR", $PAR::SetupTemp::PARTemp, "UNLINK", $^O ne "MSWin32" && !($^O =~ /hpux/)) or die "Cannot create temporary file: $!" 0 0 0
Condition0%0/3
$^O ne 'MSWin32' && !($^O =~ /hpux/)
!ll&&!rl&&r
000
MC/DC0%0/2
$^O ne 'MSWin32' && !($^O =~ /hpux/)
$^O ne 'MSWin32' !($^O =~ /hpux/)
Truth table0%0/3
A && not(B)
A= $^O ne 'MSWin32'B= !($^O =~ /hpux/)
ABresult
0X0
100
111
1110 DIR => $PAR::SetupTemp::PARTemp,
1111 UNLINK => ($^O ne 'MSWin32' and $^O !~ /hpux/),
1112 ) or die "Cannot create temporary file: $!";
1113 0 binmode($fh);
1114 0 $callback->($fh);
1115 0 seek($fh, 0, 0);
1116 0 return ($fh, $filename);
1117 }
1118 }
1119  
1120 3 require File::Spec;
1121  
1122 # untainting tempfile path
1123 3 my ($filename) = File::Spec->catfile($PAR::SetupTemp::PARTemp, $name) =~ /^(.+)$/;
1124  
1125 3 ▶ unless (-r $filename) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $filename) 3 0 3
1126 3 my $tempname = "$filename.$$";
1127  
1128 3 ▶ open my $fh, '>', $tempname or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $tempname or die $! 0 3 3
1129 3 binmode($fh);
1130 3 $callback->($fh);
1131 3 close($fh);
1132  
1133 # FIXME why?
1134 3 ▶ rename($tempname, $filename) or unlink($tempname);
Branch: 1 branch
BranchTrueFalseTotal
rename $tempname, $filename or unlink $tempname 0 3 3
1135 }
1136  
1137 3 ▶ open my $fh, '<', $filename or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die $! 0 3 3
1138 3 binmode($fh);
1139  
1140 3 return ($fh, $filename);
1141 }
1142  
1143 # Given an Archive::Zip object, this generates a hash of
1144 # file_name_in_zip => file object
1145 # and returns a reference to that.
1146 # If we broke the encapsulation of A::Zip::Member and
1147 # accessed $member->{fileName} directly, that would be
1148 # *significantly* faster.
1149 sub _make_file_cache {
1150 4 ▶ my $zip = shift;
Subroutine _make_file_cache: called CC=3 SCAR=11.3
1151 4 ▶ if (not ref($zip)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $zip) 0 4 4
1152 0 croak("_make_file_cache needs an Archive::Zip object as argument.");
1153 }
1154 4 my $cache = {};
1155 4 foreach my $member ($zip->members) {
1156 28 $cache->{$member->fileName()} = $member;
1157 }
1158 4 return $cache;
1159 }
1160  
1161 # given an Archive::Zip object, this finds the cached hash
1162 # of Archive::Zip member names => members,
1163 # and returns all member objects whose file names match
1164 # a regexp
1165 # Without file caching, it just uses $zip->membersMatching
1166 sub _cached_members_matching {
1167 4 ▶ my $zip = shift;
Subroutine _cached_members_matching: called CC=2 SCAR=7.0
1168 4 my $regex = shift;
1169  
1170 4 my $cache = $FileCache{$zip};
1171 4 ▶ $cache = $FileCache{$zip} = _make_file_cache($zip) if not $cache;
Branch: 1 branch
BranchTrueFalseTotal
unless $cache 2 2 4
1172  
1173 0 return map {$cache->{$_}}
1174 4 grep { $_ =~ $regex }
1175 keys %$cache;
1176 }
1177  
1178 # access named zip file member through cache. Fall
1179 # back to using Archive::Zip (slow)
1180 sub _cached_member_named {
1181 23 ▶ my $zip = shift;
Subroutine _cached_member_named: called CC=2 SCAR=7.0
1182 23 my $name = shift;
1183  
1184 23 my $cache = $FileCache{$zip};
1185 23 ▶ $cache = $FileCache{$zip} = _make_file_cache($zip) if not $cache;
Branch: 1 branch
BranchTrueFalseTotal
unless $cache 0 23 23
1186 23 return $cache->{$name};
1187 }
1188  
1189  
1190 # Attempt to clean up the temporary directory if
1191 # --> We're running in clean mode
1192 # --> It's defined
1193 # --> It's an existing directory
1194 # --> It's empty
1195 END {
1196 4 ▶ if (exists $ENV{PAR_CLEAN} and $ENV{PAR_CLEAN}
Subroutine END: called CC=6 SCAR=18.7
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"PAR_CLEAN"} and $ENV{"PAR_CLEAN"} and exists $ENV{"PAR_TEMP"} and defined $ENV{"PAR_TEMP"} and -d $ENV{"PAR_TEMP"}) 2 2 4
Condition66%8/12
exists $ENV{"PAR_CLEAN"} and $ENV{"PAR_CLEAN"} and exists $ENV{"PAR_TEMP"} and defined $ENV{"PAR_TEMP"} and -d $ENV{"PAR_TEMP"}
!ll&&!rl&&r
202
exists $ENV{"PAR_CLEAN"} and $ENV{"PAR_CLEAN"} and exists $ENV{"PAR_TEMP"} and defined $ENV{"PAR_TEMP"}
!ll&&!rl&&r
202
exists $ENV{"PAR_CLEAN"} and $ENV{"PAR_CLEAN"} and exists $ENV{"PAR_TEMP"}
!ll&&!rl&&r
202
exists $ENV{"PAR_CLEAN"} and $ENV{"PAR_CLEAN"}
!ll&&!rl&&r
202
MC/DC20%1/5
exists $ENV{"PAR_CLEAN"} and $ENV{"PAR_CLEAN"} and exists $ENV{"PAR_TEMP"} and defined $ENV{"PAR_TEMP"} and -d $ENV{"PAR_TEMP"}
exists $ENV{"PAR_CLEAN"} $ENV{"PAR_CLEAN"} exists $ENV{"PAR_TEMP"} defined $ENV{"PAR_TEMP"} -d $ENV{"PAR_TEMP"}
Truth table33%2/6
A and B and C and D and E
A= exists $ENV{"PAR_CLEAN"}B= $ENV{"PAR_CLEAN"}C= exists $ENV{"PAR_TEMP"}D= defined $ENV{"PAR_TEMP"}E= -d $ENV{"PAR_TEMP"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1197 and exists $ENV{PAR_TEMP} and defined $ENV{PAR_TEMP} and -d $ENV{PAR_TEMP}
1198 ) {
1199 2 local($!); # paranoid: ignore potential errors without clobbering a global variable!
1200 2 rmdir($ENV{PAR_TEMP});
1201 }
1202 }
1203  
1204 1;
1205  
1206 __END__
↑ Summary PAR/Heavy.pm »