1 # Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org>
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.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 Dpkg::Control - parse and manipulate official control-like information
24 The Dpkg::Control object is a smart version of L<Dpkg::Control::Hash>.
25 It associates a type to the control information. That type can be
26 used to know what fields are allowed and in what order they must be
29 The types are constants that are exported by default. Here's the full
36 This type is the default type, it indicates that the type of control
37 information is not yet known.
41 Corresponds to the first stanza in a F<debian/control> file in
42 a Debian source package.
46 Corresponds to subsequent stanza in a F<debian/control> file
47 in a Debian source package.
49 =item CTRL_REPO_RELEASE
51 Corresponds to a F<Release> file in a repository.
55 Corresponds to a stanza in a F<Sources> file of a source package
60 Corresponds to a stanza in a F<Packages> file of a binary package
65 Corresponds to a .dsc file of a Debian source package.
69 Corresponds to the F<control> file generated by dpkg-gencontrol
70 (F<DEBIAN/control>) and to the same file inside .deb packages.
72 =item CTRL_FILE_BUILDINFO
74 Corresponds to a .buildinfo file.
76 =item CTRL_FILE_CHANGES
78 Corresponds to a .changes file.
80 =item CTRL_FILE_VENDOR
82 Corresponds to a vendor file in $Dpkg::CONFDIR/origins/.
84 =item CTRL_FILE_STATUS
86 Corresponds to a stanza in dpkg's F<status> file ($Dpkg::ADMINDIR/status).
90 Corresponds to the output of dpkg-parsechangelog.
92 =item CTRL_COPYRIGHT_HEADER
94 Corresponds to the header stanza in a F<debian/copyright> file in
95 machine readable format.
97 =item CTRL_COPYRIGHT_FILES
99 Corresponds to a files stanza in a F<debian/copyright> file in
100 machine readable format.
102 =item CTRL_COPYRIGHT_LICENSE
104 Corresponds to a license stanza in a F<debian/copyright> file in
105 machine readable format.
109 Corresponds to a package tests control file in F<debian/tests/control>.
115 package Dpkg
::Control
1.03;
134 CTRL_COPYRIGHT_HEADER
136 CTRL_COPYRIGHT_LICENSE
140 use Exporter
qw(import);
143 use Dpkg
::ErrorHandling
;
144 use Dpkg
::Control
::Types
;
145 use Dpkg
::Control
::Hash
;
146 use Dpkg
::Control
::Fields
;
148 use parent
qw(Dpkg::Control::Hash);
152 All the methods of L<Dpkg::Control::Hash> are available. Those listed below
153 are either new or overridden with a different behavior.
157 =item $c = Dpkg::Control->new(%opts)
159 If the "type" option is given, it's used to setup default values
160 for other options. See set_options() for more details.
165 my ($this, %opts) = @_;
166 my $class = ref($this) || $this;
168 my $self = Dpkg
::Control
::Hash
->new();
170 $self->set_options(%opts);
175 =item $c->set_options(%opts)
177 Changes the value of one or more options. If the "type" option is changed,
178 it is used first to define default values for others options. The option
179 "allow_pgp" is set to 1 for CTRL_PKG_SRC, CTRL_FILE_CHANGES and
180 CTRL_REPO_RELEASE and to 0 otherwise. The option "drop_empty" is set to 0
181 for CTRL_INFO_PKG and CTRL_INFO_SRC and to 1 otherwise. The option "name"
182 is set to a textual description of the type of control information.
184 The output order is also set to match the ordered list returned by
185 Dpkg::Control::Fields::field_ordered_list($type).
190 my ($self, %opts) = @_;
191 if (exists $opts{type
}) {
193 $$self->{allow_pgp
} = ($t & (CTRL_PKG_SRC
| CTRL_FILE_CHANGES
| CTRL_REPO_RELEASE
)) ?
1 : 0;
194 $$self->{drop_empty
} = ($t & (CTRL_INFO_PKG
| CTRL_INFO_SRC
)) ?
0 : 1;
195 if ($t == CTRL_INFO_SRC
) {
196 $$self->{name
} = g_
('general section of control info file');
197 } elsif ($t == CTRL_INFO_PKG
) {
198 $$self->{name
} = g_
("package's section of control info file");
199 } elsif ($t == CTRL_CHANGELOG
) {
200 $$self->{name
} = g_
('parsed version of changelog');
201 } elsif ($t == CTRL_COPYRIGHT_HEADER
) {
202 $$self->{name
} = g_
('header stanza of copyright file');
203 } elsif ($t == CTRL_COPYRIGHT_FILES
) {
204 $$self->{name
} = g_
('files stanza of copyright file');
205 } elsif ($t == CTRL_COPYRIGHT_HEADER
) {
206 $$self->{name
} = g_
('license stanza of copyright file');
207 } elsif ($t == CTRL_TESTS
) {
208 $$self->{name
} = g_
("package's tests control file");
209 } elsif ($t == CTRL_REPO_RELEASE
) {
210 $$self->{name
} = sprintf(g_
("repository's %s file"), 'Release');
211 } elsif ($t == CTRL_INDEX_SRC
) {
212 $$self->{name
} = sprintf(g_
("stanza in repository's %s file"), 'Sources');
213 } elsif ($t == CTRL_INDEX_PKG
) {
214 $$self->{name
} = sprintf(g_
("stanza in repository's %s file"), 'Packages');
215 } elsif ($t == CTRL_PKG_SRC
) {
216 $$self->{name
} = sprintf(g_
('%s file'), '.dsc');
217 } elsif ($t == CTRL_PKG_DEB
) {
218 $$self->{name
} = g_
('control info of a .deb package');
219 } elsif ($t == CTRL_FILE_BUILDINFO
) {
220 $$self->{name
} = g_
('build information file');
221 } elsif ($t == CTRL_FILE_CHANGES
) {
222 $$self->{name
} = sprintf(g_
('%s file'), '.changes');
223 } elsif ($t == CTRL_FILE_VENDOR
) {
224 $$self->{name
} = g_
('vendor file');
225 } elsif ($t == CTRL_FILE_STATUS
) {
226 $$self->{name
} = g_
("stanza in dpkg's status file");
228 $self->set_output_order(field_ordered_list
($opts{type
}));
231 # Options set by the user override default values
232 $$self->{$_} = $opts{$_} foreach keys %opts;
237 Returns the type of control information stored. See the type parameter
244 return $$self->{type
};
251 =head2 Version 1.03 (dpkg 1.18.11)
253 New type: CTRL_FILE_BUILDINFO.
255 =head2 Version 1.02 (dpkg 1.18.8)
257 New type: CTRL_TESTS.
259 =head2 Version 1.01 (dpkg 1.18.5)
261 New types: CTRL_REPO_RELEASE, CTRL_COPYRIGHT_HEADER, CTRL_COPYRIGHT_FILES,
262 CTRL_COPYRIGHT_LICENSE.
264 =head2 Version 1.00 (dpkg 1.15.6)
266 Mark the module as public.