PAR/Heavy.pm

filter: Statementstmt 20.2% 15 / 74 Branchbran 7.1% 4 / 56 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 20.0% 1 / 5 Podpod n/a totaltotal 12.5% 20 / 160 SCAR 67.3
CC
35
Cov
13%
_bootstrap
342.0
_dl_findfile
72.0
_dl_extract
72.0
CRAP 838.8
« PAR.pm ↑ Summary PAR/SetupTemp.pm »
1 package PAR::Heavy;
2 $PAR::Heavy::VERSION = '0.12';
3  
4 =head1 NAME
5  
6 PAR::Heavy - PAR guts
7  
8 =head1 SYNOPSIS
9  
10 (internal use only)
11  
12 =head1 DESCRIPTION
13  
14 No user-serviceable parts inside.
15  
16 =cut
17  
18 ########################################################################
19 # Dynamic inclusion of XS modules
20  
21 # NOTE: Don't "use" any module here, esp. one that is an XS module or
22 # whose "use" could cause the loading of an XS module thru its dependencies.
23  
24 # enable debug/trace messages from DynaLoader perl code
25 my $dl_debug = $ENV{PERL_DL_DEBUG} || 0;
26  
27 my ($bootstrap, $dl_findfile); # Caches for code references
28 my ($cache_key); # The current file to find
29 my $is_insensitive_fs = (
30 -s $0
31 and (-s lc($0) || -1) == (-s uc($0) || -1)
32 and (-s lc($0) || -1) == -s $0
33 );
34  
35 # Adds pre-hooks to Dynaloader's key methods
36 sub _init_dynaloader {
37 7 ▶ return if $bootstrap;
Subroutine _init_dynaloader: called CC=4 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
if $bootstrap 3 4 7
38 4 ▶ return unless eval { require DynaLoader; DynaLoader::dl_findfile(); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require DynaLoader; DynaLoader::dl_findfile(); 1 } } 0 4 4
39  
40 4 ▶ print STDERR "PAR::Heavy: pre-hooks to Dynaloader's key methods\n"
Branch: 1 branch
BranchTrueFalseTotal
if $dl_debug 0 4 4
41 if $dl_debug;
42  
43 4 $bootstrap = \&DynaLoader::bootstrap;
44 4 $dl_findfile = \&DynaLoader::dl_findfile;
45  
46 4 local $^W;
47 4 ▶ *{'DynaLoader::dl_expandspec'} = sub { return };
Subroutine __ANON__: not called CC=1 SCAR=0.4
48 4 *{'DynaLoader::bootstrap'} = \&_bootstrap;
49 4 *{'DynaLoader::dl_findfile'} = \&_dl_findfile;
50 }
51  
52 # Return the cached location of .dll inside PAR first, if possible.
53 sub _dl_findfile {
54 0 ▶ print STDERR "PAR::Heavy::_dl_findfile($cache_key)\n" if $dl_debug;
Subroutine _dl_findfile: not called CC=8 SCAR=42.8
Branch: 1 branch
BranchTrueFalseTotal
if $dl_debug 0 0 0
55  
56 0 ▶ if (exists $FullCache{$cache_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FullCache{$cache_key}) 0 0 0
57 0 ▶ print STDERR " found in FullCache as $FullCache{$cache_key}\n"
Branch: 1 branch
BranchTrueFalseTotal
if $dl_debug 0 0 0
58 if $dl_debug;
59 0 return $FullCache{$cache_key};
60 }
61 0 ▶ if ($is_insensitive_fs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_insensitive_fs) 0 0 0
62 # We have a case-insensitive filesystem...
63 0 my ($key) = grep { lc($_) eq lc($cache_key) } keys %FullCache;
64 0 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 0 0 0
65 0 ▶ print STDERR " found case-insensitively in FullCache as $FullCache{$key}\n"
Branch: 1 branch
BranchTrueFalseTotal
if $dl_debug 0 0 0
66 if $dl_debug;
67 0 return $FullCache{$key};
68 }
69 }
70 0 ▶ print STDERR " fall back to DynaLoader::dl_findfile\n" if $dl_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $dl_debug 0 0 0
71 0 return $dl_findfile->(@_);
72 }
73  
74 # Find and extract .dll from PAR files for a given dynamic module.
75 sub _bootstrap {
76 0 ▶ my (@args) = @_;
Subroutine _bootstrap: not called CC=18 SCAR=58.3
77 0 ▶ my ($module) = $args[0] or return;
Branch: 1 branch
BranchTrueFalseTotal
my($module) = $args[0] or return 0 0 0
78  
79 0 my @modparts = split(/::/, $module);
80 0 my $modfname = $modparts[-1];
81  
82 0 ▶ $modfname = &DynaLoader::mod2fname(\@modparts)
Branch: 1 branch
BranchTrueFalseTotal
if defined &DynaLoader::mod2fname 0 0 0
83 if defined &DynaLoader::mod2fname;
84  
85 0 ▶ if (($^O eq 'NetWare') && (length($modfname) > 8)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "NetWare" and length $modfname > 8) 0 0 0
Condition0%0/3
$^O eq "NetWare" and length $modfname > 8
!ll&&!rl&&r
000
MC/DC0%0/2
$^O eq "NetWare" and length $modfname > 8
$^O eq "NetWare" length $modfname > 8
Truth table0%0/3
A and B
A= $^O eq "NetWare"B= length $modfname > 8
ABresult
0X0
100
111
86 0 $modfname = substr($modfname, 0, 8);
87 }
88  
89 0 ▶ my $modpname = join((($^O eq 'MacOS') ? ':' : '/'), @modparts);
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MacOS' ? : 0 0 0
90 0 my $file = $cache_key = "auto/$modpname/$modfname.$DynaLoader::dl_dlext";
91  
92 0 ▶ if ($FullCache{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FullCache{$file}) 0 0 0
93 # TODO: understand
94 0 local $DynaLoader::do_expand = 1;
95 0 return $bootstrap->(@args);
96 }
97  
98 0 my $member;
99 # First, try to find things in the preferentially loaded PARs:
100 0 ▶ $member = PAR::_find_par_internals([@PAR::PAR_INC], undef, $file, 1)
Branch: 1 branch
BranchTrueFalseTotal
if defined &PAR::_find_par_internals 0 0 0
101 if defined &PAR::_find_par_internals;
102  
103 # If that failed to find the dll, let DynaLoader (try or) throw an error
104 0 ▶ unless ($member) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($member) 0 0 0
105 0 my $filename = eval { $bootstrap->(@args) };
106 0 ▶ return $filename if not $@ and defined $filename;
Branch: 1 branch
BranchTrueFalseTotal
if not $@ and defined $filename 0 0 0
Condition0%0/3
not $@ and defined $filename
!ll&&!rl&&r
000
MC/DC0%0/2
not $@ and defined $filename
not $@ defined $filename
Truth table0%0/3
not(A) and B
A= not $@B= defined $filename
ABresult
0X0
100
111
107  
108 # Now try the fallback pars
109 0 ▶ $member = PAR::_find_par_internals([@PAR::PAR_INC_LAST], undef, $file, 1)
Branch: 1 branch
BranchTrueFalseTotal
if defined &PAR::_find_par_internals 0 0 0
110 if defined &PAR::_find_par_internals;
111  
112 # If that fails, let dynaloader have another go JUST to throw an error
113 # While this may seem wasteful, nothing really matters once we fail to
114 # load shared libraries!
115 0 ▶ unless ($member) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($member) 0 0 0
116 0 return $bootstrap->(@args);
117 }
118 }
119  
120 0 $FullCache{$file} = _dl_extract($member);
121  
122 # Now extract all associated shared objs in the same auto/ dir
123 # XXX: shouldn't this also set $FullCache{...} for those files?
124 0 my $first = $member->fileName;
125 0 my $path_pattern = $first;
126 0 $path_pattern =~ s{[^/]*$}{};
127 0 ▶ if ($PAR::LastAccessedPAR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PAR::LastAccessedPAR) 0 0 0
128 0 foreach my $member ( $PAR::LastAccessedPAR->members ) {
129 0 ▶ next if $member->isDirectory;
Branch: 1 branch
BranchTrueFalseTotal
if $member->isDirectory 0 0 0
130  
131 0 my $name = $member->fileName;
132 0 ▶ next if $name eq $first;
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $first 0 0 0
133 0 ▶ next unless $name =~ m{^/?\Q$path_pattern\E\/[^/]*\.\Q$DynaLoader::dl_dlext\E[^/]*$};
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ m[^/?\Q$path_pattern\E\/[^/]*\.\Q$DynaLoader::dl_dlext\E[^/]*$] 0 0 0
134 0 $name =~ s{.*/}{};
135 0 _dl_extract($member, $name);
136 }
137 }
138  
139 0 local $DynaLoader::do_expand = 1;
140 0 return $bootstrap->(@args);
141 }
142  
143 sub _dl_extract {
144 0 ▶ my ($member, $name) = @_;
Subroutine _dl_extract: not called CC=8 SCAR=42.8
145 0 ▶ $name ||= $member->crc32String . ".$DynaLoader::dl_dlext";
Condition0%0/3
$name ||= $member->crc32String . ".$DynaLoader::dl_dlext"
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= $member->crc32String . ".$DynaLoader::dl_dlext"
$name $member->crc32String . ".$DynaLoader::dl_dlext"
Truth table0%0/3
A ||= B
A= $nameB= $member->crc32String . ".$DynaLoader::dl_dlext"
ABresult
1X1
011
000
146  
147 0 ▶ my $filename = File::Spec->catfile($ENV{PAR_TEMP} || File::Spec->tmpdir, $name);
Condition0%0/3
$ENV{'PAR_TEMP'} || 'File::Spec'->tmpdir
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'PAR_TEMP'} || 'File::Spec'->tmpdir
$ENV{'PAR_TEMP'} 'File::Spec'->tmpdir
Truth table0%0/3
A || B
A= $ENV{'PAR_TEMP'}B= 'File::Spec'->tmpdir
ABresult
1X1
011
000
148 0 ($filename) = $filename =~ /^([\x20-\xff]+)$/;
149  
150 0 ▶ return $filename if -e $filename && -s _ == $member->uncompressedSize;
Branch: 1 branch
BranchTrueFalseTotal
if -e $filename and -s _ == $member->uncompressedSize 0 0 0
Condition0%0/3
-e $filename and -s _ == $member->uncompressedSize
!ll&&!rl&&r
000
MC/DC0%0/2
-e $filename and -s _ == $member->uncompressedSize
-e $filename -s _ == $member->uncompressedSize
Truth table0%0/3
A and B
A= -e $filenameB= -s _ == $member->uncompressedSize
ABresult
0X0
100
111
151  
152 # $filename doesn't exist or hasn't been completely extracted:
153 # extract it under a temporary name that isn't likely to be used
154 # by concurrent processes doing the same
155 0 my $tempname = "$filename.$$";
156 0 ▶ $member->extractToFileNamed($tempname) == Archive::Zip::AZ_OK()
Branch: 1 branch
BranchTrueFalseTotal
$member->extractToFileNamed($tempname) == 0 or die q[Can't extract archive member ] . $member->fileName . " to ${tempname}: $!" 0 0 0
157 or die "Can't extract archive member ".$member->fileName." to $tempname: $!";
158  
159 # now that we have a "good" copy in $tempname, rename it to $filename;
160 # if this fails (e.g. some OSes won't let you delete DLLs that are
161 # in use), but $filename exists, we assume that $filename is also
162 # "good": remove $tempname and return $filename
163 0 ▶ unless (rename($tempname, $filename))
Branch: 1 branch
BranchTrueFalseTotal
unless (rename $tempname, $filename) 0 0 0
164 {
165 0 ▶ -e $filename or die "can't rename $tempname to $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
-e $filename or die "can't rename $tempname to ${filename}: $!" 0 0 0
166 0 unlink($tempname);
167 }
168 0 return $filename;
169 }
170  
171 1;
172  
173 =head1 SEE ALSO
174  
175 L<PAR>
176  
177 =head1 AUTHORS
178  
179 Audrey Tang E<lt>cpan@audreyt.orgE<gt>
180  
181 You can write
182 to the mailing list at E<lt>par@perl.orgE<gt>, or send an empty mail to
183 E<lt>par-subscribe@perl.orgE<gt> to participate in the discussion.
184  
185 Please submit bug reports to E<lt>bug-par@rt.cpan.orgE<gt>.
186  
187 =head1 COPYRIGHT
188  
189 Copyright 2002-2010 by Audrey Tang
190 E<lt>cpan@audreyt.orgE<gt>.
191  
192 Copyright 2006-2010 by Steffen Mueller
193 E<lt>smueller@cpan.orgE<gt>.
194  
195 This program is free software; you can redistribute it and/or modify it
196 under the same terms as Perl itself.
197  
198 See F<LICENSE>.
199  
200 =cut
« PAR.pm ↑ Summary PAR/SetupTemp.pm »