PATCH: AutoSplit
Chip Salzenberg [Wed, 15 Jan 1997 19:24:00 +0000 (07:24 +1200)]
(this is the same change as commit bb8fceff88bc3fe9e820d0761f1b0451a870ac65, but as applied)

lib/AutoSplit.pm

index cc9de33..c1ff13a 100644 (file)
@@ -248,7 +248,10 @@ sub autosplit_file{
 
     open(OUT,">/dev/null") || open(OUT,">nla0:"); # avoid 'not opened' warning
     my(@subnames, %proto);
+    my @cache = ();
+    my $caching = 1;
     while (<IN>) {
+       next if /^=\w/ .. /^=cut/;
        if (/^package ([\w:]+)\s*;/) {
            warn "package $1; in AutoSplit section ignored. Not currently supported.";
        }
@@ -275,10 +278,26 @@ 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, $_) if @cache || /\S/;
+       }
+       else {
+           print OUT $_;
+       }
+       if(/^}/) {
+           if($caching) {
+               print OUT @cache;
+               @cache = ();
+           }
+           print OUT "\n";
+           $caching = 1;
        }
-       print OUT $_;
     }
-    print OUT "1;\n";
+    print OUT @cache,"1;\n";
     close(OUT);
     close(IN);