This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mktables: Allow multiple eof handlers for input files
authorKarl Williamson <khw@cpan.org>
Sun, 26 Jul 2015 01:19:05 +0000 (19:19 -0600)
committerKarl Williamson <khw@cpan.org>
Wed, 29 Jul 2015 04:15:57 +0000 (22:15 -0600)
The Input_file class is hereby extended so there can be more than one
subroutine stacked to call when an EOF is encountered.  This new
capability will be used in later commits.  There is no current need for
any outside class to look at this, so that capability is removed.

charclass_invlists.h
lib/unicore/mktables
regcharclass.h

index 10bdf06..6dbd249 100644 (file)
@@ -99521,7 +99521,7 @@ static const UV XPosixXDigit_invlist[] = { /* for EBCDIC POSIX-BC */
  * 1a0687fb9c6c4567e853913549df0944fe40821279a3e9cdaa6ab8679bc286fd lib/unicore/extracted/DLineBreak.txt
  * 40bcfed3ca727c19e1331f6c33806231d5f7eeeabd2e6a9e06a3740c85d0c250 lib/unicore/extracted/DNumType.txt
  * a18d502bad39d527ac5586d7bc93e29f565859e3bcc24ada627eff606d6f5fed lib/unicore/extracted/DNumValues.txt
- * 3354de92c9bccd2eb1912c54d3accf2855da6b77ebd52891a797299e0cd1e360 lib/unicore/mktables
+ * 18fbf94ad448e47cb72e463de0eb4f03c471a88a0c9afde1ed0709cc775a8604 lib/unicore/mktables
  * 462c9aaa608fb2014cd9649af1c5c009485c60b9c8b15b89401fdc10cf6161c6 lib/unicore/version
  * c6884f4d629f04d1316f3476cb1050b6a1b98ca30c903262955d4eae337c6b1e regen/charset_translations.pl
  * 7b6f61662df48e0cbfb234a926e02e5cb9468af052f7f9feb84285996f30df09 regen/mk_invlists.pl
index cf52361..ff034cb 100644 (file)
@@ -2125,12 +2125,13 @@ package Input_file;
 # each_line_handler()s.  So, if the format of the line is not in the desired
 # format for the main handler, these are used to do that adjusting.  They can
 # be stacked (by enclosing them in an [ anonymous array ] in the constructor,
-# so the $_ output of one is used as the input to the next.  None of the other
-# handlers are stackable, but could easily be changed to be so.
+# so the $_ output of one is used as the input to the next.  The eof handler
+# is also stackable, but none of the others are, but could easily be changed
+# to be so.
 #
 # Most of the handlers can call insert_lines() or insert_adjusted_lines()
 # which insert the parameters as lines to be processed before the next input
-# file line is read.  This allows the EOF handler to flush buffers, for
+# file line is read.  This allows the EOF handler(s) to flush buffers, for
 # example.  The difference between the two routines is that the lines inserted
 # by insert_lines() are subjected to the each_line_handler()s.  (So if you
 # called it from such a handler, you would get infinite recursion without some
@@ -2231,11 +2232,11 @@ sub trace { return main::trace(@_); }
     main::set_access('pre_handler', \%pre_handler, qw{ c });
 
     my %eof_handler;
-    # Subroutine to call upon getting an EOF on the input file, but before
+    # Subroutines to call upon getting an EOF on the input file, but before
     # that is returned to the main handler.  This is to allow buffers to be
     # flushed.  The handler is expected to call insert_lines() or
     # insert_adjusted() with the buffered material
-    main::set_access('eof_handler', \%eof_handler, qw{ c });
+    main::set_access('eof_handler', \%eof_handler, qw{ c });
 
     my %post_handler;
     # Subroutine to call after all the lines of the file are read in and
@@ -2286,6 +2287,7 @@ sub trace { return main::trace(@_); }
         $added_lines{$addr} = [ ];
         $remapped_lines{$addr} = [ ];
         $each_line_handler{$addr} = [ ];
+        $eof_handler{$addr} = [ ];
         $errors{$addr} = { };
         $missings{$addr} = [ ];
 
@@ -2414,7 +2416,7 @@ sub trace { return main::trace(@_); }
     sub run {
         # Process the input object $self.  This opens and closes the file and
         # calls all the handlers for it.  Currently,  this can only be called
-        # once per file, as it destroy's the EOF handler
+        # once per file, as it destroy's the EOF handlers
 
         my $self = shift;
         Carp::carp_extra_args(\@_) if main::DEBUG && @_;
@@ -2753,11 +2755,11 @@ END
             return 1;
         } # End of looping through lines.
 
-        # If there is an EOF handler, call it (only once) and if it generates
+        # If there are EOF handlers, call each (only once) and if it generates
         # more lines to process go back in the loop to handle them.
-        if ($eof_handler{$addr}) {
-            &{$eof_handler{$addr}}($self);
-            $eof_handler{$addr} = "";   # Currently only get one shot at it.
+        while ($eof_handler{$addr}->@*) {
+            &{$eof_handler{$addr}[0]}($self);
+            shift $eof_handler{$addr}->@*;   # Currently only get one shot at it.
             goto LINE if $added_lines{$addr};
         }
 
index 36d6a43..547cb58 100644 (file)
  * 1a0687fb9c6c4567e853913549df0944fe40821279a3e9cdaa6ab8679bc286fd lib/unicore/extracted/DLineBreak.txt
  * 40bcfed3ca727c19e1331f6c33806231d5f7eeeabd2e6a9e06a3740c85d0c250 lib/unicore/extracted/DNumType.txt
  * a18d502bad39d527ac5586d7bc93e29f565859e3bcc24ada627eff606d6f5fed lib/unicore/extracted/DNumValues.txt
- * 3354de92c9bccd2eb1912c54d3accf2855da6b77ebd52891a797299e0cd1e360 lib/unicore/mktables
+ * 18fbf94ad448e47cb72e463de0eb4f03c471a88a0c9afde1ed0709cc775a8604 lib/unicore/mktables
  * 462c9aaa608fb2014cd9649af1c5c009485c60b9c8b15b89401fdc10cf6161c6 lib/unicore/version
  * c6884f4d629f04d1316f3476cb1050b6a1b98ca30c903262955d4eae337c6b1e regen/charset_translations.pl
  * d9c04ac46bdd81bb3e26519f2b8eb6242cb12337205add3f7cf092b0c58dccc4 regen/regcharclass.pl