package AutoSplit;
+use 5.005_64;
use Exporter ();
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;
-use vars qw(
- $VERSION @ISA @EXPORT @EXPORT_OK
- $Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime
- );
+our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Verbose, $Keep, $Maxlen,
+ $CheckForAutoloader, $CheckModTime);
-$VERSION = "1.0302";
+$VERSION = "1.0305";
@ISA = qw(Exporter);
@EXPORT = qw(&autosplit &autosplit_lib_modules);
@EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime);
}
my $Is_VMS = ($^O eq 'VMS');
+# allow checking for valid ': attrlist' attachments
+my $nested;
+$nested = qr{ \( (?: (?> [^()]+ ) | (??{ $nested }) )* \) }x;
+my $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x;
+my $attr_list = qr{ \s* : \s* (?: $one_attr )* }x;
+
+
sub autosplit{
my($file, $autodir, $keep, $ckal, $ckmt) = @_;
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/##; # incase specified as lib/*.pm
+ 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) = (/(.*])(.*)/);
- $dir =~ s/.*lib[\.\]]//;
+ 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;
local($/) = "\n";
# where to write output files
- $autodir ||= "lib/auto";
+ $autodir ||= catfile(curdir(), "lib", "auto");
if ($Is_VMS) {
- ($autodir = VMS::Filespec::unixpath($autodir)) =~ s|/$||;
+ ($autodir = VMS::Filespec::unixpath($autodir)) =~ s|/\z||;
$filename = VMS::Filespec::unixify($filename); # may have dirs
}
unless (-d $autodir){
}
# allow just a package name to be used
- $filename .= ".pm" unless ($filename =~ m/\.pm$/);
+ $filename .= ".pm" unless ($filename =~ m/\.pm\z/);
open(IN, "<$filename") or die "AutoSplit: Can't open $filename: $!\n";
my($pm_mod_time) = (stat($filename))[9];
while (<IN>) {
# Skip pod text.
$fnr++;
- $in_pod = 1 if /^=/;
+ $in_pod = 1 if /^=\w/;
$in_pod = 0 if /^=cut/;
next if ($in_pod || /^=cut/);
$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 ".
}
}
- 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
$last_package = '';
while (<IN>) {
$fnr++;
- $in_pod = 1 if /^=/;
+ $in_pod = 1 if /^=\w/;
$in_pod = 0 if /^=cut/;
next if ($in_pod || /^=cut/);
# the following (tempting) old coding gives big troubles if a
if (/^package\s+([\w:]+)\s*;/) {
$this_package = $def_package = $1;
}
- if (/^sub\s+([\w:]+)(\s*\(.*?\))?/) {
+ if (/^sub\s+([\w:]+)(\s*(?:\(.*?\))?(?:$attr_list)?)/) {
print OUT "# end of $last_package\::$subname\n1;\n"
if $last_package;
$subname = $1;
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;
}
$last_package = $this_package if defined $this_package;
}
- print OUT @cache,"1;\n# end of $last_package\::$subname\n";
- close(OUT);
+ if ($subname) {
+ print OUT @cache,"1;\n# end of $last_package\::$subname\n";
+ close(OUT);
+ }
close(IN);
if (!$keep){ # don't keep any obsolete *.al files in the directory
for my $dir (keys %outdirs) {
opendir(OUTDIR,$dir);
foreach (sort readdir(OUTDIR)){
- next unless /\.al$/;
- my($file) = "$dir/$_";
+ next unless /\.al\z/;
+ my($file) = catfile($dir, $_);
$file = lc $file if $Is83 or $Is_VMS;
next if $outfiles{$file};
print " deleting $file\n" if ($Verbose>=2);
if ($^O eq 'MSWin32') {
$modpname =~ s#::#\\#g;
} else {
- $modpname =~ s#::#/#g;
+ while ($modpname =~ m#(.*?[^:])::([^:].*)#) {
+ $modpname = catfile($1, $2);
+ }
}
$modpname;
}
package Yet::Another::AutoSplit;
sub testtesttesttest4_1 ($) { "another test 4\n"; }
sub testtesttesttest4_2 ($$) { "another duplicate test 4\n"; }
+package Yet::More::Attributes;
+sub test_a1 ($) : locked :locked { 1; }
+sub test_a2 : locked { 1; }