diff options
author | Graham Barr <bodg@tiuk.ti.com> | 1996-03-11 06:01:58 -0500 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-01-16 07:24:00 +1200 |
commit | bb8fceff88bc3fe9e820d0761f1b0451a870ac65 (patch) | |
tree | dc24d3e2814ff05d7b7676998769773a2f922b19 | |
parent | 7adad424447c8a24bce71f2593459be2ef4eb957 (diff) | |
download | perl-bb8fceff88bc3fe9e820d0761f1b0451a870ac65.tar.gz |
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>
-rw-r--r-- | lib/AutoSplit.pm | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/AutoSplit.pm b/lib/AutoSplit.pm index cc9de33f26..2d2465f5f1 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 (<IN>) { 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); |