Przeglądaj źródła

Dpkg::Changelog: Allow input to come directly from a filehandle

* scripts/Dpkg/Changelog/Debian.pm (parse): Accept input in
configuration item 'inhandle'. Allow to override the name of
the file (used for reporting) with configuration item
'reportfile'.
* scripts/Dpkg/Changelog.pm (init): Call parse if
'inhandle' is given.
Frank Lichtenheld 18 lat temu
rodzic
commit
83d4b9afc3
2 zmienionych plików z 18 dodań i 6 usunięć
  1. 8 4
      scripts/Dpkg/Changelog.pm
  2. 10 2
      scripts/Dpkg/Changelog/Debian.pm

+ 8 - 4
scripts/Dpkg/Changelog.pm

@@ -64,7 +64,7 @@ There are currently no supported general configuration options, but
 see the other methods for more specific configuration options which
 can also specified to C<init>.
 
-If C<infile> or C<instring> are specified (see L<parse>), C<parse()>
+If C<infile>, C<inhandle>, or C<instring> are specified, C<parse()>
 is called from C<init>. If a fatal error is encountered during parsing
 (e.g. the file can't be opened), C<init> will not return a
 valid object but C<undef>!
@@ -82,7 +82,9 @@ sub init {
 
     $self->reset_parse_errors;
 
-    if ($self->{config}{infile} || $self->{config}{instring}) {
+    if ($self->{config}{infile}
+	|| $self->{config}{inhandle}
+	|| $self->{config}{instring}) {
 	defined($self->parse) or return undef;
     }
 
@@ -132,8 +134,10 @@ an array of arrays. Each of these arrays contains
 
 =item 1.
 
-the filename of the parsed file or C<String> if a string was
-parsed directly
+the filename of the parsed file or C<FileHandle> or C<String>
+if the input came from a file handle or a string. If the
+reportfile configuration option was given, its value will be
+used instead
 
 =item 2.
 

+ 10 - 2
scripts/Dpkg/Changelog/Debian.pm

@@ -74,8 +74,11 @@ use base qw(Dpkg::Changelog);
 
 =head3 parse
 
-Parses either the file named in configuration item C<infile> or the string
-saved in configuration item C<instring>.
+Parses either the file named in configuration item C<infile>, the content
+of the filehandle in configuration item C<inhandle>, or the string
+saved in configuration item C<instring> (the latter requires IO::String).
+You can set a filename to use for reporting errors with configuration
+item C<reportfile>.
 Accepts a hash ref as optional argument which can contain configuration
 items.
 
@@ -99,6 +102,8 @@ sub parse {
 					$file, $! );
 	    return undef;
 	};
+    } elsif ($fh = $self->{config}{inhandle}) {
+	$file = 'FileHandle';
     } elsif (my $string = $self->{config}{instring}) {
 	eval { require IO::String };
 	if ($@) {
@@ -112,6 +117,9 @@ sub parse {
 	$self->_do_fatal_error(_g('no changelog file specified'));
 	return undef;
     }
+    if (defined($self->{config}{reportfile})) {
+	$file = $self->{config}{reportfile};
+    }
 
     $self->reset_parse_errors;