From 83d4b9afc3e33c3c0f7a35af426eb796f1e9f87b Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Wed, 16 Jan 2008 13:08:51 +0100 Subject: [PATCH] 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. --- scripts/Dpkg/Changelog.pm | 12 ++++++++---- scripts/Dpkg/Changelog/Debian.pm | 12 ++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/Dpkg/Changelog.pm b/scripts/Dpkg/Changelog.pm index 18db282f..7d5b9410 100644 --- a/scripts/Dpkg/Changelog.pm +++ b/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. -If C or C are specified (see L), C +If C, C, or C are specified, C is called from C. If a fatal error is encountered during parsing (e.g. the file can't be opened), C will not return a valid object but C! @@ -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 if a string was -parsed directly +the filename of the parsed file or C or C +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. diff --git a/scripts/Dpkg/Changelog/Debian.pm b/scripts/Dpkg/Changelog/Debian.pm index 79714662..2aa26874 100644 --- a/scripts/Dpkg/Changelog/Debian.pm +++ b/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 or the string -saved in configuration item C. +Parses either the file named in configuration item C, the content +of the filehandle in configuration item C, or the string +saved in configuration item C (the latter requires IO::String). +You can set a filename to use for reporting errors with configuration +item C. 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; -- 2.39.5