Dpkg/Control.pm

filter: Statementstmt 82.4% 47 / 57 Branchbran 57.8% 22 / 38 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 3 / 3 totaltotal 73.6% 84 / 114 CC 22 SCAR 35.7
CC
22
Cov
71%
set_options
53.5
new
2.0
BEGIN
1.0
CRAP 35.5
« Dpkg/OpenPGP/Backend/Sequoia.pm ↑ Summary Dpkg/Vendor/Ubuntu.pm »
1 # Copyright © 2007-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
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 Dpkg::Control - parse and manipulate official control-like information
21  
22 =head1 DESCRIPTION
23  
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
27 output.
28  
29 The types are constants that are exported by default. Here's the full
30 list:
31  
32 =over 4
33  
34 =item CTRL_UNKNOWN
35  
36 This type is the default type, it indicates that the type of control
37 information is not yet known.
38  
39 =item CTRL_TMPL_SRC
40  
41 Corresponds to the first source package stanza in a F<debian/control> file in
42 a Debian source package.
43  
44 =item CTRL_TMPL_PKG
45  
46 Corresponds to subsequent binary package stanza in a F<debian/control> file
47 in a Debian source package.
48  
49 =item CTRL_REPO_RELEASE
50  
51 Corresponds to a F<Release> file in a repository.
52  
53 =item CTRL_REPO_SRC
54  
55 Corresponds to a stanza in a F<Sources> file of a source package
56 repository.
57  
58 =item CTRL_REPO_PKG
59  
60 Corresponds to a stanza in a F<Packages> file of a binary package
61 repository.
62  
63 =item CTRL_DSC
64  
65 Corresponds to a .dsc file of a Debian source package.
66  
67 =item CTRL_DEB
68  
69 Corresponds to the F<control> file generated by dpkg-gencontrol
70 (F<DEBIAN/control>) and to the same file inside .deb packages.
71  
72 =item CTRL_FILE_BUILDINFO
73  
74 Corresponds to a .buildinfo file.
75  
76 =item CTRL_FILE_CHANGES
77  
78 Corresponds to a .changes file.
79  
80 =item CTRL_FILE_VENDOR
81  
82 Corresponds to a vendor file in $Dpkg::CONFDIR/origins/.
83  
84 =item CTRL_FILE_STATUS
85  
86 Corresponds to a stanza in dpkg's F<status> file ($Dpkg::ADMINDIR/status).
87  
88 =item CTRL_CHANGELOG
89  
90 Corresponds to the output of dpkg-parsechangelog.
91  
92 =item CTRL_COPYRIGHT_HEADER
93  
94 Corresponds to the header stanza in a F<debian/copyright> file in
95 machine readable format.
96  
97 =item CTRL_COPYRIGHT_FILES
98  
99 Corresponds to a files stanza in a F<debian/copyright> file in
100 machine readable format.
101  
102 =item CTRL_COPYRIGHT_LICENSE
103  
104 Corresponds to a license stanza in a F<debian/copyright> file in
105 machine readable format.
106  
107 =item CTRL_TESTS
108  
109 Corresponds to a source package tests control file in F<debian/tests/control>.
110  
111 =item CTRL_INFO_SRC
112  
113 Deprecated alias for CTRL_TMPL_SRC.
114  
115 =item CTRL_INFO_PKG
116  
117 Deprecated alias for CTRL_TMPL_PKG.
118  
119 =item CTRL_PKG_SRC
120  
121 Deprecated alias for CTRL_DSC.
122  
123 =item CTRL_PKG_DEB
124  
125 Deprecated alias for CTRL_DEB.
126  
127 =item CTRL_INDEX_SRC
128  
129 Deprecated alias for CTRL_REPO_SRC.
130  
131 =item CTRL_INDEX_PKG
132  
133 Deprecated alias for CTRL_REPO_PKG.
134  
135 =back
136  
137 =cut
138  
139 package Dpkg::Control 1.05;
140  
141 9 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 9 our @EXPORT = qw(
144 CTRL_UNKNOWN
145 CTRL_TMPL_SRC
146 CTRL_TMPL_PKG
147 CTRL_REPO_RELEASE
148 CTRL_REPO_SRC
149 CTRL_REPO_PKG
150 CTRL_DSC
151 CTRL_DEB
152 CTRL_FILE_BUILDINFO
153 CTRL_FILE_CHANGES
154 CTRL_FILE_VENDOR
155 CTRL_FILE_STATUS
156 CTRL_CHANGELOG
157 CTRL_COPYRIGHT_HEADER
158 CTRL_COPYRIGHT_FILES
159 CTRL_COPYRIGHT_LICENSE
160 CTRL_TESTS
161  
162 CTRL_INFO_SRC
163 CTRL_INFO_PKG
164 CTRL_PKG_SRC
165 CTRL_PKG_DEB
166 CTRL_INDEX_SRC
167 CTRL_INDEX_PKG
168 );
169  
170 9 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
171  
172 9 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
173 9 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
174 9 ▶use Dpkg::Control::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
175 9 ▶use Dpkg::Control::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
176 9 ▶use Dpkg::Control::Fields;
Subroutine BEGIN: called CC=1 SCAR=0.0
177  
178 9 ▶use parent qw(Dpkg::Control::Hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
179  
180 =head1 METHODS
181  
182 All the methods of L<Dpkg::Control::Hash> are available. Those listed below
183 are either new or overridden with a different behavior.
184  
185 =over 4
186  
187 =item $ctrl = Dpkg::Control->new(%opts)
188  
189 Create a new deb822 control object.
190  
191 Options:
192  
193 =over
194  
195 =item B<type>
196  
197 Set the deb822 control type, used to setup default values for other options.
198  
199 =back
200  
201 See set_options() for more details.
202  
203 =cut
204  
205 800 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
206 800 my ($this, %opts) = @_;
207 800 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
08000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
208  
209 800 my $self = Dpkg::Control::Hash->new();
210 800 bless $self, $class;
211 800 $self->set_options(%opts);
212  
213 800 return $self;
214 }
215  
216 =item $ctrl->set_options(%opts)
217  
218 Changes the value of one or more options.
219  
220 Options:
221  
222 =over
223  
224 =item B<type>
225  
226 Sets the deb822 control object type, used to define default values for others
227 options.
228  
229 The output order is also set to match the ordered list returned by
230 Dpkg::Control::Fields::field_ordered_list($type).
231  
232 =item B<name>
233  
234 Sets a textual description of the type of control information.
235  
236 =item B<allow_pgp>
237  
238 Sets whether the parser accepts OpenPGP signatures around the deb822
239 control information.
240  
241 By default it is set to 1 for CTRL_DSC, CTRL_FILE_CHANGES and
242 CTRL_REPO_RELEASE and to 0 otherwise.
243  
244 =item B<allow_duplicate>
245  
246 Sets whether the parser allows duplicate fields in deb822 control information.
247  
248 =item B<keep_duplicate>
249  
250 Sets whether the parser will keep values for duplicate fields found in
251 deb822 control information (when B<allow_duplicate> is enabled),
252 as array references.
253  
254 =item B<drop_empty>
255  
256 Sets whether empty fields are dropped during output.
257  
258 By default it is set to 0 for CTRL_TMPL_SRC and CTRL_TMPL_PKG and
259 to 1 otherwise.
260  
261 =back
262  
263 =cut
264  
265 800 ▶sub set_options {
Subroutine set_options: called CC=21 SCAR=39.8
Pod documented
266 800 my ($self, %opts) = @_;
267 800 ▶ if (exists $opts{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"type"}) 800 0 800
268 800 my $t = $opts{type};
269 800 ▶ $$self->{allow_pgp} = ($t & (CTRL_DSC | CTRL_FILE_CHANGES | CTRL_REPO_RELEASE)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$t & 1104 ? : 9 791 800
270 800 ▶ $$self->{drop_empty} = ($t & (CTRL_TMPL_SRC | CTRL_TMPL_PKG)) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$t & 3 ? : 26 774 800
271 800 ▶ if ($t == CTRL_TMPL_SRC) {
Branch: 16 branches
BranchTrueFalseTotal
if ($t == 1) { } 8 792 800
elsif ($t == 2) { } 18 774 792
elsif ($t == 512) { } 750 24 774
elsif ($t == 2048) { } 0 24 24
elsif ($t == 4096) { } 0 24 24
elsif ($t == 2048) { } 0 24 24
elsif ($t == 16384) { } 12 12 24
elsif ($t == 1024) { } 0 12 12
elsif ($t == 4) { } 0 12 12
elsif ($t == 8) { } 0 12 12
elsif ($t == 16) { } 9 3 12
elsif ($t == 32) { } 3 0 3
elsif ($t == 32768) { } 0 0 0
elsif ($t == 64) { } 0 0 0
elsif ($t == 128) { } 0 0 0
elsif ($t == 256) { } 0 0 0
272 8 $$self->{name} = g_('source package stanza of template control file');
273 } elsif ($t == CTRL_TMPL_PKG) {
274 18 $$self->{name} = g_('binary package stanza of template control file');
275 } elsif ($t == CTRL_CHANGELOG) {
276 750 $$self->{name} = g_('parsed version of changelog');
277 } elsif ($t == CTRL_COPYRIGHT_HEADER) {
278 0 $$self->{name} = g_('header stanza of copyright file');
279 } elsif ($t == CTRL_COPYRIGHT_FILES) {
280 0 $$self->{name} = g_('files stanza of copyright file');
281 } elsif ($t == CTRL_COPYRIGHT_HEADER) {
282 0 $$self->{name} = g_('license stanza of copyright file');
283 } elsif ($t == CTRL_TESTS) {
284 12 $$self->{name} = g_('source package tests control file');
285 } elsif ($t == CTRL_REPO_RELEASE) {
286 0 $$self->{name} = sprintf(g_("repository's %s file"), 'Release');
287 } elsif ($t == CTRL_REPO_SRC) {
288 0 $$self->{name} = sprintf(g_("stanza in repository's %s file"), 'Sources');
289 } elsif ($t == CTRL_REPO_PKG) {
290 0 $$self->{name} = sprintf(g_("stanza in repository's %s file"), 'Packages');
291 } elsif ($t == CTRL_DSC) {
292 9 $$self->{name} = g_('source package control file');
293 } elsif ($t == CTRL_DEB) {
294 3 $$self->{name} = g_('binary package control file');
295 } elsif ($t == CTRL_FILE_BUILDINFO) {
296 0 $$self->{name} = g_('build information file');
297 } elsif ($t == CTRL_FILE_CHANGES) {
298 0 $$self->{name} = g_('upload changes control file');
299 } elsif ($t == CTRL_FILE_VENDOR) {
300 0 $$self->{name} = g_('vendor file');
301 } elsif ($t == CTRL_FILE_STATUS) {
302 0 $$self->{name} = g_("stanza in dpkg's status file");
303 }
304 800 $self->set_output_order(field_ordered_list($opts{type}));
305 }
306  
307 # Options set by the user override default values.
308 800 $$self->{$_} = $opts{$_} foreach keys %opts;
309 }
310  
311 =item $type = $ctrl->get_type()
312  
313 Returns the type of control information stored. See the type parameter
314 set during new().
315  
316 =cut
317  
318 723 ▶sub get_type {
Subroutine get_type: called CC=1 SCAR=0.0
Pod documented
319 723 my $self = shift;
320 723 return $$self->{type};
321 }
322  
323 =back
324  
325 =head1 CHANGES
326  
327 =head2 Version 1.05 (dpkg 1.22.12)
328  
329 Deprecate types: CTRL_INFO_SRC, CTRL_INFO_PKG, CTRL_PKG_SRC, CTRL_PKG_DEB,
330 CTRL_INDEX_SRC, CTRL_INDEX_PKG.
331  
332 =head2 Version 1.04 (dpkg 1.22.2)
333  
334 New types: CTRL_TMPL_SRC, CTRL_TMPL_PKG, CTRL_REPO_SRC, CTRL_REPO_PKG,
335 CTRL_DSC, CTRL_DEB.
336  
337 =head2 Version 1.03 (dpkg 1.18.11)
338  
339 New type: CTRL_FILE_BUILDINFO.
340  
341 =head2 Version 1.02 (dpkg 1.18.8)
342  
343 New type: CTRL_TESTS.
344  
345 =head2 Version 1.01 (dpkg 1.18.5)
346  
347 New types: CTRL_REPO_RELEASE, CTRL_COPYRIGHT_HEADER, CTRL_COPYRIGHT_FILES,
348 CTRL_COPYRIGHT_LICENSE.
349  
350 =head2 Version 1.00 (dpkg 1.15.6)
351  
352 Mark the module as public.
353  
354 =cut
355  
356 9 1;
« Dpkg/OpenPGP/Backend/Sequoia.pm ↑ Summary Dpkg/Vendor/Ubuntu.pm »