Debian.pm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along
  14. # with this program; if not, write to the Free Software Foundation, Inc.,
  15. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. package Dpkg::Changelog::Entry::Debian;
  17. use strict;
  18. use warnings;
  19. use Exporter;
  20. use Dpkg::Changelog::Entry;
  21. use base qw(Exporter Dpkg::Changelog::Entry);
  22. our @EXPORT_OK = qw($regex_header $regex_trailer);
  23. use Dpkg::Control::Changelog;
  24. use Dpkg::Version;
  25. use Dpkg::Changelog qw(:util);
  26. =head1 NAME
  27. Dpkg::Changelog::Entry::Debian - represents a Debian changelog entry
  28. =head1 DESCRIPTION
  29. This object represents a Debian changelog entry. It implements the
  30. generic interface Dpkg::Changelog::Entry. Only functions specific to this
  31. implementation are described below.
  32. =head1 VARIABLES
  33. $regex_header, $regex_trailer are two regular expressions that can be used
  34. to match a line and know whether it's a valid header/trailer line.
  35. The matched content for $regex_header is the source package name ($1), the
  36. version ($2), the target distributions ($3) and the options on the rest
  37. of the line ($4). For $regex_trailer, it's the maintainer name ($1), its
  38. email ($2), some blanks ($3) and the timestamp ($4).
  39. =cut
  40. my $name_chars = qr/[-+0-9a-z.]/i;
  41. our $regex_header = qr/^(\w$name_chars*) \(([^\(\) \t]+)\)((?:\s+$name_chars+)+)\;(.*)$/i;
  42. our $regex_trailer = qr/^ \-\- (.*) <(.*)>( ?)((\w+\,\s*)?\d{1,2}\s+\w+\s+\d{4}\s+\d{1,2}:\d\d:\d\d\s+[-+]\d{4}(\s+\([^\\\(\)]\))?)\s*$/o;
  43. =head1 FUNCTIONS
  44. =over 4
  45. =item $entry->normalize()
  46. Normalize the content. Strip whitespaces at end of lines, use a single
  47. empty line to separate each part.
  48. =cut
  49. sub normalize {
  50. my ($self) = @_;
  51. $self->SUPER::normalize();
  52. #XXX: recreate header/trailer
  53. }
  54. sub get_source {
  55. my ($self) = @_;
  56. if (defined($self->{header}) and $self->{header} =~ $regex_header) {
  57. return $1;
  58. }
  59. return undef;
  60. }
  61. sub get_version {
  62. my ($self) = @_;
  63. if (defined($self->{header}) and $self->{header} =~ $regex_header) {
  64. return Dpkg::Version->new($2) || $2;
  65. }
  66. return undef;
  67. }
  68. sub get_distributions {
  69. my ($self) = @_;
  70. if (defined($self->{header}) and $self->{header} =~ $regex_header) {
  71. my $value = $3;
  72. $value =~ s/^\s+//;
  73. my @dists = split(/\s+/, $value);
  74. return @dists if wantarray;
  75. return $dists[0];
  76. }
  77. return () if wantarray;
  78. return undef;
  79. }
  80. sub get_optional_fields {
  81. my ($self) = @_;
  82. my $f = Dpkg::Control::Changelog->new();
  83. if (defined($self->{header}) and $self->{header} =~ $regex_header) {
  84. my $options = $4;
  85. $options =~ s/^\s+//;
  86. foreach my $opt (split(/\s*,\s*/, $options)) {
  87. if ($opt =~ m/^([-0-9a-z]+)\=\s*(.*\S)$/i) {
  88. $f->{$1} = $2;
  89. }
  90. }
  91. }
  92. my $closes = find_closes(join("\n", @{$self->{changes}}));
  93. if (@$closes) {
  94. $f->{Closes} = join(" ", @$closes);
  95. }
  96. return $f;
  97. }
  98. sub get_urgency {
  99. my ($self) = @_;
  100. my $f = $self->get_optional_fields();
  101. if (exists $f->{Urgency}) {
  102. $f->{Urgency} =~ s/\s.*$//;
  103. return lc($f->{Urgency});
  104. }
  105. return undef;
  106. }
  107. sub get_maintainer {
  108. my ($self) = @_;
  109. if (defined($self->{trailer}) and $self->{trailer} =~ $regex_trailer) {
  110. return "$1 <$2>";
  111. }
  112. return undef;
  113. }
  114. sub get_timestamp {
  115. my ($self) = @_;
  116. if (defined($self->{trailer}) and $self->{trailer} =~ $regex_trailer) {
  117. return $4;
  118. }
  119. return undef;
  120. }
  121. =back
  122. =head1 AUTHOR
  123. Raphaël Hertzog <hertzog@debian.org>.
  124. =cut
  125. 1;