From: Graham Barr Date: Mon, 11 Mar 1996 11:01:58 +0000 (-0500) Subject: PATCH: AutoSplit X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bb8fceff88bc3fe9e820d0761f1b0451a870ac65;p=p5sagit%2Fp5-mst-13.2.git PATCH: AutoSplit Below is a patch which moves where AutoSplit splits a file. Currently AutoSplit split when it sees a sub. This inhibits individual routines from having their own use or require statements. This patch causes AutoSplit to split at the last line starting with a } before a sub. The reason behind this is that I have a package which is a collection of utility routines each requiring separate packages, as I am trying to reduce what is loaded by autoloading the routines, it seems only sensible to only 'use' packages when the routine which needs them it loaded p5p-msgid: <9603111010.AA29935@tiuk.ti.com> --- diff --git a/lib/AutoSplit.pm b/lib/AutoSplit.pm index cc9de33..2d2465f 100644 --- a/lib/AutoSplit.pm +++ b/lib/AutoSplit.pm @@ -248,6 +248,8 @@ sub autosplit_file{ open(OUT,">/dev/null") || open(OUT,">nla0:"); # avoid 'not opened' warning my(@subnames, %proto); + my @cache = (); + my $caching = 1; while () { if (/^package ([\w:]+)\s*;/) { warn "package $1; in AutoSplit section ignored. Not currently supported."; @@ -275,10 +277,25 @@ sub autosplit_file{ print OUT "# NOTE: Derived from $filename. ", "Changes made here will be lost.\n"; print OUT "package $package;\n\n"; + print OUT @cache; + @cache = (); + $caching = 0; + } + if($caching) { + push(@cache, $_); + } + else { + print OUT $_; + } + if(/^}/) { + if($caching) { + print OUT @cache; + @cache = (); + } + $caching = 1; } - print OUT $_; } - print OUT "1;\n"; + print OUT @cache,"1;\n"; close(OUT); close(IN);