# Copyright © 2005, 2007 Frank Lichtenheld # Copyright © 2009 Raphaël Hertzog # Copyright © 2010, 2012-2015 Guillem Jover # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . =encoding utf8 =head1 NAME Dpkg::Changelog::Parse - generic changelog parser for dpkg-parsechangelog =head1 DESCRIPTION This module provides a set of functions which reproduce all the features of dpkg-parsechangelog. =cut package Dpkg::Changelog::Parse 2.01; use strict; use warnings; our @EXPORT = qw( changelog_parse ); use Exporter qw(import); use List::Util qw(none); use Dpkg (); use Dpkg::Gettext; use Dpkg::ErrorHandling; use Dpkg::Control::Changelog; sub _changelog_detect_format { my $file = shift; my $format = 'debian'; # Extract the format from the changelog file if possible if ($file ne '-') { local $_; open my $format_fh, '<', $file or syserr(g_('cannot open file %s'), $file); if (-s $format_fh > 4096) { seek $format_fh, -4096, 2 or syserr(g_('cannot seek into file %s'), $file); } while (<$format_fh>) { $format = $1 if m/\schangelog-format:\s+([0-9a-z]+)\W/; } close $format_fh; } return $format; } =head1 FUNCTIONS =over 4 =item $fields = changelog_parse(%opts) This function will parse a changelog. In list context, it returns as many L objects as the parser did create. In scalar context, it will return only the first one. If the parser did not return any data, it will return an empty list in list context or undef on scalar context. If the parser failed, it will die. Any parse errors will be printed as warnings on standard error, but this can be disabled by passing $opts{verbose} to 0. The parsing itself is done by a parser module (searched in the standard perl library directories. That module is named according to the format that it is able to parse, with the name capitalized. By default it is either L (from the "debian" format) or the format name looked up in the 40 last lines of the changelog itself (extracted with this perl regular expression "\schangelog-format:\s+([0-9a-z]+)\W"). But it can be overridden with $opts{changelogformat}. All the other keys in %opts are forwarded to the parser module constructor. Options: =over =item B Set the changelog file to parse. Defaults to F. =item B