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
99 $v =~ m/\n\S/o && warn("field $f has newline then non whitespace >$v<");
100 $v =~ m/\n[ \t]*\n/o && warn("field $f has blank lines >$v<");
101 $v =~ m/\n$/o && warn("field $f has trailing newline >$v<");
102 $v =~ s/\$\{\}/\$/go;
103 $rfc822_str .= "$f: $v\n";
111 =head3 data2rfc822_mult
113 The first argument should be an array ref to an array of hash references.
114 The second argument is a hash reference and has the same meaning as
115 the second argument of L<data2rfc822>.
117 Calls L<data2rfc822> for each element of the array given as first
118 argument and returns the concatenated results.
122 sub data2rfc822_mult {
123 my ($data, $fieldimps) = @_;
126 foreach my $entry (@$data) {
127 push @rfc822, data2rfc822($entry,$fieldimps);
130 return join "\n", @rfc822;
135 =head3 get_dpkg_changes
137 Takes a Parse::DebianChangelog::Entry object as first argument.
139 Returns a string that is suitable for using it in a C<Changes> field
140 in the output format of C<dpkg-parsechangelog>.
144 sub get_dpkg_changes {
145 my $changes = "\n ".$_[0]->Header."\n .\n".$_[0]->Changes;
147 $changes =~ s/^ $/ ./mgo;
156 Parse::DebianChangelog, Parse::DebianChangelog::Entry
160 Frank Lichtenheld, E<lt>frank@lichtenheld.deE<gt>
162 =head1 COPYRIGHT AND LICENSE
164 Copyright (C) 2005 by Frank Lichtenheld
166 This program is free software; you can redistribute it and/or modify
167 it under the terms of the GNU General Public License as published by
168 the Free Software Foundation; either version 2 of the License, or
169 (at your option) any later version.
171 This program is distributed in the hope that it will be useful,
172 but WITHOUT ANY WARRANTY; without even the implied warranty of
173 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
174 GNU General Public License for more details.
176 You should have received a copy of the GNU General Public License
177 along with this program; if not, write to the Free Software
178 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA