PAR.pm

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