This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Tell where the nice Estonian database is.
[perl5.git] / lib / AutoSplit.pm
index ecdb039..25e29c3 100644 (file)
@@ -6,11 +6,12 @@ use Config qw(%Config);
 use Carp qw(carp);
 use File::Basename ();
 use File::Path qw(mkpath);
+use File::Spec::Functions qw(curdir catfile);
 use strict;
 our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Verbose, $Keep, $Maxlen,
     $CheckForAutoloader, $CheckModTime);
 
-$VERSION = "1.0305";
+$VERSION = "1.0306";
 @ISA = qw(Exporter);
 @EXPORT = qw(&autosplit &autosplit_lib_modules);
 @EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime);
@@ -53,7 +54,7 @@ $keep defaults to 0.
 
 The
 fourth argument, I<$check>, instructs C<autosplit> to check the module
-currently being split to ensure that it does include a C<use>
+currently being split to ensure that it includes a C<use>
 specification for the AutoLoader module, and skips the module if
 AutoLoader is not detected.
 $check defaults to 1.
@@ -148,7 +149,7 @@ my $Is_VMS = ($^O eq 'VMS');
 
 # allow checking for valid ': attrlist' attachments
 my $nested;
-$nested = qr{ \( (?: (?> [^()]+ ) | (?p{ $nested }) )* \) }x;
+$nested = qr{ \( (?: (?> [^()]+ ) | (??{ $nested }) )* \) }x;
 my $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x;
 my $attr_list = qr{ \s* : \s* (?: $one_attr )* }x;
 
@@ -173,16 +174,23 @@ sub autosplit_lib_modules{
     my(@modules) = @_; # list of Module names
 
     while(defined($_ = shift @modules)){
-       s#::#/#g;       # incase specified as ABC::XYZ
+       while (m#(.*?[^:])::([^:].*)#) { # in case specified as ABC::XYZ
+           $_ = catfile($1, $2);
+       }
        s|\\|/|g;               # bug in ksh OS/2
        s#^lib/##s; # incase specified as lib/*.pm
+       my($lib) = catfile(curdir(), "lib");
+       if ($Is_VMS) { # may need to convert VMS-style filespecs
+           $lib =~ s#^\[\]#.\/#;
+       }
+       s#^$lib\W+##s; # incase specified as ./lib/*.pm
        if ($Is_VMS && /[:>\]]/) { # may need to convert VMS-style filespecs
            my ($dir,$name) = (/(.*])(.*)/s);
            $dir =~ s/.*lib[\.\]]//s;
            $dir =~ s#[\.\]]#/#g;
            $_ = $dir . $name;
        }
-       autosplit_file("lib/$_", "lib/auto",
+       autosplit_file(catfile($lib, $_), catfile($lib, "auto"),
                       $Keep, $CheckForAutoloader, $CheckModTime);
     }
     0;
@@ -191,6 +199,8 @@ sub autosplit_lib_modules{
 
 # private functions
 
+my $self_mod_time = (stat __FILE__)[9];
+
 sub autosplit_file {
     my($filename, $autodir, $keep, $check_for_autoloader, $check_mod_time)
        = @_;
@@ -199,7 +209,7 @@ sub autosplit_file {
     local($/) = "\n";
 
     # where to write output files
-    $autodir ||= "lib/auto";
+    $autodir ||= catfile(curdir(), "lib", "auto");
     if ($Is_VMS) {
        ($autodir = VMS::Filespec::unixpath($autodir)) =~ s|/\z||;
        $filename = VMS::Filespec::unixify($filename); # may have dirs
@@ -245,30 +255,35 @@ sub autosplit_file {
     $def_package or die "Can't find 'package Name;' in $filename\n";
 
     my($modpname) = _modpname($def_package); 
+    if ($Is_VMS) {
+       $modpname = VMS::Filespec::unixify($modpname); # may have dirs
+    }
 
     # this _has_ to match so we have a reasonable timestamp file
     die "Package $def_package ($modpname.pm) does not ".
        "match filename $filename"
            unless ($filename =~ m/\Q$modpname.pm\E$/ or
-                   ($^O eq 'dos') or ($^O eq 'MSWin32') or
+                   ($^O eq 'dos') or ($^O eq 'MSWin32') or ($^O eq 'NetWare') or
                    $Is_VMS && $filename =~ m/$modpname.pm/i);
 
-    my($al_idx_file) = "$autodir/$modpname/$IndexFile";
+    my($al_idx_file) = catfile($autodir, $modpname, $IndexFile);
 
     if ($check_mod_time){
        my($al_ts_time) = (stat("$al_idx_file"))[9] || 1;
-       if ($al_ts_time >= $pm_mod_time){
+       if ($al_ts_time >= $pm_mod_time and
+           $al_ts_time >= $self_mod_time){
            print "AutoSplit skipped ($al_idx_file newer than $filename)\n"
                if ($Verbose >= 2);
            return undef;       # one undef, not a list
        }
     }
 
-    print "AutoSplitting $filename ($autodir/$modpname)\n"
+    my($modnamedir) = catfile($autodir, $modpname);
+    print "AutoSplitting $filename ($modnamedir)\n"
        if $Verbose;
 
-    unless (-d "$autodir/$modpname"){
-       mkpath("$autodir/$modpname",0,0777);
+    unless (-d $modnamedir){
+       mkpath($modnamedir,0,0777);
     }
 
     # We must try to deal with some SVR3 systems with a limit of 14
@@ -311,9 +326,10 @@ sub autosplit_file {
            push(@subnames, $fq_subname);
            my($lname, $sname) = ($subname, substr($subname,0,$maxflen-3));
            $modpname = _modpname($this_package);
-           mkpath("$autodir/$modpname",0,0777);
-           my($lpath) = "$autodir/$modpname/$lname.al";
-           my($spath) = "$autodir/$modpname/$sname.al";
+           my($modnamedir) = catfile($autodir, $modpname);
+           mkpath($modnamedir,0,0777);
+           my($lpath) = catfile($modnamedir, "$lname.al");
+           my($spath) = catfile($modnamedir, "$sname.al");
            my $path;
            if (!$Is83 and open(OUT, ">$lpath")){
                $path=$lpath;
@@ -325,13 +341,14 @@ sub autosplit_file {
                        if ($Verbose>=1);
            }
            push(@outfiles, $path);
+           my $lineno = $fnr - @cache;
            print OUT <<EOT;
 # NOTE: Derived from $filename.
-# Changes made here will be lost when autosplit again.
+# Changes made here will be lost when autosplit is run again.
 # See AutoSplit.pm.
 package $this_package;
 
-#line $fnr "$filename (autosplit into $path)"
+#line $lineno "$filename (autosplit into $path)"
 EOT
            print OUT @cache;
            @cache = ();
@@ -379,7 +396,7 @@ EOT
            opendir(OUTDIR,$dir);
            foreach (sort readdir(OUTDIR)){
                next unless /\.al\z/;
-               my($file) = "$dir/$_";
+               my($file) = catfile($dir, $_);
                $file = lc $file if $Is83 or $Is_VMS;
                next if $outfiles{$file};
                print "  deleting $file\n" if ($Verbose>=2);
@@ -418,7 +435,9 @@ sub _modpname ($) {
     if ($^O eq 'MSWin32') {
        $modpname =~ s#::#\\#g; 
     } else {
-       $modpname =~ s#::#/#g;
+       while ($modpname =~ m#(.*?[^:])::([^:].*)#) {
+           $modpname = catfile($1, $2);
+       }
     }
     $modpname;
 }