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>
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.";
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);