Skip to content

Commit

Permalink
PATCH: AutoSplit
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Graham Barr authored and Chip Salzenberg committed Jan 15, 1997
1 parent 7adad42 commit bb8fcef
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/AutoSplit.pm
Expand Up @@ -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.";
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit bb8fcef

Please sign in to comment.