X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FAutoSplit.pm;h=3c45d9211320ad81b050ce1d3d9ae34878c96fe2;hb=917211f59b1d5210f3944956e717bae1a2ca7565;hp=33c0b9a03ddbd3a8e7bd501ddcc588bc01a0129e;hpb=92c28edd459d810e3c841dc07d7846c462b368a9;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/AutoSplit.pm b/lib/AutoSplit.pm index 33c0b9a..3c45d92 100644 --- a/lib/AutoSplit.pm +++ b/lib/AutoSplit.pm @@ -1,17 +1,17 @@ package AutoSplit; +use 5.006_001; 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 catdir); 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.0303"; +$VERSION = "1.0307"; @ISA = qw(Exporter); @EXPORT = qw(&autosplit &autosplit_lib_modules); @EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime); @@ -54,7 +54,7 @@ $keep defaults to 0. The fourth argument, I<$check>, instructs C to check the module -currently being split to ensure that it does include a C +currently being split to ensure that it includes a C specification for the AutoLoader module, and skips the module if AutoLoader is not detected. $check defaults to 1. @@ -147,6 +147,13 @@ if (defined (&Dos::UseLFN)) { } 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) = @_; @@ -167,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/##; # 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; @@ -185,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) = @_; @@ -193,9 +209,9 @@ 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|/$||; + ($autodir = VMS::Filespec::unixpath($autodir)) =~ s|/\z||; $filename = VMS::Filespec::unixify($filename); # may have dirs } unless (-d $autodir){ @@ -209,7 +225,7 @@ sub autosplit_file { } # 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]; @@ -222,6 +238,7 @@ sub autosplit_file { $in_pod = 1 if /^=\w/; $in_pod = 0 if /^=cut/; next if ($in_pod || /^=cut/); + next if /^\s*#/; # record last package name seen $def_package = $1 if (m/^\s*package\s+([\w:]+)\s*;/); @@ -244,25 +261,27 @@ sub autosplit_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) = catdir($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 @@ -289,7 +308,7 @@ sub autosplit_file { 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; @@ -305,9 +324,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) = catdir($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; @@ -319,13 +339,14 @@ sub autosplit_file { if ($Verbose>=1); } push(@outfiles, $path); + my $lineno = $fnr - @cache; print OUT <=2); @@ -410,7 +433,15 @@ sub _modpname ($) { if ($^O eq 'MSWin32') { $modpname =~ s#::#\\#g; } else { - $modpname =~ s#::#/#g; + my @modpnames = (); + while ($modpname =~ m#(.*?[^:])::([^:].*)#) { + push @modpnames, $1; + $modpname = $2; + } + $modpname = catfile(@modpnames, $modpname); + } + if ($Is_VMS) { + $modpname = VMS::Filespec::unixify($modpname); # may have dirs } $modpname; } @@ -459,3 +490,6 @@ sub test6 { return join ":", __FILE__,__LINE__; } 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; }