1 # Copyright © 2008-2011 Raphaël Hertzog <hertzog@debian.org>
2 # Copyright © 2008-2018 Guillem Jover <guillem@debian.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 Dpkg::Source::Format - manipulate debian/source/format files
25 This module provides a class that can manipulate Debian source
26 package F<debian/source/format> files.
30 package Dpkg
::Source
::Format
1.00;
36 use Dpkg
::ErrorHandling
;
38 use parent
qw(Dpkg::Interface::Storable);
44 =item $f = Dpkg::Source::Format->new(%opts)
46 Creates a new object corresponding to a source package's
47 F<debian/source/format> file.
55 Set the filename to use to parse and set the format.
59 Set and validate the format to use instead of loading the default file,
60 if no filename has been specified.
67 my ($this, %opts) = @_;
68 my $class = ref($this) || $this;
77 if (exists $opts{filename
}) {
78 $self->load($opts{filename
}, compression
=> 0);
79 } elsif ($opts{format
}) {
80 $self->set($opts{format
});
85 =item $f->set_from_parts($major[, $minor[, $variant]])
87 Sets the source format from its parts. The $major part is mandatory.
88 The $minor and $variant parts are optional.
90 B<Notice>: This function performs no validation.
95 my ($self, $major, $minor, $variant) = @_;
97 $self->{major
} = $major;
98 $self->{minor
} = $minor // 0;
99 $self->{variant
} = $variant;
102 =item ($major, $minor, $variant) = $f->set($format)
104 Sets (and validates) the source $format specified. Will return the parsed
105 format parts as a list, the optional $minor and $variant parts might be
111 my ($self, $format) = @_;
113 if ($format =~ /^(\d+)(?:\.(\d+))?(?:\s+\(([a-z0-9]+)\))?$/) {
114 my ($major, $minor, $variant) = ($1, $2, $3);
116 $self->set_from_parts($major, $minor, $variant);
118 return ($major, $minor, $variant);
120 error
(g_
("source package format '%s' is invalid"), $format);
124 =item ($major, $minor, $variant) = $f->get()
126 =item $format = $f->get()
128 Gets the source format, either as properly formatted scalar, or as a list
129 of its parts, where the optional $minor and $variant parts might be undef.
137 return ($self->{major
}, $self->{minor
}, $self->{variant
});
139 my $format = "$self->{major}.$self->{minor}";
140 $format .= " ($self->{variant})" if defined $self->{variant
};
146 =item $count = $f->parse($fh, $desc)
148 Parse the source format string from $fh, with filehandle description $desc.
153 my ($self, $fh, $desc) = @_;
156 chomp $format if defined $format;
157 error
(g_
('%s is empty'), $desc)
158 unless defined $format and length $format;
165 =item $count = $f->load($filename)
167 Parse $filename contents for a source package format string.
169 =item $str = $f->output([$fh])
173 Returns a string representing the source package format version.
174 If $fh is set, it prints the string to the filehandle.
179 my ($self, $fh) = @_;
181 my $str = $self->get();
183 print { $fh } "$str\n" if defined $fh;
188 =item $f->save($filename)
190 Save the source package format into the given $filename.
196 =head2 Version 1.00 (dpkg 1.19.3)
198 Mark the module as public.