Commit | Line | Data |
a0d0e21e |
1 | package AutoSplit; |
2 | |
3b825e41 |
3 | use 5.006_001; |
4e6ea2c3 |
4 | use Exporter (); |
5 | use Config qw(%Config); |
6 | use Carp qw(carp); |
7 | use File::Basename (); |
68dc0745 |
8 | use File::Path qw(mkpath); |
64a3d80f |
9 | use File::Spec::Functions qw(curdir catfile catdir); |
4e6ea2c3 |
10 | use strict; |
17f410f9 |
11 | our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Verbose, $Keep, $Maxlen, |
12 | $CheckForAutoloader, $CheckModTime); |
a0d0e21e |
13 | |
88d01e8d |
14 | $VERSION = "1.0307"; |
a0d0e21e |
15 | @ISA = qw(Exporter); |
16 | @EXPORT = qw(&autosplit &autosplit_lib_modules); |
3edbfbe5 |
17 | @EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime); |
a0d0e21e |
18 | |
f06db76b |
19 | =head1 NAME |
20 | |
21 | AutoSplit - split a package for autoloading |
22 | |
cb1a09d0 |
23 | =head1 SYNOPSIS |
24 | |
4e6ea2c3 |
25 | autosplit($file, $dir, $keep, $check, $modtime); |
84dc3c4d |
26 | |
4e6ea2c3 |
27 | autosplit_lib_modules(@modules); |
cb1a09d0 |
28 | |
f06db76b |
29 | =head1 DESCRIPTION |
30 | |
31 | This function will split up your program into files that the AutoLoader |
21c92a1d |
32 | module can handle. It is used by both the standard perl libraries and by |
33 | the MakeMaker utility, to automatically configure libraries for autoloading. |
34 | |
35 | The C<autosplit> interface splits the specified file into a hierarchy |
36 | rooted at the directory C<$dir>. It creates directories as needed to reflect |
37 | class hierarchy, and creates the file F<autosplit.ix>. This file acts as |
38 | both forward declaration of all package routines, and as timestamp for the |
39 | last update of the hierarchy. |
40 | |
4e6ea2c3 |
41 | The remaining three arguments to C<autosplit> govern other options to |
42 | the autosplitter. |
43 | |
44 | =over 2 |
45 | |
46 | =item $keep |
47 | |
48 | If the third argument, I<$keep>, is false, then any |
49 | pre-existing C<*.al> files in the autoload directory are removed if |
50 | they are no longer part of the module (obsoleted functions). |
51 | $keep defaults to 0. |
52 | |
53 | =item $check |
54 | |
55 | The |
56 | fourth argument, I<$check>, instructs C<autosplit> to check the module |
e8fac187 |
57 | currently being split to ensure that it includes a C<use> |
4e6ea2c3 |
58 | specification for the AutoLoader module, and skips the module if |
59 | AutoLoader is not detected. |
60 | $check defaults to 1. |
61 | |
62 | =item $modtime |
63 | |
64 | Lastly, the I<$modtime> argument specifies |
65 | that C<autosplit> is to check the modification time of the module |
66 | against that of the C<autosplit.ix> file, and only split the module if |
67 | it is newer. |
68 | $modtime defaults to 1. |
69 | |
70 | =back |
21c92a1d |
71 | |
72 | Typical use of AutoSplit in the perl MakeMaker utility is via the command-line |
73 | with: |
74 | |
75 | perl -e 'use AutoSplit; autosplit($ARGV[0], $ARGV[1], 0, 1, 1)' |
76 | |
77 | Defined as a Make macro, it is invoked with file and directory arguments; |
78 | C<autosplit> will split the specified file into the specified directory and |
79 | delete obsolete C<.al> files, after checking first that the module does use |
80 | the AutoLoader, and ensuring that the module is not already currently split |
81 | in its current form (the modtime test). |
82 | |
83 | The C<autosplit_lib_modules> form is used in the building of perl. It takes |
84 | as input a list of files (modules) that are assumed to reside in a directory |
85 | B<lib> relative to the current directory. Each file is sent to the |
86 | autosplitter one at a time, to be split into the directory B<lib/auto>. |
87 | |
88 | In both usages of the autosplitter, only subroutines defined following the |
4e6ea2c3 |
89 | perl I<__END__> token are split out into separate files. Some |
21c92a1d |
90 | routines may be placed prior to this marker to force their immediate loading |
91 | and parsing. |
92 | |
4e6ea2c3 |
93 | =head2 Multiple packages |
94 | |
95 | As of version 1.01 of the AutoSplit module it is possible to have |
96 | multiple packages within a single file. Both of the following cases |
97 | are supported: |
98 | |
99 | package NAME; |
100 | __END__ |
101 | sub AAA { ... } |
102 | package NAME::option1; |
103 | sub BBB { ... } |
104 | package NAME::option2; |
105 | sub BBB { ... } |
21c92a1d |
106 | |
4e6ea2c3 |
107 | package NAME; |
108 | __END__ |
109 | sub AAA { ... } |
110 | sub NAME::option1::BBB { ... } |
111 | sub NAME::option2::BBB { ... } |
21c92a1d |
112 | |
113 | =head1 DIAGNOSTICS |
114 | |
4e6ea2c3 |
115 | C<AutoSplit> will inform the user if it is necessary to create the |
116 | top-level directory specified in the invocation. It is preferred that |
117 | the script or installation process that invokes C<AutoSplit> have |
118 | created the full directory path ahead of time. This warning may |
119 | indicate that the module is being split into an incorrect path. |
21c92a1d |
120 | |
4e6ea2c3 |
121 | C<AutoSplit> will warn the user of all subroutines whose name causes |
122 | potential file naming conflicts on machines with drastically limited |
123 | (8 characters or less) file name length. Since the subroutine name is |
124 | used as the file name, these warnings can aid in portability to such |
125 | systems. |
21c92a1d |
126 | |
4e6ea2c3 |
127 | Warnings are issued and the file skipped if C<AutoSplit> cannot locate |
128 | either the I<__END__> marker or a "package Name;"-style specification. |
21c92a1d |
129 | |
4e6ea2c3 |
130 | C<AutoSplit> will also emit general diagnostics for inability to |
131 | create directories or files. |
f06db76b |
132 | |
133 | =cut |
134 | |
a0d0e21e |
135 | # for portability warn about names longer than $maxlen |
136 | $Maxlen = 8; # 8 for dos, 11 (14-".al") for SYSVR3 |
137 | $Verbose = 1; # 0=none, 1=minimal, 2=list .al files |
138 | $Keep = 0; |
3edbfbe5 |
139 | $CheckForAutoloader = 1; |
140 | $CheckModTime = 1; |
a0d0e21e |
141 | |
4e6ea2c3 |
142 | my $IndexFile = "autosplit.ix"; # file also serves as timestamp |
143 | my $maxflen = 255; |
a0d0e21e |
144 | $maxflen = 14 if $Config{'d_flexfnam'} ne 'define'; |
39e571d4 |
145 | if (defined (&Dos::UseLFN)) { |
146 | $maxflen = Dos::UseLFN() ? 255 : 11; |
147 | } |
4e6ea2c3 |
148 | my $Is_VMS = ($^O eq 'VMS'); |
a0d0e21e |
149 | |
09bef843 |
150 | # allow checking for valid ': attrlist' attachments |
151 | my $nested; |
14455d6c |
152 | $nested = qr{ \( (?: (?> [^()]+ ) | (??{ $nested }) )* \) }x; |
0120eecf |
153 | my $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x; |
09bef843 |
154 | my $attr_list = qr{ \s* : \s* (?: $one_attr )* }x; |
155 | |
156 | |
3edbfbe5 |
157 | |
a0d0e21e |
158 | sub autosplit{ |
4e6ea2c3 |
159 | my($file, $autodir, $keep, $ckal, $ckmt) = @_; |
75f92628 |
160 | # $file - the perl source file to be split (after __END__) |
161 | # $autodir - the ".../auto" dir below which to write split subs |
162 | # Handle optional flags: |
4e6ea2c3 |
163 | $keep = $Keep unless defined $keep; |
75f92628 |
164 | $ckal = $CheckForAutoloader unless defined $ckal; |
165 | $ckmt = $CheckModTime unless defined $ckmt; |
166 | autosplit_file($file, $autodir, $keep, $ckal, $ckmt); |
a0d0e21e |
167 | } |
168 | |
169 | |
a0d0e21e |
170 | # This function is used during perl building/installation |
21c92a1d |
171 | # ./miniperl -e 'use AutoSplit; autosplit_lib_modules(@ARGV)' ... |
a0d0e21e |
172 | |
173 | sub autosplit_lib_modules{ |
174 | my(@modules) = @_; # list of Module names |
175 | |
3e3baf6d |
176 | while(defined($_ = shift @modules)){ |
0eb04855 |
177 | while (m#(.*?[^:])::([^:].*)#) { # in case specified as ABC::XYZ |
178 | $_ = catfile($1, $2); |
179 | } |
4633a7c4 |
180 | s|\\|/|g; # bug in ksh OS/2 |
413e5597 |
181 | s#^lib/##s; # incase specified as lib/*.pm |
0eb04855 |
182 | my($lib) = catfile(curdir(), "lib"); |
b1179839 |
183 | if ($Is_VMS) { # may need to convert VMS-style filespecs |
184 | $lib =~ s#^\[\]#.\/#; |
185 | } |
413e5597 |
186 | s#^$lib\W+##s; # incase specified as ./lib/*.pm |
c6538b72 |
187 | if ($Is_VMS && /[:>\]]/) { # may need to convert VMS-style filespecs |
14a089c5 |
188 | my ($dir,$name) = (/(.*])(.*)/s); |
189 | $dir =~ s/.*lib[\.\]]//s; |
a0d0e21e |
190 | $dir =~ s#[\.\]]#/#g; |
191 | $_ = $dir . $name; |
192 | } |
0eb04855 |
193 | autosplit_file(catfile($lib, $_), catfile($lib, "auto"), |
4e6ea2c3 |
194 | $Keep, $CheckForAutoloader, $CheckModTime); |
a0d0e21e |
195 | } |
196 | 0; |
197 | } |
198 | |
199 | |
200 | # private functions |
201 | |
e8fac187 |
202 | my $self_mod_time = (stat __FILE__)[9]; |
203 | |
4e6ea2c3 |
204 | sub autosplit_file { |
205 | my($filename, $autodir, $keep, $check_for_autoloader, $check_mod_time) |
206 | = @_; |
207 | my(@outfiles); |
6e7678af |
208 | local($_); |
4e6ea2c3 |
209 | local($/) = "\n"; |
a0d0e21e |
210 | |
211 | # where to write output files |
0eb04855 |
212 | $autodir ||= catfile(curdir(), "lib", "auto"); |
f86702cc |
213 | if ($Is_VMS) { |
14a089c5 |
214 | ($autodir = VMS::Filespec::unixpath($autodir)) =~ s|/\z||; |
f86702cc |
215 | $filename = VMS::Filespec::unixify($filename); # may have dirs |
216 | } |
3edbfbe5 |
217 | unless (-d $autodir){ |
68dc0745 |
218 | mkpath($autodir,0,0755); |
4e6ea2c3 |
219 | # We should never need to create the auto dir |
220 | # here. installperl (or similar) should have done |
221 | # it. Expecting it to exist is a valuable sanity check against |
222 | # autosplitting into some random directory by mistake. |
223 | print "Warning: AutoSplit had to create top-level " . |
224 | "$autodir unexpectedly.\n"; |
3edbfbe5 |
225 | } |
a0d0e21e |
226 | |
227 | # allow just a package name to be used |
14a089c5 |
228 | $filename .= ".pm" unless ($filename =~ m/\.pm\z/); |
a0d0e21e |
229 | |
b6c146dd |
230 | open(my $in, "<$filename") or die "AutoSplit: Can't open $filename: $!\n"; |
a0d0e21e |
231 | my($pm_mod_time) = (stat($filename))[9]; |
232 | my($autoloader_seen) = 0; |
f06db76b |
233 | my($in_pod) = 0; |
4e6ea2c3 |
234 | my($def_package,$last_package,$this_package,$fnr); |
b6c146dd |
235 | while (<$in>) { |
f06db76b |
236 | # Skip pod text. |
4e6ea2c3 |
237 | $fnr++; |
697fd008 |
238 | $in_pod = 1 if /^=\w/; |
f06db76b |
239 | $in_pod = 0 if /^=cut/; |
240 | next if ($in_pod || /^=cut/); |
fe169e07 |
241 | next if /^\s*#/; |
f06db76b |
242 | |
a0d0e21e |
243 | # record last package name seen |
4e6ea2c3 |
244 | $def_package = $1 if (m/^\s*package\s+([\w:]+)\s*;/); |
3edbfbe5 |
245 | ++$autoloader_seen if m/^\s*(use|require)\s+AutoLoader\b/; |
a0d0e21e |
246 | ++$autoloader_seen if m/\bISA\s*=.*\bAutoLoader\b/; |
247 | last if /^__END__/; |
248 | } |
3edbfbe5 |
249 | if ($check_for_autoloader && !$autoloader_seen){ |
4e6ea2c3 |
250 | print "AutoSplit skipped $filename: no AutoLoader used\n" |
251 | if ($Verbose>=2); |
252 | return 0; |
3edbfbe5 |
253 | } |
a0d0e21e |
254 | $_ or die "Can't find __END__ in $filename\n"; |
255 | |
4e6ea2c3 |
256 | $def_package or die "Can't find 'package Name;' in $filename\n"; |
a0d0e21e |
257 | |
4e6ea2c3 |
258 | my($modpname) = _modpname($def_package); |
a0d0e21e |
259 | |
4e6ea2c3 |
260 | # this _has_ to match so we have a reasonable timestamp file |
261 | die "Package $def_package ($modpname.pm) does not ". |
262 | "match filename $filename" |
68dc0745 |
263 | unless ($filename =~ m/\Q$modpname.pm\E$/ or |
2986a63f |
264 | ($^O eq 'dos') or ($^O eq 'MSWin32') or ($^O eq 'NetWare') or |
c6538b72 |
265 | $Is_VMS && $filename =~ m/$modpname.pm/i); |
a0d0e21e |
266 | |
084592ab |
267 | my($al_idx_file) = catfile($autodir, $modpname, $IndexFile); |
68dc0745 |
268 | |
a0d0e21e |
269 | if ($check_mod_time){ |
270 | my($al_ts_time) = (stat("$al_idx_file"))[9] || 1; |
e8fac187 |
271 | if ($al_ts_time >= $pm_mod_time and |
272 | $al_ts_time >= $self_mod_time){ |
4e6ea2c3 |
273 | print "AutoSplit skipped ($al_idx_file newer than $filename)\n" |
a0d0e21e |
274 | if ($Verbose >= 2); |
275 | return undef; # one undef, not a list |
276 | } |
277 | } |
278 | |
64a3d80f |
279 | my($modnamedir) = catdir($autodir, $modpname); |
0eb04855 |
280 | print "AutoSplitting $filename ($modnamedir)\n" |
a0d0e21e |
281 | if $Verbose; |
282 | |
084592ab |
283 | unless (-d $modnamedir){ |
284 | mkpath($modnamedir,0,0777); |
a0d0e21e |
285 | } |
286 | |
287 | # We must try to deal with some SVR3 systems with a limit of 14 |
288 | # characters for file names. Sadly we *cannot* simply truncate all |
289 | # file names to 14 characters on these systems because we *must* |
290 | # create filenames which exactly match the names used by AutoLoader.pm. |
291 | # This is a problem because some systems silently truncate the file |
292 | # names while others treat long file names as an error. |
293 | |
39e571d4 |
294 | my $Is83 = $maxflen==11; # plain, case INSENSITIVE dos filenames |
295 | |
4e6ea2c3 |
296 | my(@subnames, $subname, %proto, %package); |
96bc026d |
297 | my @cache = (); |
298 | my $caching = 1; |
4e6ea2c3 |
299 | $last_package = ''; |
b6c146dd |
300 | my $out; |
301 | while (<$in>) { |
4e6ea2c3 |
302 | $fnr++; |
53667d02 |
303 | $in_pod = 1 if /^=\w/; |
4e6ea2c3 |
304 | $in_pod = 0 if /^=cut/; |
305 | next if ($in_pod || /^=cut/); |
306 | # the following (tempting) old coding gives big troubles if a |
307 | # cut is forgotten at EOF: |
308 | # next if /^=\w/ .. /^=cut/; |
309 | if (/^package\s+([\w:]+)\s*;/) { |
310 | $this_package = $def_package = $1; |
a0d0e21e |
311 | } |
b6c146dd |
312 | |
09bef843 |
313 | if (/^sub\s+([\w:]+)(\s*(?:\(.*?\))?(?:$attr_list)?)/) { |
b6c146dd |
314 | print $out "# end of $last_package\::$subname\n1;\n" |
4e6ea2c3 |
315 | if $last_package; |
316 | $subname = $1; |
317 | my $proto = $2 || ''; |
318 | if ($subname =~ s/(.*):://){ |
319 | $this_package = $1; |
320 | } else { |
321 | $this_package = $def_package; |
a0d0e21e |
322 | } |
4e6ea2c3 |
323 | my $fq_subname = "$this_package\::$subname"; |
324 | $package{$fq_subname} = $this_package; |
325 | $proto{$fq_subname} = $proto; |
326 | push(@subnames, $fq_subname); |
a0d0e21e |
327 | my($lname, $sname) = ($subname, substr($subname,0,$maxflen-3)); |
4e6ea2c3 |
328 | $modpname = _modpname($this_package); |
64a3d80f |
329 | my($modnamedir) = catdir($autodir, $modpname); |
084592ab |
330 | mkpath($modnamedir,0,0777); |
0eb04855 |
331 | my($lpath) = catfile($modnamedir, "$lname.al"); |
332 | my($spath) = catfile($modnamedir, "$sname.al"); |
4e6ea2c3 |
333 | my $path; |
b6c146dd |
334 | |
335 | if (!$Is83 and open($out, ">$lpath")){ |
4e6ea2c3 |
336 | $path=$lpath; |
a0d0e21e |
337 | print " writing $lpath\n" if ($Verbose>=2); |
4e6ea2c3 |
338 | } else { |
b6c146dd |
339 | open($out, ">$spath") or die "Can't create $spath: $!\n"; |
4e6ea2c3 |
340 | $path=$spath; |
341 | print " writing $spath (with truncated name)\n" |
342 | if ($Verbose>=1); |
a0d0e21e |
343 | } |
4e6ea2c3 |
344 | push(@outfiles, $path); |
e8fac187 |
345 | my $lineno = $fnr - @cache; |
b6c146dd |
346 | print $out <<EOT; |
4e6ea2c3 |
347 | # NOTE: Derived from $filename. |
e8fac187 |
348 | # Changes made here will be lost when autosplit is run again. |
4e6ea2c3 |
349 | # See AutoSplit.pm. |
350 | package $this_package; |
351 | |
e8fac187 |
352 | #line $lineno "$filename (autosplit into $path)" |
4e6ea2c3 |
353 | EOT |
b6c146dd |
354 | print $out @cache; |
96bc026d |
355 | @cache = (); |
356 | $caching = 0; |
357 | } |
358 | if($caching) { |
359 | push(@cache, $_) if @cache || /\S/; |
4e6ea2c3 |
360 | } else { |
b6c146dd |
361 | print $out $_; |
96bc026d |
362 | } |
4e6ea2c3 |
363 | if(/^\}/) { |
96bc026d |
364 | if($caching) { |
b6c146dd |
365 | print $out @cache; |
96bc026d |
366 | @cache = (); |
367 | } |
b6c146dd |
368 | print $out "\n"; |
96bc026d |
369 | $caching = 1; |
a0d0e21e |
370 | } |
4e6ea2c3 |
371 | $last_package = $this_package if defined $this_package; |
a0d0e21e |
372 | } |
548da3d2 |
373 | if ($subname) { |
b6c146dd |
374 | print $out @cache,"1;\n# end of $last_package\::$subname\n"; |
375 | close($out); |
548da3d2 |
376 | } |
b6c146dd |
377 | close($in); |
4e6ea2c3 |
378 | |
a0d0e21e |
379 | if (!$keep){ # don't keep any obsolete *.al files in the directory |
4e6ea2c3 |
380 | my(%outfiles); |
381 | # @outfiles{@outfiles} = @outfiles; |
382 | # perl downcases all filenames on VMS (which upcases all filenames) so |
383 | # we'd better downcase the sub name list too, or subs with upper case |
384 | # letters in them will get their .al files deleted right after they're |
8f8c40b1 |
385 | # created. (The mixed case sub name won't match the all-lowercase |
4e6ea2c3 |
386 | # filename, and so be cleaned up as a scrap file) |
387 | if ($Is_VMS or $Is83) { |
388 | %outfiles = map {lc($_) => lc($_) } @outfiles; |
389 | } else { |
390 | @outfiles{@outfiles} = @outfiles; |
391 | } |
392 | my(%outdirs,@outdirs); |
393 | for (@outfiles) { |
394 | $outdirs{File::Basename::dirname($_)}||=1; |
395 | } |
396 | for my $dir (keys %outdirs) { |
b6c146dd |
397 | opendir(my $outdir,$dir); |
398 | foreach (sort readdir($outdir)){ |
14a089c5 |
399 | next unless /\.al\z/; |
0eb04855 |
400 | my($file) = catfile($dir, $_); |
8f8c40b1 |
401 | $file = lc $file if $Is83 or $Is_VMS; |
4e6ea2c3 |
402 | next if $outfiles{$file}; |
403 | print " deleting $file\n" if ($Verbose>=2); |
404 | my($deleted,$thistime); # catch all versions on VMS |
405 | do { $deleted += ($thistime = unlink $file) } while ($thistime); |
406 | carp "Unable to delete $file: $!" unless $deleted; |
407 | } |
b6c146dd |
408 | closedir($outdir); |
a0d0e21e |
409 | } |
a0d0e21e |
410 | } |
411 | |
b6c146dd |
412 | open(my $ts,">$al_idx_file") or |
a0d0e21e |
413 | carp "AutoSplit: unable to create timestamp file ($al_idx_file): $!"; |
b6c146dd |
414 | print $ts "# Index created by AutoSplit for $filename\n"; |
415 | print $ts "# (file acts as timestamp)\n"; |
4e6ea2c3 |
416 | $last_package = ''; |
417 | for my $fqs (@subnames) { |
418 | my($subname) = $fqs; |
419 | $subname =~ s/.*:://; |
b6c146dd |
420 | print $ts "package $package{$fqs};\n" |
4e6ea2c3 |
421 | unless $last_package eq $package{$fqs}; |
b6c146dd |
422 | print $ts "sub $subname $proto{$fqs};\n"; |
4e6ea2c3 |
423 | $last_package = $package{$fqs}; |
424 | } |
b6c146dd |
425 | print $ts "1;\n"; |
426 | close($ts); |
a0d0e21e |
427 | |
4e6ea2c3 |
428 | _check_unique($filename, $Maxlen, 1, @outfiles); |
a0d0e21e |
429 | |
4e6ea2c3 |
430 | @outfiles; |
a0d0e21e |
431 | } |
432 | |
4e6ea2c3 |
433 | sub _modpname ($) { |
434 | my($package) = @_; |
435 | my $modpname = $package; |
436 | if ($^O eq 'MSWin32') { |
437 | $modpname =~ s#::#\\#g; |
438 | } else { |
64a3d80f |
439 | my @modpnames = (); |
440 | while ($modpname =~ m#(.*?[^:])::([^:].*)#) { |
441 | push @modpnames, $1; |
442 | $modpname = $2; |
443 | } |
444 | $modpname = catfile(@modpnames, $modpname); |
445 | } |
446 | if ($Is_VMS) { |
447 | $modpname = VMS::Filespec::unixify($modpname); # may have dirs |
4e6ea2c3 |
448 | } |
449 | $modpname; |
450 | } |
a0d0e21e |
451 | |
4e6ea2c3 |
452 | sub _check_unique { |
453 | my($filename, $maxlen, $warn, @outfiles) = @_; |
a0d0e21e |
454 | my(%notuniq) = (); |
455 | my(%shorts) = (); |
4e6ea2c3 |
456 | my(@toolong) = grep( |
457 | length(File::Basename::basename($_)) |
458 | > $maxlen, |
459 | @outfiles |
460 | ); |
461 | |
462 | foreach (@toolong){ |
463 | my($dir) = File::Basename::dirname($_); |
464 | my($file) = File::Basename::basename($_); |
465 | my($trunc) = substr($file,0,$maxlen); |
466 | $notuniq{$dir}{$trunc} = 1 if $shorts{$dir}{$trunc}; |
467 | $shorts{$dir}{$trunc} = $shorts{$dir}{$trunc} ? |
468 | "$shorts{$dir}{$trunc}, $file" : $file; |
a0d0e21e |
469 | } |
470 | if (%notuniq && $warn){ |
4e6ea2c3 |
471 | print "$filename: some names are not unique when " . |
472 | "truncated to $maxlen characters:\n"; |
473 | foreach my $dir (sort keys %notuniq){ |
474 | print " directory $dir:\n"; |
475 | foreach my $trunc (sort keys %{$notuniq{$dir}}) { |
476 | print " $shorts{$dir}{$trunc} truncate to $trunc\n"; |
477 | } |
a0d0e21e |
478 | } |
479 | } |
a0d0e21e |
480 | } |
481 | |
482 | 1; |
483 | __END__ |
484 | |
485 | # test functions so AutoSplit.pm can be applied to itself: |
4e6ea2c3 |
486 | sub test1 ($) { "test 1\n"; } |
487 | sub test2 ($$) { "test 2\n"; } |
488 | sub test3 ($$$) { "test 3\n"; } |
489 | sub testtesttesttest4_1 { "test 4\n"; } |
490 | sub testtesttesttest4_2 { "duplicate test 4\n"; } |
491 | sub Just::Another::test5 { "another test 5\n"; } |
492 | sub test6 { return join ":", __FILE__,__LINE__; } |
493 | package Yet::Another::AutoSplit; |
494 | sub testtesttesttest4_1 ($) { "another test 4\n"; } |
495 | sub testtesttesttest4_2 ($$) { "another duplicate test 4\n"; } |
09bef843 |
496 | package Yet::More::Attributes; |
0120eecf |
497 | sub test_a1 ($) : locked :locked { 1; } |
09bef843 |
498 | sub test_a2 : locked { 1; } |