home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / perl5 / Parse / DebianChangelog / Util.pm < prev   
Encoding:
Perl POD Document  |  2009-02-17  |  4.6 KB  |  185 lines

  1. #
  2. # Parse::DebianChangelog::Util
  3. #
  4. # Copyright 1996 Ian Jackson
  5. # Copyright 2005 Frank Lichtenheld <frank@lichtenheld.de>
  6. #
  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.
  11. #
  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.
  16. #
  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
  20. #
  21.  
  22. =head1 NAME
  23.  
  24. Parse::DebianChangelog::Util - utility functions for parsing Debian changelogs
  25.  
  26. =head1 DESCRIPTION
  27.  
  28. This is currently only used internally by Parse::DebianChangelog.
  29. There may be still API changes until this module is finalized.
  30.  
  31. =head2 Functions
  32.  
  33. =cut
  34.  
  35. package Parse::DebianChangelog::Util;
  36.  
  37. use strict;
  38. use warnings;
  39.  
  40. require Exporter;
  41.  
  42. our @ISA = qw(Exporter);
  43.  
  44. our %EXPORT_TAGS = ( 'all' => [ qw(
  45.          find_closes
  46.          data2rfc822
  47.          data2rfc822_mult
  48.          get_dpkg_changes
  49. ) ] );
  50.  
  51. our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
  52.  
  53. our @EXPORT = qw(
  54. );
  55.  
  56. =pod
  57.  
  58. =head3 find_closes
  59.  
  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.
  63.  
  64. =cut
  65.  
  66. sub find_closes {
  67.     my $changes = shift;
  68.     my @closes = ();
  69.  
  70.     while ($changes && ($changes =~ /closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*/ig)) {
  71.     push(@closes, $& =~ /\#?\s?(\d+)/g);
  72.     }
  73.  
  74.     @closes = sort { $a <=> $b } @closes;
  75.     return \@closes;
  76. }
  77.  
  78. =pod
  79.  
  80. =head3 data2rfc822
  81.  
  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.
  86.  
  87. Return the data in RFC822 format as string.
  88.  
  89. =cut
  90.  
  91. sub data2rfc822 {
  92.     my ($data, $fieldimps) = @_;
  93.     my $rfc822_str = '';
  94.  
  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
  100.         && warn(__g("field %s has newline then non whitespace >%s<",
  101.             $f, $v ));
  102.     $v =~ m/\n[ \t]*\n/o && warn(__g("field %s has blank lines >%s<",
  103.                      $f, $v ));
  104.     $v =~ m/\n$/o && warn(__g("field %s has trailing newline >%s<",
  105.                   $f, $v ));
  106.     $v =~ s/\$\{\}/\$/go;
  107.     $rfc822_str .= "$f: $v\n";
  108.     }
  109.  
  110.     return $rfc822_str;
  111. }
  112.  
  113. =pod
  114.  
  115. =head3 data2rfc822_mult
  116.  
  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>.
  120.  
  121. Calls L<data2rfc822> for each element of the array given as first
  122. argument and returns the concatenated results.
  123.  
  124. =cut
  125.  
  126. sub data2rfc822_mult {
  127.     my ($data, $fieldimps) = @_;
  128.     my @rfc822 = ();
  129.  
  130.     foreach my $entry (@$data) {
  131.     push @rfc822, data2rfc822($entry,$fieldimps);
  132.     }
  133.  
  134.     return join "\n", @rfc822;
  135. }
  136.  
  137. =pod
  138.  
  139. =head3 get_dpkg_changes
  140.  
  141. Takes a Parse::DebianChangelog::Entry object as first argument.
  142.  
  143. Returns a string that is suitable for using it in a C<Changes> field
  144. in the output format of C<dpkg-parsechangelog>.
  145.  
  146. =cut
  147.  
  148. sub get_dpkg_changes {
  149.     my $changes = "\n ".($_[0]->Header||'')."\n .\n".($_[0]->Changes||'');
  150.     chomp $changes;
  151.     $changes =~ s/^ $/ ./mgo;
  152.     return $changes;
  153. }
  154.  
  155. 1;
  156. __END__
  157.  
  158. =head1 SEE ALSO
  159.  
  160. Parse::DebianChangelog, Parse::DebianChangelog::Entry
  161.  
  162. =head1 AUTHOR
  163.  
  164. Frank Lichtenheld, E<lt>frank@lichtenheld.deE<gt>
  165.  
  166. =head1 COPYRIGHT AND LICENSE
  167.  
  168. Copyright (C) 2005 by Frank Lichtenheld
  169.  
  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.
  174.  
  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.
  179.  
  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
  183.  
  184. =cut
  185.