AutoSplit.pm

filter: Statementstmt 82.7% 192 / 232 Branchbran 63.2% 86 / 136 Conditioncond 40.7% 22 / 54 MC/DCmcdc 19.3% 6 / 31 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 4 totaltotal 67.3% 316 / 469 CC 91 SCAR 48.4
CC
91
Cov
71%
autosplit_file
172.0
autosplit_lib_modules
42.0
_check_unique
8.0
CRAP 126.6
↑ Summary AutoLoader.pm »
1 package AutoSplit;
2  
3 9 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use Config qw(%Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use File::Path qw(mkpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use File::Spec::Functions qw(curdir catfile catdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Verbose, $Keep, $Maxlen,
10 $CheckForAutoloader, $CheckModTime);
11  
12 9 $VERSION = "1.06";
13 9 @ISA = qw(Exporter);
14 9 @EXPORT = qw(&autosplit &autosplit_lib_modules);
15 9 @EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime);
16  
17 =head1 NAME
18  
19 AutoSplit - split a package for autoloading
20  
21 =head1 SYNOPSIS
22  
23 autosplit($file, $dir, $keep, $check, $modtime);
24  
25 autosplit_lib_modules(@modules);
26  
27 =head1 DESCRIPTION
28  
29 This function will split up your program into files that the AutoLoader
30 module can handle. It is used by both the standard perl libraries and by
31 the MakeMaker utility, to automatically configure libraries for autoloading.
32  
33 The C<autosplit> interface splits the specified file into a hierarchy
34 rooted at the directory C<$dir>. It creates directories as needed to reflect
35 class hierarchy, and creates the file F<autosplit.ix>. This file acts as
36 both forward declaration of all package routines, and as timestamp for the
37 last update of the hierarchy.
38  
39 The remaining three arguments to C<autosplit> govern other options to
40 the autosplitter.
41  
42 =over 2
43  
44 =item $keep
45  
46 If the third argument, I<$keep>, is false, then any
47 pre-existing C<*.al> files in the autoload directory are removed if
48 they are no longer part of the module (obsoleted functions).
49 $keep defaults to 0.
50  
51 =item $check
52  
53 The
54 fourth argument, I<$check>, instructs C<autosplit> to check the module
55 currently being split to ensure that it includes a C<use>
56 specification for the AutoLoader module, and skips the module if
57 AutoLoader is not detected.
58 $check defaults to 1.
59  
60 =item $modtime
61  
62 Lastly, the I<$modtime> argument specifies
63 that C<autosplit> is to check the modification time of the module
64 against that of the C<autosplit.ix> file, and only split the module if
65 it is newer.
66 $modtime defaults to 1.
67  
68 =back
69  
70 Typical use of AutoSplit in the perl MakeMaker utility is via the command-line
71 with:
72  
73 perl -e 'use AutoSplit; autosplit($ARGV[0], $ARGV[1], 0, 1, 1)'
74  
75 Defined as a Make macro, it is invoked with file and directory arguments;
76 C<autosplit> will split the specified file into the specified directory and
77 delete obsolete C<.al> files, after checking first that the module does use
78 the AutoLoader, and ensuring that the module is not already currently split
79 in its current form (the modtime test).
80  
81 The C<autosplit_lib_modules> form is used in the building of perl. It takes
82 as input a list of files (modules) that are assumed to reside in a directory
83 B<lib> relative to the current directory. Each file is sent to the
84 autosplitter one at a time, to be split into the directory B<lib/auto>.
85  
86 In both usages of the autosplitter, only subroutines defined following the
87 perl I<__END__> token are split out into separate files. Some
88 routines may be placed prior to this marker to force their immediate loading
89 and parsing.
90  
91 =head2 Multiple packages
92  
93 As of version 1.01 of the AutoSplit module it is possible to have
94 multiple packages within a single file. Both of the following cases
95 are supported:
96  
97 package NAME;
98 __END__
99 sub AAA { ... }
100 package NAME::option1;
101 sub BBB { ... }
102 package NAME::option2;
103 sub BBB { ... }
104  
105 package NAME;
106 __END__
107 sub AAA { ... }
108 sub NAME::option1::BBB { ... }
109 sub NAME::option2::BBB { ... }
110  
111 =head1 DIAGNOSTICS
112  
113 C<AutoSplit> will inform the user if it is necessary to create the
114 top-level directory specified in the invocation. It is preferred that
115 the script or installation process that invokes C<AutoSplit> have
116 created the full directory path ahead of time. This warning may
117 indicate that the module is being split into an incorrect path.
118  
119 C<AutoSplit> will warn the user of all subroutines whose name causes
120 potential file naming conflicts on machines with drastically limited
121 (8 characters or less) file name length. Since the subroutine name is
122 used as the file name, these warnings can aid in portability to such
123 systems.
124  
125 Warnings are issued and the file skipped if C<AutoSplit> cannot locate
126 either the I<__END__> marker or a "package Name;"-style specification.
127  
128 C<AutoSplit> will also emit general diagnostics for inability to
129 create directories or files.
130  
131 =head1 AUTHOR
132  
133 C<AutoSplit> is maintained by the perl5-porters. Please direct
134 any questions to the canonical mailing list. Anything that
135 is applicable to the CPAN release can be sent to its maintainer,
136 though.
137  
138 Author and Maintainer: The Perl5-Porters <perl5-porters@perl.org>
139  
140 Maintainer of the CPAN release: Steffen Mueller <smueller@cpan.org>
141  
142 =head1 COPYRIGHT AND LICENSE
143  
144 This package has been part of the perl core since the first release
145 of perl5. It has been released separately to CPAN so older installations
146 can benefit from bug fixes.
147  
148 This package has the same copyright and license as the perl core:
149  
150 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
151 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
152 by Larry Wall and others
153
154 All rights reserved.
155
156 This program is free software; you can redistribute it and/or modify
157 it under the terms of either:
158
159 a) the GNU General Public License as published by the Free
160 Software Foundation; either version 1, or (at your option) any
161 later version, or
162
163 b) the "Artistic License" which comes with this Kit.
164
165 This program is distributed in the hope that it will be useful,
166 but WITHOUT ANY WARRANTY; without even the implied warranty of
167 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
168 the GNU General Public License or the Artistic License for more details.
169
170 You should have received a copy of the Artistic License with this
171 Kit, in the file named "Artistic". If not, I'll be glad to provide one.
172
173 You should also have received a copy of the GNU General Public License
174 along with this program in the file named "Copying". If not, write to the
175 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
176 02111-1307, USA or visit their web page on the internet at
177 http://www.gnu.org/copyleft/gpl.html.
178
179 For those of you that choose to use the GNU General Public License,
180 my interpretation of the GNU General Public License is that no Perl
181 script falls under the terms of the GPL unless you explicitly put
182 said script under the terms of the GPL yourself. Furthermore, any
183 object code linked with perl does not automatically fall under the
184 terms of the GPL, provided such object code only adds definitions
185 of subroutines and variables, and does not otherwise impair the
186 resulting interpreter from executing any standard Perl script. I
187 consider linking in C subroutines in this manner to be the moral
188 equivalent of defining subroutines in the Perl language itself. You
189 may sell such an object file as proprietary provided that you provide
190 or offer to provide the Perl source, as specified by the GNU General
191 Public License. (This is merely an alternate way of specifying input
192 to the program.) You may also sell a binary produced by the dumping of
193 a running Perl script that belongs to you, provided that you provide or
194 offer to provide the Perl source as specified by the GPL. (The
195 fact that a Perl interpreter and your code are in the same binary file
196 is, in this case, a form of mere aggregation.) This is my interpretation
197 of the GPL. If you still have concerns or difficulties understanding
198 my intent, feel free to contact me. Of course, the Artistic License
199 spells all this out for your protection, so you may prefer to use that.
200  
201 =cut
202  
203 # for portability warn about names longer than $maxlen
204 9 $Maxlen = 8; # 8 for dos, 11 (14-".al") for SYSVR3
205 9 $Verbose = 1; # 0=none, 1=minimal, 2=list .al files
206 9 $Keep = 0;
207 9 $CheckForAutoloader = 1;
208 9 $CheckModTime = 1;
209  
210 9 my $IndexFile = "autosplit.ix"; # file also serves as timestamp
211 9 my $maxflen = 255;
212 9 ▶$maxflen = 14 if $Config{'d_flexfnam'} ne 'define';
Branch: 1 branch
BranchTrueFalseTotal
if $AutoSplit::Config{"d_flexfnam"} ne "define" 0 9 9
213 9 ▶if (defined (&Dos::UseLFN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Dos::UseLFN) 0 9 9
214 0 ▶ $maxflen = Dos::UseLFN() ? 255 : 11;
Branch: 1 branch
BranchTrueFalseTotal
Dos::UseLFN() ? : 0 0 0
215 }
216 9 my $Is_VMS = ($^O eq 'VMS');
217  
218 # allow checking for valid ': attrlist' attachments.
219 # extra jugglery required to support both 5.8 and 5.9/5.10 features
220 # (support for 5.8 required for cross-compiling environments)
221  
222 my $attr_list =
223 $] >= 5.009005 ?
224 eval <<'__QR__'
225 qr{
226 \s* : \s*
227 (?:
228 # one attribute
229 (?> # no backtrack
230 (?! \d) \w+
231 (?<nested> \( (?: [^()]++ | (?&nested)++ )*+ \) ) ?
232 )
233 (?: \s* : \s* | \s+ (?! :) )
234 )*
235 }x
236 __QR__
237 :
238 9 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$] >= 5.009005 ? : 9 0 9
239 # In pre-5.9.5 world we have to do dirty tricks.
240 # (we use 'our' rather than 'my' here, due to the rather complex and buggy
241 # behaviour of lexicals with qr// and (??{$lex}) )
242 0 our $trick1; # yes, cannot our and assign at the same time.
243 0 $trick1 = qr{ \( (?: (?> [^()]+ ) | (??{ $trick1 }) )* \) }x;
244 0 our $trick2 = qr{ (?> (?! \d) \w+ (?:$trick1)? ) (?:\s*\:\s*|\s+(?!\:)) }x;
245 0 qr{ \s* : \s* (?: $trick2 )* }x;
246 };
247  
248 8 ▶sub autosplit{
Subroutine autosplit: called CC=4 SCAR=13.9
Pod undocumented
249 8 my($file, $autodir, $keep, $ckal, $ckmt) = @_;
250 # $file - the perl source file to be split (after __END__)
251 # $autodir - the ".../auto" dir below which to write split subs
252 # Handle optional flags:
253 8 ▶ $keep = $Keep unless defined $keep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keep 4 4 8
254 8 ▶ $ckal = $CheckForAutoloader unless defined $ckal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ckal 4 4 8
255 8 ▶ $ckmt = $CheckModTime unless defined $ckmt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ckmt 6 2 8
256 8 autosplit_file($file, $autodir, $keep, $ckal, $ckmt);
257 }
258  
259 0 ▶sub carp{
Subroutine carp: not called CC=1 SCAR=6.9
Pod undocumented
260 0 require Carp;
261 0 goto &Carp::carp;
262 }
263  
264 # This function is used during perl building/installation
265 # ./miniperl -e 'use AutoSplit; autosplit_lib_modules(@ARGV)' ...
266  
267 0 ▶sub autosplit_lib_modules {
Subroutine autosplit_lib_modules: not called CC=6 SCAR=37.4
Pod undocumented
268 0 my(@modules) = @_; # list of Module names
269 0 local $_; # Avoid clobber.
270 0 ▶ while (defined($_ = shift @modules)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = shift @modules)) 0 0 0
271 0 ▶ while (m#([^:]+)::([^:].*)#) { # in case specified as ABC::XYZ
Branch: 1 branch
BranchTrueFalseTotal
if (/([^:]+)::([^:].*)/) 0 0 0
272 0 $_ = catfile($1, $2);
273 }
274 0 s|\\|/|g; # bug in ksh OS/2
275 0 s#^lib/##s; # incase specified as lib/*.pm
276 0 my($lib) = catfile(curdir(), "lib");
277 0 ▶ if ($Is_VMS) { # may need to convert VMS-style filespecs
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) 0 0 0
278 0 $lib =~ s#^\[\]#.\/#;
279 }
280 0 s#^$lib\W+##s; # incase specified as ./lib/*.pm
281 0 ▶ if ($Is_VMS && /[:>\]]/) { # may need to convert VMS-style filespecs
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS and /[:>\]]/) 0 0 0
Condition0%0/3
$Is_VMS and /[:>\]]/
!ll&&!rl&&r
000
MC/DC0%0/2
$Is_VMS and /[:>\]]/
$Is_VMS /[:>\]]/
Truth table0%0/3
A and B
A= $Is_VMSB= /[:>\]]/
ABresult
0X0
100
111
282 0 my ($dir,$name) = (/(.*])(.*)/s);
283 0 $dir =~ s/.*lib[\.\]]//s;
284 0 $dir =~ s#[\.\]]#/#g;
285 0 $_ = $dir . $name;
286 }
287 0 autosplit_file(catfile($lib, $_), catfile($lib, "auto"),
288 $Keep, $CheckForAutoloader, $CheckModTime);
289 }
290 0 0;
291 }
292  
293  
294 # private functions
295  
296 9 my $self_mod_time = (stat __FILE__)[9];
297  
298 8 ▶sub autosplit_file {
Subroutine autosplit_file: called CC=73 SCAR=51.5
Pod undocumented
299 8 my($filename, $autodir, $keep, $check_for_autoloader, $check_mod_time)
300 = @_;
301 8 my(@outfiles);
302 8 local($_);
303 8 local($/) = "\n";
304  
305 # where to write output files
306 8 ▶ $autodir ||= catfile(curdir(), "lib", "auto");
Condition33%1/3
$autodir ||= catfile(".", "lib", "auto")
l!l&&r!l&&!r
800
MC/DC0%0/2
$autodir ||= catfile(".", "lib", "auto")
$autodir catfile(".", "lib", "auto")
Truth table33%1/3
A ||= B
A= $autodirB= catfile(".", "lib", "auto")
ABresult
1X1
011
000
307 8 ▶ if ($Is_VMS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) 0 8 8
308 0 ($autodir = VMS::Filespec::unixpath($autodir)) =~ s|/\z||;
309 0 $filename = VMS::Filespec::unixify($filename); # may have dirs
310 }
311 8 ▶ unless (-d $autodir){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $autodir) 1 7 8
312 1 mkpath($autodir,0,0755);
313 # We should never need to create the auto dir
314 # here. installperl (or similar) should have done
315 # it. Expecting it to exist is a valuable sanity check against
316 # autosplitting into some random directory by mistake.
317 1 print "Warning: AutoSplit had to create top-level " .
318 "$autodir unexpectedly.\n";
319 }
320  
321 # allow just a package name to be used
322 8 ▶ $filename .= ".pm" unless ($filename =~ m/\.pm\z/);
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ /\.pm\z/ 0 8 8
323  
324 8 ▶ open(my $in, "<$filename") or die "AutoSplit: Can't open $filename: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<$filename" or die "AutoSplit: Can't open ${filename}: $!\n" 8 0 8
325 8 my($pm_mod_time) = (stat($filename))[9];
326 8 my($autoloader_seen) = 0;
327 8 my($in_pod) = 0;
328 8 my($def_package,$last_package,$this_package,$fnr);
329 8 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 34 0 34
330 # Skip pod text.
331 34 $fnr++;
332 34 ▶ $in_pod = 1 if /^=\w/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=\w/ 0 34 34
333 34 ▶ $in_pod = 0 if /^=cut/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=cut/ 0 34 34
334 34 ▶ next if ($in_pod || /^=cut/);
Branch: 1 branch
BranchTrueFalseTotal
if $in_pod or /^=cut/ 0 34 34
Condition33%1/3
$in_pod or /^=cut/
l!l&&r!l&&!r
0034
MC/DC0%0/2
$in_pod or /^=cut/
$in_pod /^=cut/
Truth table33%1/3
A or B
A= $in_podB= /^=cut/
ABresult
1X1
011
000
335 34 ▶ next if /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*#/ 0 34 34
336  
337 # record last package name seen
338 34 ▶ $def_package = $1 if (m/^\s*package\s+([\w:]+)\s*;/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*package\s+([\w:]+)\s*;/ 8 26 34
339 34 ▶ ++$autoloader_seen if m/^\s*(use|require)\s+AutoLoader\b/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*(use|require)\s+AutoLoader\b/ 7 27 34
340 34 ▶ ++$autoloader_seen if m/\bISA\s*=.*\bAutoLoader\b/;
Branch: 1 branch
BranchTrueFalseTotal
if /\bISA\s*=.*\bAutoLoader\b/ 1 33 34
341 34 ▶ last if /^__END__/;
Branch: 1 branch
BranchTrueFalseTotal
if /^__END__/ 8 26 34
342 }
343 8 ▶ if ($check_for_autoloader && !$autoloader_seen){
Branch: 1 branch
BranchTrueFalseTotal
if ($check_for_autoloader and not $autoloader_seen) 1 7 8
Condition100%3/3
$check_for_autoloader and not $autoloader_seen
!ll&&!rl&&r
161
MC/DC100%2/2
$check_for_autoloader and not $autoloader_seen
$check_for_autoloader not $autoloader_seen
Truth table100%3/3
A and not(B)
A= $check_for_autoloaderB= not $autoloader_seen
ABresult
0X0
100
111
344 1 ▶ print "AutoSplit skipped $filename: no AutoLoader used\n"
Branch: 1 branch
BranchTrueFalseTotal
if $AutoSplit::Verbose >= 2 0 1 1
345 if ($Verbose>=2);
346 1 return 0;
347 }
348 7 ▶ $_ or die "Can't find __END__ in $filename\n";
Branch: 1 branch
BranchTrueFalseTotal
$_ or die "Can't find __END__ in $filename\n" 7 0 7
349  
350 7 ▶ $def_package or die "Can't find 'package Name;' in $filename\n";
Branch: 1 branch
BranchTrueFalseTotal
$def_package or die "Can't find 'package Name;' in $filename\n" 7 0 7
351  
352 7 my($modpname) = _modpname($def_package);
353  
354 # this _has_ to match so we have a reasonable timestamp file
355 7 ▶ die "Package $def_package ($modpname.pm) does not ".
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ /\Q$modpname.pm\E$/ or $^O eq "dos" or $^O eq "MSWin32" or $^O eq "NetWare" or $Is_VMS and $filename =~ /$modpname.pm/i 0 7 7
Condition26%4/15
$filename =~ /\Q$modpname.pm\E$/ or $^O eq "dos" or $^O eq "MSWin32" or $^O eq "NetWare" or $Is_VMS and $filename =~ /$modpname.pm/i
l!l&&r!l&&!r
700
$filename =~ /\Q$modpname.pm\E$/ or $^O eq "dos" or $^O eq "MSWin32" or $^O eq "NetWare"
l!l&&r!l&&!r
700
$filename =~ /\Q$modpname.pm\E$/ or $^O eq "dos" or $^O eq "MSWin32"
l!l&&r!l&&!r
700
$filename =~ /\Q$modpname.pm\E$/ or $^O eq "dos"
l!l&&r!l&&!r
700
$Is_VMS and $filename =~ /$modpname.pm/i
!ll&&!rl&&r
000
MC/DC0%0/6
$filename =~ /\Q$modpname.pm\E$/ or $^O eq "dos" or $^O eq "MSWin32" or $^O eq "NetWare" or $Is_VMS and $filename =~ /$modpname.pm/i
$filename =~ /\Q$modpname.pm\E$/ $^O eq "dos" $^O eq "MSWin32" $^O eq "NetWare" $Is_VMS $filename =~ /$modpname.pm/i
Truth table14%1/7
A or B or C or D or E and F
A= $filename =~ /\Q$modpname.pm\E$/B= $^O eq "dos"C= $^O eq "MSWin32"D= $^O eq "NetWare"E= $Is_VMSF= $filename =~ /$modpname.pm/i
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
0000111
00000X0
0000100
356 "match filename $filename"
357 unless ($filename =~ m/\Q$modpname.pm\E$/ or
358 ($^O eq 'dos') or ($^O eq 'MSWin32') or ($^O eq 'NetWare') or
359 $Is_VMS && $filename =~ m/$modpname.pm/i);
360  
361 7 my($al_idx_file) = catfile($autodir, $modpname, $IndexFile);
362  
363 7 ▶ if ($check_mod_time){
Branch: 1 branch
BranchTrueFalseTotal
if ($check_mod_time) 6 1 7
364 6 ▶ my($al_ts_time) = (stat("$al_idx_file"))[9] || 1;
Condition100%2/2
(stat "$al_idx_file")[9] || 1
l!l
33
MC/DC100%1/1
(stat "$al_idx_file")[9] || 1
(stat "$al_idx_file")[9]
Truth table100%2/2
A
A= (stat "$al_idx_file")[9]
Aresult
11
00
365 6 ▶ if ($al_ts_time >= $pm_mod_time and
Branch: 1 branch
BranchTrueFalseTotal
if ($al_ts_time >= $pm_mod_time and $al_ts_time >= $self_mod_time) 1 5 6
Condition66%2/3
$al_ts_time >= $pm_mod_time and $al_ts_time >= $self_mod_time
!ll&&!rl&&r
501
MC/DC50%1/2
$al_ts_time >= $pm_mod_time and $al_ts_time >= $self_mod_time
$al_ts_time >= $pm_mod_time $al_ts_time >= $self_mod_time
Truth table66%2/3
A and B
A= $al_ts_time >= $pm_mod_timeB= $al_ts_time >= $self_mod_time
ABresult
0X0
100
111
366 $al_ts_time >= $self_mod_time){
367 1 ▶ print "AutoSplit skipped ($al_idx_file newer than $filename)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $AutoSplit::Verbose >= 2 0 1 1
368 if ($Verbose >= 2);
369 1 return undef; # one undef, not a list
370 }
371 }
372  
373 6 my($modnamedir) = catdir($autodir, $modpname);
374 6 ▶ print "AutoSplitting $filename ($modnamedir)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $AutoSplit::Verbose 6 0 6
375 if $Verbose;
376  
377 6 ▶ unless (-d $modnamedir){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $modnamedir) 3 3 6
378 3 mkpath($modnamedir,0,0777);
379 }
380  
381 # We must try to deal with some SVR3 systems with a limit of 14
382 # characters for file names. Sadly we *cannot* simply truncate all
383 # file names to 14 characters on these systems because we *must*
384 # create filenames which exactly match the names used by AutoLoader.pm.
385 # This is a problem because some systems silently truncate the file
386 # names while others treat long file names as an error.
387  
388 6 my $Is83 = $maxflen==11; # plain, case INSENSITIVE dos filenames
389  
390 6 my(@subnames, $subname, %proto, %package);
391 6 my @cache = ();
392 6 my $caching = 1;
393 6 $last_package = '';
394 6 my $out;
395 6 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 25 6 31
396 25 $fnr++;
397 25 ▶ $in_pod = 1 if /^=\w/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=\w/ 0 25 25
398 25 ▶ $in_pod = 0 if /^=cut/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=cut/ 0 25 25
399 25 ▶ next if ($in_pod || /^=cut/);
Branch: 1 branch
BranchTrueFalseTotal
if $in_pod or /^=cut/ 0 25 25
Condition33%1/3
$in_pod or /^=cut/
l!l&&r!l&&!r
0025
MC/DC0%0/2
$in_pod or /^=cut/
$in_pod /^=cut/
Truth table33%1/3
A or B
A= $in_podB= /^=cut/
ABresult
1X1
011
000
400 # the following (tempting) old coding gives big troubles if a
401 # cut is forgotten at EOF:
402 # next if /^=\w/ .. /^=cut/;
403 25 ▶ if (/^package\s+([\w:]+)\s*;/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^package\s+([\w:]+)\s*;/) 2 23 25
404 2 $this_package = $def_package = $1;
405 }
406  
407 25 ▶ if (/^sub\s+([\w:]+)(\s*(?:\(.*?\))?(?:$attr_list)?)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^sub\s+([\w:]+)(\s*(?:\(.*?\))?(?:$attr_list)?)/) 22 3 25
408 22 ▶ print $out "# end of $last_package\::$subname\n1;\n"
Branch: 1 branch
BranchTrueFalseTotal
if $last_package 17 5 22
409 if $last_package;
410 22 $subname = $1;
411 22 ▶ my $proto = $2 || '';
Condition50%1/2
$2 || ''
l!l
220
MC/DC0%0/1
$2 || ''
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
412 22 ▶ if ($subname =~ s/(.*):://){
Branch: 1 branch
BranchTrueFalseTotal
if ($subname =~ s/(.*):://) { } 1 21 22
413 1 $this_package = $1;
414 } else {
415 21 $this_package = $def_package;
416 }
417 22 my $fq_subname = "$this_package\::$subname";
418 22 $package{$fq_subname} = $this_package;
419 22 $proto{$fq_subname} = $proto;
420 22 push(@subnames, $fq_subname);
421 22 my($lname, $sname) = ($subname, substr($subname,0,$maxflen-3));
422 22 $modpname = _modpname($this_package);
423 22 my($modnamedir) = catdir($autodir, $modpname);
424 22 mkpath($modnamedir,0,0777);
425 22 my($lpath) = catfile($modnamedir, "$lname.al");
426 22 my($spath) = catfile($modnamedir, "$sname.al");
427 22 my $path;
428  
429 22 ▶ if (!$Is83 and open($out, ">$lpath")){
Branch: 1 branch
BranchTrueFalseTotal
if (not $Is83 and open $out, ">$lpath") { } 22 0 22
Condition33%1/3
not $Is83 and open $out, ">$lpath"
!ll&&!rl&&r
0022
MC/DC0%0/2
not $Is83 and open $out, ">$lpath"
not $Is83 open $out, ">$lpath"
Truth table33%1/3
not(A) and B
A= not $Is83B= open $out, ">$lpath"
ABresult
0X0
100
111
430 22 $path=$lpath;
431 22 ▶ print " writing $lpath\n" if ($Verbose>=2);
Branch: 1 branch
BranchTrueFalseTotal
if $AutoSplit::Verbose >= 2 0 22 22
432 } else {
433 0 ▶ open($out, ">$spath") or die "Can't create $spath: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $out, ">$spath" or die "Can't create ${spath}: $!\n" 0 0 0
434 0 $path=$spath;
435 0 ▶ print " writing $spath (with truncated name)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $AutoSplit::Verbose >= 1 0 0 0
436 if ($Verbose>=1);
437 }
438 22 push(@outfiles, $path);
439 22 my $lineno = $fnr - @cache;
440 22 print $out <<EOT;
441 # NOTE: Derived from $filename.
442 # Changes made here will be lost when autosplit is run again.
443 # See AutoSplit.pm.
444 package $this_package;
445  
446 #line $lineno "$filename (autosplit into $path)"
447 EOT
448 22 print $out @cache;
449 22 @cache = ();
450 22 $caching = 0;
451 }
452 25 ▶ if($caching) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caching) { } 0 25 25
453 0 ▶ push(@cache, $_) if @cache || /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if @cache or /\S/ 0 0 0
Condition0%0/3
@cache or /\S/
l!l&&r!l&&!r
000
MC/DC0%0/2
@cache or /\S/
@cache /\S/
Truth table0%0/3
A or B
A= @cacheB= /\S/
ABresult
1X1
011
000
454 } else {
455 25 print $out $_;
456 }
457 25 ▶ if(/^\}/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\}/) 0 25 25
458 0 ▶ if($caching) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caching) 0 0 0
459 0 print $out @cache;
460 0 @cache = ();
461 }
462 0 print $out "\n";
463 0 $caching = 1;
464 }
465 25 ▶ $last_package = $this_package if defined $this_package;
Branch: 1 branch
BranchTrueFalseTotal
if defined $this_package 25 0 25
466 }
467 6 ▶ if ($subname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subname) 5 1 6
468 5 print $out @cache,"1;\n# end of $last_package\::$subname\n";
469 5 close($out);
470 }
471 6 close($in);
472
473 6 ▶ if (!$keep){ # don't keep any obsolete *.al files in the directory
Branch: 1 branch
BranchTrueFalseTotal
unless ($keep) 5 1 6
474 5 my(%outfiles);
475 # @outfiles{@outfiles} = @outfiles;
476 # perl downcases all filenames on VMS (which upcases all filenames) so
477 # we'd better downcase the sub name list too, or subs with upper case
478 # letters in them will get their .al files deleted right after they're
479 # created. (The mixed case sub name won't match the all-lowercase
480 # filename, and so be cleaned up as a scrap file)
481 5 ▶ if ($Is_VMS or $Is83) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS or $Is83) { } 0 5 5
Condition33%1/3
$Is_VMS or $Is83
l!l&&r!l&&!r
005
MC/DC0%0/2
$Is_VMS or $Is83
$Is_VMS $Is83
Truth table33%1/3
A or B
A= $Is_VMSB= $Is83
ABresult
1X1
011
000
482 0 %outfiles = map {lc($_) => lc($_) } @outfiles;
483 } else {
484 5 @outfiles{@outfiles} = @outfiles;
485 }
486 5 my(%outdirs,@outdirs);
487 5 for (@outfiles) {
488 20 ▶ $outdirs{File::Basename::dirname($_)}||=1;
Condition100%2/2
$outdirs{File::Basename::dirname($_)} ||= 1
l!l
137
MC/DC100%1/1
$outdirs{File::Basename::dirname($_)} ||= 1
$outdirs{File::Basename::dirname($_)}
Truth table100%2/2
A
A= $outdirs{File::Basename::dirname($_)}
Aresult
11
00
489 }
490 5 for my $dir (keys %outdirs) {
491 7 opendir(my $outdir,$dir);
492 7 foreach (sort readdir($outdir)){
493 42 ▶ next unless /\.al\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.al\z/ 16 26 42
494 26 my($file) = catfile($dir, $_);
495 26 ▶ $file = lc $file if $Is83 or $Is_VMS;
Branch: 1 branch
BranchTrueFalseTotal
if $Is83 or $Is_VMS 0 26 26
Condition33%1/3
$Is83 or $Is_VMS
l!l&&r!l&&!r
0026
MC/DC0%0/2
$Is83 or $Is_VMS
$Is83 $Is_VMS
Truth table33%1/3
A or B
A= $Is83B= $Is_VMS
ABresult
1X1
011
000
496 26 ▶ next if $outfiles{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $outfiles{$file} 20 6 26
497 6 ▶ print " deleting $file\n" if ($Verbose>=2);
Branch: 1 branch
BranchTrueFalseTotal
if $AutoSplit::Verbose >= 2 0 6 6
498 6 my($deleted,$thistime); # catch all versions on VMS
499 6 ▶ do { $deleted += ($thistime = unlink $file) } while ($thistime);
Branch: 1 branch
BranchTrueFalseTotal
$thistime and do { do { $deleted += ($thistime = unlink($file)) } } 6 6 12
500 6 ▶ carp ("Unable to delete $file: $!") unless $deleted;
Branch: 1 branch
BranchTrueFalseTotal
unless $deleted 0 6 6
501 }
502 7 closedir($outdir);
503 }
504 }
505  
506 6 ▶ open(my $ts,">$al_idx_file") or
Branch: 1 branch
BranchTrueFalseTotal
open my $ts, ">$al_idx_file" or carp("AutoSplit: unable to create timestamp file ($al_idx_file): $!") 6 0 6
507 carp ("AutoSplit: unable to create timestamp file ($al_idx_file): $!");
508 6 print $ts "# Index created by AutoSplit for $filename\n";
509 6 print $ts "# (file acts as timestamp)\n";
510 6 $last_package = '';
511 6 for my $fqs (@subnames) {
512 22 my($subname) = $fqs;
513 22 $subname =~ s/.*:://;
514 print $ts "package $package{$fqs};\n"
515 22 ▶ unless $last_package eq $package{$fqs};
Branch: 1 branch
BranchTrueFalseTotal
unless $last_package eq $package{$fqs} 9 13 22
516 22 print $ts "sub $subname $proto{$fqs};\n";
517 22 $last_package = $package{$fqs};
518 }
519 6 print $ts "1;\n";
520 6 close($ts);
521  
522 6 _check_unique($filename, $Maxlen, 1, @outfiles);
523  
524 6 @outfiles;
525 }
526  
527 29 ▶sub _modpname ($) {
Subroutine _modpname: called CC=4 SCAR=14.3
528 29 my($package) = @_;
529 29 my $modpname = $package;
530 29 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 29 29
531 0 $modpname =~ s#::#\\#g;
532 } else {
533 29 my @modpnames = ();
534 29 ▶ while ($modpname =~ m#(.*?[^:])::([^:].*)#) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modpname =~ /(.*?[^:])::([^:].*)/) 9 29 38
535 9 push @modpnames, $1;
536 9 $modpname = $2;
537 }
538 29 $modpname = catfile(@modpnames, $modpname);
539 }
540 29 ▶ if ($Is_VMS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) 0 29 29
541 0 $modpname = VMS::Filespec::unixify($modpname); # may have dirs
542 }
543 29 $modpname;
544 }
545  
546 6 ▶sub _check_unique {
Subroutine _check_unique: called CC=8 SCAR=20.8
547 6 my($filename, $maxlen, $warn, @outfiles) = @_;
548 6 my(%notuniq) = ();
549 6 my(%shorts) = ();
550 6 my(@toolong) = grep(
551 length(File::Basename::basename($_))
552 > $maxlen,
553 @outfiles
554 );
555  
556 6 foreach (@toolong){
557 13 my($dir) = File::Basename::dirname($_);
558 13 my($file) = File::Basename::basename($_);
559 13 my($trunc) = substr($file,0,$maxlen);
560 13 ▶ $notuniq{$dir}{$trunc} = 1 if $shorts{$dir}{$trunc};
Branch: 1 branch
BranchTrueFalseTotal
if $shorts{$dir}{$trunc} 2 11 13
561 13 ▶ $shorts{$dir}{$trunc} = $shorts{$dir}{$trunc} ?
Branch: 1 branch
BranchTrueFalseTotal
$shorts{$dir}{$trunc} ? : 2 11 13
562 "$shorts{$dir}{$trunc}, $file" : $file;
563 }
564 6 ▶ if (%notuniq && $warn){
Branch: 1 branch
BranchTrueFalseTotal
if (%notuniq and $warn) 1 5 6
Condition66%2/3
%notuniq and $warn
!ll&&!rl&&r
501
MC/DC50%1/2
%notuniq and $warn
%notuniq $warn
Truth table66%2/3
A and B
A= %notuniqB= $warn
ABresult
0X0
100
111
565 1 print "$filename: some names are not unique when " .
566 "truncated to $maxlen characters:\n";
567 1 foreach my $dir (sort keys %notuniq){
568 2 print " directory $dir:\n";
569 2 foreach my $trunc (sort keys %{$notuniq{$dir}}) {
570 2 print " $shorts{$dir}{$trunc} truncate to $trunc\n";
571 }
572 }
573 }
574 }
575  
576 9 1;
577 __END__
↑ Summary AutoLoader.pm »