This is my patch patch.1g for perl5.001.
[p5sagit/p5-mst-13.2.git] / lib / AutoSplit.pm
index 71115c6..72f897d 100644 (file)
@@ -10,6 +10,19 @@ use Carp;
 @EXPORT = qw(&autosplit &autosplit_lib_modules);
 @EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime);
 
+=head1 NAME
+
+AutoSplit - split a package for autoloading
+
+=head1 DESCRIPTION
+
+This function will split up your program into files that the AutoLoader
+module can handle.  Normally only used to build autoloading Perl library
+modules, especially extensions (like POSIX).  You should look at how
+they're built out for details.
+
+=cut
+
 # for portability warn about names longer than $maxlen
 $Maxlen  = 8;  # 8 for dos, 11 (14-".al") for SYSVR3
 $Verbose = 1;  # 0=none, 1=minimal, 2=list .al files
@@ -24,8 +37,14 @@ $vms = ($Config{'osname'} eq 'VMS');
 
 
 sub autosplit{
-    my($file, $autodir) = @_;
-    autosplit_file($file, $autodir, $Keep, $CheckForAutoloader, $CheckModTime);
+    my($file, $autodir,  $k, $ckal, $ckmt) = @_;
+    # $file    - the perl source file to be split (after __END__)
+    # $autodir - the ".../auto" dir below which to write split subs
+    # Handle optional flags:
+    $keep = $Keep unless defined $k;
+    $ckal = $CheckForAutoloader unless defined $ckal;
+    $ckmt = $CheckModTime unless defined $ckmt;
+    autosplit_file($file, $autodir, $keep, $ckal, $ckmt);
 }
 
 
@@ -77,7 +96,13 @@ sub autosplit_file{
     open(IN, "<$filename") || die "AutoSplit: Can't open $filename: $!\n";
     my($pm_mod_time) = (stat($filename))[9];
     my($autoloader_seen) = 0;
+    my($in_pod) = 0;
     while (<IN>) {
+       # Skip pod text.
+       $in_pod = 1 if /^=/;
+       $in_pod = 0 if /^=cut/;
+       next if ($in_pod || /^=cut/);
+
        # record last package name seen
        $package = $1 if (m/^\s*package\s+([\w:]+)\s*;/);
        ++$autoloader_seen if m/^\s*(use|require)\s+AutoLoader\b/;
@@ -193,7 +218,9 @@ sub autosplit_file{
            next if $names{substr($subname,0,$maxflen-3)};
            my($file) = "$autodir/$modpname/$_";
            print "  deleting $file\n" if ($Verbose>=2);
-           unlink $file or carp "Unable to delete $file: $!";
+           my($deleted,$thistime);  # catch all versions on VMS
+           do { $deleted += ($thistime = unlink $file) } while ($thistime);
+           carp "Unable to delete $file: $!" unless $deleted;
        }
        closedir(OUTDIR);
     }
@@ -201,7 +228,9 @@ sub autosplit_file{
     open(TS,">$al_idx_file") or
        carp "AutoSplit: unable to create timestamp file ($al_idx_file): $!";
     print TS "# Index created by AutoSplit for $filename (file acts as timestamp)\n";
+    print TS "package $package;\n";
     print TS map("sub $_ ;\n", @subnames);
+    print TS "1;\n";
     close(TS);
 
     check_unique($package, $Maxlen, 1, @names);