2 # Parse::DebianChangelog::Util
4 # Copyright 1996 Ian Jackson
5 # Copyright 2005 Frank Lichtenheld <frank@lichtenheld.de>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 Parse::DebianChangelog::Util - utility functions for parsing Debian changelogs
28 This is currently only used internally by Parse::DebianChangelog.
29 There may be still API changes until this module is finalized.
35 package Parse::DebianChangelog::Util;
42 our @ISA = qw(Exporter);
44 our %EXPORT_TAGS = ( 'all' => [ qw(
51 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
60 Takes one string as argument and finds "Closes: #123456, #654321" statements
61 as supported by the Debian Archive software in it. Returns all closed bug
62 numbers in an array reference.
70 while ($changes && ($changes =~ /closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*/ig)) {
71 push(@closes, $& =~ /\#?\s?(\d+)/g);
74 @closes = sort { $a <=> $b } @closes;
82 Takes two hash references as arguments. The first should contain the
83 data to output in RFC822 format. The second can contain a sorting order
84 for the fields. The higher the numerical value of the hash value, the
85 earlier the field is printed if it exists.
87 Return the data in RFC822 format as string.
92 my ($data, $fieldimps) = @_;
95 # based on /usr/lib/dpkg/controllib.pl
96 for my $f (sort { $fieldimps->{$b} <=> $fieldimps->{$a} } keys %$data) {
97 my $v= $data->{$f} or next;
98 $v =~ m/\S/o || next; # delete whitespace-only fields
100 && warn(__g("field %s has newline then non whitespace >%s<",
102 $v =~ m/\n[ \t]*\n/o && warn(__g("field %s has blank lines >%s<",
104 $v =~ m/\n$/o && warn(__g("field %s has trailing newline >%s<",
106 $v =~ s/\$\{\}/\$/go;
107 $rfc822_str .= "$f: $v\n";
115 =head3 data2rfc822_mult
117 The first argument should be an array ref to an array of hash references.
118 The second argument is a hash reference and has the same meaning as
119 the second argument of L<data2rfc822>.
121 Calls L<data2rfc822> for each element of the array given as first
122 argument and returns the concatenated results.
126 sub data2rfc822_mult {
127 my ($data, $fieldimps) = @_;
130 foreach my $entry (@$data) {
131 push @rfc822, data2rfc822($entry,$fieldimps);
134 return join "\n", @rfc822;
139 =head3 get_dpkg_changes
141 Takes a Parse::DebianChangelog::Entry object as first argument.
143 Returns a string that is suitable for using it in a C<Changes> field
144 in the output format of C<dpkg-parsechangelog>.
148 sub get_dpkg_changes {
149 my $changes = "\n ".($_[0]->Header||'')."\n .\n".($_[0]->Changes||'');
151 $changes =~ s/^ $/ ./mgo;
160 Parse::DebianChangelog, Parse::DebianChangelog::Entry
164 Frank Lichtenheld, E<lt>frank@lichtenheld.deE<gt>
166 =head1 COPYRIGHT AND LICENSE
168 Copyright (C) 2005 by Frank Lichtenheld
170 This program is free software; you can redistribute it and/or modify
171 it under the terms of the GNU General Public License as published by
172 the Free Software Foundation; either version 2 of the License, or
173 (at your option) any later version.
175 This program is distributed in the hope that it will be useful,
176 but WITHOUT ANY WARRANTY; without even the implied warranty of
177 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
178 GNU General Public License for more details.
180 You should have received a copy of the GNU General Public License
181 along with this program; if not, write to the Free Software
182 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA