| 1 | # Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org> | ||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright © 2009, 2012-2019, 2021 Guillem Jover <guillem@debian.org> | ||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||
| 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/>. | ||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||
| 17 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||
| 21 | Dpkg::Control::HashCore - parse and manipulate a stanza of deb822 fields | ||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||
| 25 | The L<Dpkg::Control::Hash> class is a hash-like representation of a set of | ||||||||||||||||||||||||||||||||||||||||
| 26 | L<deb822(5)> fields. The fields names are case insensitive and are always | ||||||||||||||||||||||||||||||||||||||||
| 27 | capitalized the same when output (see field_capitalize() function in | ||||||||||||||||||||||||||||||||||||||||
| 28 | L<Dpkg::Control::Fields>). | ||||||||||||||||||||||||||||||||||||||||
| 29 | The order in which fields have been set is remembered and is used | ||||||||||||||||||||||||||||||||||||||||
| 30 | to be able to dump back the same content. The output order can also be | ||||||||||||||||||||||||||||||||||||||||
| 31 | overridden if needed. | ||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||
| 33 | You can store arbitrary values in the hash, they will always be properly | ||||||||||||||||||||||||||||||||||||||||
| 34 | escaped in the output to conform to the syntax of control files. This is | ||||||||||||||||||||||||||||||||||||||||
| 35 | relevant mainly for multilines values: while the first line is always output | ||||||||||||||||||||||||||||||||||||||||
| 36 | unchanged directly after the field name, supplementary lines are | ||||||||||||||||||||||||||||||||||||||||
| 37 | modified. Empty lines and lines containing only dots are prefixed with | ||||||||||||||||||||||||||||||||||||||||
| 38 | " ." (space + dot) while other lines are prefixed with a single space. | ||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||
| 40 | During parsing, trailing spaces are stripped on all lines while leading | ||||||||||||||||||||||||||||||||||||||||
| 41 | spaces are stripped only on the first line of each field. | ||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||
| 45 | package Dpkg::Control::HashCore 1.02; | ||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||
| 47 | 15 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||
| 49 | 15 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 50 | 15 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 51 | 15 | ▶ | use Dpkg::Control::FieldsCore; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 52 | 15 | ▶ | use Dpkg::Control::HashCore::Tie; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||
| 54 | # This module cannot use Dpkg::Control::Fields, because that one makes use | ||||||||||||||||||||||||||||||||||||||||
| 55 | # of Dpkg::Vendor which at the same time uses this module, which would turn | ||||||||||||||||||||||||||||||||||||||||
| 56 | # into a compilation error. We can use Dpkg::Control::FieldsCore instead. | ||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | 15 | ▶ | use parent qw(Dpkg::Interface::Storable); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | use overload | ||||||||||||||||||||||||||||||||||||||||
| 61 | 13955 | ▶ | '%{}' => sub { ${$_[0]}->{fields} }, | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 62 | 15 | ▶ | 'eq' => sub { "$_[0]" eq "$_[1]" }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||
| 66 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||
| 68 | =item $ctrl = Dpkg::Control::Hash->new(%opts) | ||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||
| 70 | Creates a new object with the indicated options. | ||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||
| 72 | Options: | ||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||
| 74 | =over 8 | ||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||
| 76 | =item B<name> | ||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||
| 78 | The user friendly name of the information stored in the object. It might | ||||||||||||||||||||||||||||||||||||||||
| 79 | be used in some error messages or warnings. A default name might be set | ||||||||||||||||||||||||||||||||||||||||
| 80 | depending on the type. | ||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | =item B<allow_pgp> | ||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||
| 84 | Configures the parser to accept OpenPGP signatures around the control | ||||||||||||||||||||||||||||||||||||||||
| 85 | information. Value can be 0 (default) or 1. | ||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||
| 87 | =item B<allow_duplicate> | ||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||
| 89 | Configures the parser to allow duplicate fields in the control | ||||||||||||||||||||||||||||||||||||||||
| 90 | information. | ||||||||||||||||||||||||||||||||||||||||
| 91 | The last value overrides any previous values. | ||||||||||||||||||||||||||||||||||||||||
| 92 | Value can be 0 (default) or 1. | ||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||
| 94 | =item B<keep_duplicate> | ||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||
| 96 | Configure the parser to keep values for duplicate fields found in the control | ||||||||||||||||||||||||||||||||||||||||
| 97 | information (when B<allow_duplicate> is enabled), as array references. | ||||||||||||||||||||||||||||||||||||||||
| 98 | Value can be 0 (default) or 1. | ||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||
| 100 | =item B<drop_empty> | ||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||
| 102 | Defines if empty fields are dropped during the output. Value can be 0 | ||||||||||||||||||||||||||||||||||||||||
| 103 | (default) or 1. | ||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||
| 105 | =item B<is_pgp_signed> | ||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||
| 107 | Set by the parser (starting in dpkg 1.17.0) if it finds an OpenPGP | ||||||||||||||||||||||||||||||||||||||||
| 108 | signature around the control information. Value can be 0 (default) | ||||||||||||||||||||||||||||||||||||||||
| 109 | or 1, and undef when the option is not supported by the code (in | ||||||||||||||||||||||||||||||||||||||||
| 110 | versions older than dpkg 1.17.0). | ||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||
| 112 | =back | ||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||
| 116 | 816 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 117 | 816 | my ($this, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 118 | 816 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||
| 120 | # Object is a scalar reference and not a hash ref to avoid | ||||||||||||||||||||||||||||||||||||||||
| 121 | # infinite recursion due to overloading hash-dereferencing. | ||||||||||||||||||||||||||||||||||||||||
| 122 | 816 | my $self = \{ | |||||||||||||||||||||||||||||||||||||||
| 123 | in_order => [], | ||||||||||||||||||||||||||||||||||||||||
| 124 | out_order => [], | ||||||||||||||||||||||||||||||||||||||||
| 125 | is_pgp_signed => 0, | ||||||||||||||||||||||||||||||||||||||||
| 126 | allow_pgp => 0, | ||||||||||||||||||||||||||||||||||||||||
| 127 | allow_duplicate => 0, | ||||||||||||||||||||||||||||||||||||||||
| 128 | keep_duplicate => 0, | ||||||||||||||||||||||||||||||||||||||||
| 129 | drop_empty => 0, | ||||||||||||||||||||||||||||||||||||||||
| 130 | }; | ||||||||||||||||||||||||||||||||||||||||
| 131 | 816 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||
| 133 | 816 | $$self->{fields} = Dpkg::Control::HashCore::Tie->new($self); | |||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||
| 135 | # Options set by the user override default values. | ||||||||||||||||||||||||||||||||||||||||
| 136 | 816 | $$self->{$_} = $opts{$_} foreach keys %opts; | |||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||
| 138 | 816 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||
| 141 | # There is naturally a circular reference between the tied hash and its | ||||||||||||||||||||||||||||||||||||||||
| 142 | # containing object. Happily, the extra layer of scalar reference can | ||||||||||||||||||||||||||||||||||||||||
| 143 | # be used to detect the destruction of the object and break the loop so | ||||||||||||||||||||||||||||||||||||||||
| 144 | # that everything gets garbage-collected. | ||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||
| 146 | 789 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 147 | 789 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 148 | 789 | delete $$self->{fields}; | |||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||
| 151 | =item $ctrl->set_options($option, %opts) | ||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||
| 153 | Changes the value of one or more options. | ||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub set_options { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_options: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $$self->{$_} = $opts{$_} foreach keys %opts; | |||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||
| 162 | =item $value = $ctrl->get_option($option) | ||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||
| 164 | Returns the value of the corresponding option. | ||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub get_option { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_option: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my ($self, $k) = @_; | |||||||||||||||||||||||||||||||||||||||
| 170 | 0 | return $$self->{$k}; | |||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||
| 173 | =item $ctrl->parse_error($file, $fmt, ...) | ||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||
| 175 | Prints an error message and dies on syntax parse errors. | ||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||
| 179 | 7 | ▶ | sub parse_error { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_error: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | my ($self, $file, $msg, @args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | ▶ | $msg = sprintf $msg, @args if @args; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 183 | 7 | error(g_('syntax error in %s at line %d: %s'), $file, $., $msg); | |||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||
| 186 | =item $bool = $ctrl->parse($fh, $description) | ||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||
| 188 | Parse a control file from the given filehandle. Exits in case of errors. | ||||||||||||||||||||||||||||||||||||||||
| 189 | $description is used to describe the filehandle, ideally it's a filename | ||||||||||||||||||||||||||||||||||||||||
| 190 | or a description of where the data comes from. It's used in error | ||||||||||||||||||||||||||||||||||||||||
| 191 | messages. When called multiple times, the parsed fields are accumulated. | ||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||
| 193 | Returns true if some fields have been parsed. | ||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||
| 197 | 62 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=33 SCAR=39.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 198 | 62 | my ($self, $fh, $desc) = @_; | |||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||
| 200 | 62 | my $paraborder = 1; | |||||||||||||||||||||||||||||||||||||||
| 201 | 62 | my $parabody = 0; | |||||||||||||||||||||||||||||||||||||||
| 202 | # Current field. | ||||||||||||||||||||||||||||||||||||||||
| 203 | 62 | my $cf; | |||||||||||||||||||||||||||||||||||||||
| 204 | 62 | my $expect_pgp_sig = 0; | |||||||||||||||||||||||||||||||||||||||
| 205 | 62 | local $_; | |||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||
| 207 | 62 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 208 | # In the common case there will be just a trailing \n character, | ||||||||||||||||||||||||||||||||||||||||
| 209 | # so using chomp here which is very fast will avoid the latter | ||||||||||||||||||||||||||||||||||||||||
| 210 | # s/// doing anything, which gives us a significant speed up. | ||||||||||||||||||||||||||||||||||||||||
| 211 | 166 | chomp; | |||||||||||||||||||||||||||||||||||||||
| 212 | 166 | my $armor = $_; | |||||||||||||||||||||||||||||||||||||||
| 213 | 166 | s/\s+$//; | |||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||
| 215 | 166 | ▶ | next if length == 0 and $paraborder; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $_ == 0 and $paraborder
MC/DC0%0/2
length $_ == 0 and $paraborder
length $_ == 0
$paraborder
Truth table66%2/3
A and B
A= length $_ == 0B= $paraborder
| |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||
| 217 | 166 | my $lead = substr $_, 0, 1; | |||||||||||||||||||||||||||||||||||||||
| 218 | 166 | ▶ | next if $lead eq '#'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 219 | 163 | $paraborder = 0; | |||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||
| 221 | 163 | my ($name, $value) = split /\s*:\s*/, $_, 2; | |||||||||||||||||||||||||||||||||||||||
| 222 | 163 | ▶ | if (defined $name and $name =~ m/^\S+?$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
defined $name and $name =~ /^\S+?$/u
MC/DC100%2/2
defined $name and $name =~ /^\S+?$/u
defined $name
$name =~ /^\S+?$/u
Truth table100%3/3
A and B
A= defined $nameB= $name =~ /^\S+?$/u
| |||||||||||||||||||||||||||||||||||||||||
| 223 | 116 | $parabody = 1; | |||||||||||||||||||||||||||||||||||||||
| 224 | 116 | ▶ | if ($lead eq '-') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $self->parse_error($desc, g_('field cannot start with a hyphen')); | |||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||
| 227 | 116 | ▶ | if (exists $self->{$name}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | unless ($$self->{allow_duplicate}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $self->parse_error($desc, g_('duplicate field %s found'), $name); | |||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ($$self->{keep_duplicate}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if (ref $self->{$name} ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 233 | # Switch value into an array. | ||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $self->{$name} = [ $self->{$name}, $value ]; | |||||||||||||||||||||||||||||||||||||||
| 235 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 236 | # Append the value. | ||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | push @{$self->{$name}}, $value; | |||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 240 | # Overwrite with last value. | ||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $self->{$name} = $value; | |||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||
| 243 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 244 | 116 | $self->{$name} = $value; | |||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||
| 246 | 116 | $cf = $name; | |||||||||||||||||||||||||||||||||||||||
| 247 | } elsif (m/^\s(\s*\S.*)$/) { | ||||||||||||||||||||||||||||||||||||||||
| 248 | 16 | my $line = $1; | |||||||||||||||||||||||||||||||||||||||
| 249 | 16 | ▶ | unless (defined($cf)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $self->parse_error($desc, g_('continued value line not in field')); | |||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||
| 252 | 16 | ▶ | if ($line =~ /^\.+$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | $line = substr $line, 1; | |||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||
| 255 | 16 | $self->{$cf} .= "\n$line"; | |||||||||||||||||||||||||||||||||||||||
| 256 | ▶ | } elsif (length == 0 || | |||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
length $_ == 0 or $expect_pgp_sig and $armor =~ /^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/u
$expect_pgp_sig and $armor =~ /^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/u
MC/DC33%1/3
length $_ == 0 or $expect_pgp_sig and $armor =~ /^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/u
length $_ == 0
$expect_pgp_sig
$armor =~ /^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/u
Truth table50%2/4
A or B and C
A= length $_ == 0B= $expect_pgp_sigC= $armor =~ /^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/u
| |||||||||||||||||||||||||||||||||||||||||
| 257 | ($expect_pgp_sig && $armor =~ m/^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/)) { | ||||||||||||||||||||||||||||||||||||||||
| 258 | 22 | ▶ | if ($expect_pgp_sig) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 259 | # Skip empty lines. | ||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | $_ = <$fh> while defined && m/^\s*$/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_ and /^\s*$/u
MC/DC50%1/2
defined $_ and /^\s*$/u
defined $_
/^\s*$/u
Truth table66%2/3
A and B
A= defined $_B= /^\s*$/u
| |||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | ▶ | unless (length) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $self->parse_error($desc, g_('expected OpenPGP signature, ' . | |||||||||||||||||||||||||||||||||||||||
| 263 | 'found end of file after blank line')); | ||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | chomp; | |||||||||||||||||||||||||||||||||||||||
| 266 | 3 | ▶ | unless (m/^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $self->parse_error($desc, g_('expected OpenPGP signature, ' . | |||||||||||||||||||||||||||||||||||||||
| 268 | "found something else '%s'"), $_); | ||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||
| 270 | # Skip OpenPGP signature. | ||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 272 | 16 | chomp; | |||||||||||||||||||||||||||||||||||||||
| 273 | 16 | ▶ | last if m/^-----END PGP SIGNATURE-----[\r\t ]*$/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | ▶ | unless (defined) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $self->parse_error($desc, g_('unfinished OpenPGP signature')); | |||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||
| 278 | # This does not mean the signature is correct, that needs to | ||||||||||||||||||||||||||||||||||||||||
| 279 | # be verified by an OpenPGP backend. | ||||||||||||||||||||||||||||||||||||||||
| 280 | 3 | $$self->{is_pgp_signed} = 1; | |||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||
| 282 | # Finished parsing one stanza. | ||||||||||||||||||||||||||||||||||||||||
| 283 | 22 | last; | |||||||||||||||||||||||||||||||||||||||
| 284 | } elsif ($armor =~ m/^-----BEGIN PGP SIGNED MESSAGE-----[\r\t ]*$/) { | ||||||||||||||||||||||||||||||||||||||||
| 285 | 5 | $expect_pgp_sig = 1; | |||||||||||||||||||||||||||||||||||||||
| 286 | 5 | ▶ | if ($$self->{allow_pgp} and not $parabody) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$self->{"allow_pgp"} and not $parabody
MC/DC50%1/2
$$self->{"allow_pgp"} and not $parabody
$$self->{"allow_pgp"}
not $parabody
Truth table66%2/3
A and not(B)
A= $$self->{"allow_pgp"}B= not $parabody
| |||||||||||||||||||||||||||||||||||||||||
| 287 | # Skip OpenPGP headers. | ||||||||||||||||||||||||||||||||||||||||
| 288 | 4 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 289 | 8 | ▶ | last if m/^\s*$/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||
| 291 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | $self->parse_error($desc, g_('OpenPGP signature not allowed here')); | |||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||
| 294 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | $self->parse_error($desc, | |||||||||||||||||||||||||||||||||||||||
| 296 | g_('line with unknown format (not field-colon-value)')); | ||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||
| 300 | 57 | ▶ | if ($expect_pgp_sig and not $$self->{is_pgp_signed}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$expect_pgp_sig and not $$self->{"is_pgp_signed"}
MC/DC100%2/2
$expect_pgp_sig and not $$self->{"is_pgp_signed"}
$expect_pgp_sig
not $$self->{"is_pgp_signed"}
Truth table100%3/3
A and not(B)
A= $expect_pgp_sigB= not $$self->{"is_pgp_signed"}
| |||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | $self->parse_error($desc, g_('unfinished OpenPGP signature')); | |||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||
| 304 | 56 | return defined($cf); | |||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||
| 307 | =item $bool = $ctrl->load($file) | ||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||
| 309 | Parse the content of $file. Exits in case of errors. Returns true if some | ||||||||||||||||||||||||||||||||||||||||
| 310 | fields have been parsed. | ||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||
| 312 | =item $field = $ctrl->find_custom_field($name) | ||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||
| 314 | Scan the fields and look for a user specific field whose name matches the | ||||||||||||||||||||||||||||||||||||||||
| 315 | following regex: /X[SBC]*-$name/i. Return the name of the field found or | ||||||||||||||||||||||||||||||||||||||||
| 316 | undef if nothing has been found. | ||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||
| 318 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | sub find_custom_field { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_custom_field: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||
| 322 | 0 | foreach my $key (keys %$self) { | |||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | return $key if $key =~ /^X[SBC]*-\Q$name\E$/i; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||
| 328 | =item $value = $ctrl->get_custom_field($name) | ||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||
| 330 | Identify a user field and retrieve its value. | ||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||
| 332 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub get_custom_field { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_custom_field: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $key = $self->find_custom_field($name); | |||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | return $self->{$key} if defined $key; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||
| 341 | =item $string = "$ctrl" | ||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||
| 343 | =item $string = $ctrl->output() | ||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||
| 345 | Get a string representation of the control information. The fields | ||||||||||||||||||||||||||||||||||||||||
| 346 | are sorted in the order in which they have been read or set except | ||||||||||||||||||||||||||||||||||||||||
| 347 | if the order has been overridden with set_output_order(). | ||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||
| 349 | =item $string = $ctrl->output($fh) | ||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||
| 351 | Print the string representation of the control information to a | ||||||||||||||||||||||||||||||||||||||||
| 352 | filehandle. | ||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||
| 354 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||
| 356 | 28 | ▶ | sub output { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
output: called CC=18 SCAR=29.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 357 | 28 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||
| 358 | 28 | my $str = ''; | |||||||||||||||||||||||||||||||||||||||
| 359 | 28 | my @keys; | |||||||||||||||||||||||||||||||||||||||
| 360 | 28 | ▶ | if (@{$$self->{out_order}}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 361 | 28 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||
| 362 | 28 | my $imp = {}; | |||||||||||||||||||||||||||||||||||||||
| 363 | 28 | $imp->{$_} = $i++ foreach @{$$self->{out_order}}; | |||||||||||||||||||||||||||||||||||||||
| 364 | @keys = sort { | ||||||||||||||||||||||||||||||||||||||||
| 365 | 28 | ▶ | if (defined $imp->{$a} && defined $imp->{$b}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
defined $imp->{$a} and defined $imp->{$b}
MC/DC100%2/2
defined $imp->{$a} and defined $imp->{$b}
defined $imp->{$a}
defined $imp->{$b}
Truth table100%3/3
A and B
A= defined $imp->{$a}B= defined $imp->{$b}
| |||||||||||||||||||||||||||||||||||||||||
| 366 | 189 | $imp->{$a} <=> $imp->{$b}; | |||||||||||||||||||||||||||||||||||||||
| 367 | } elsif (defined($imp->{$a})) { | ||||||||||||||||||||||||||||||||||||||||
| 368 | 25 | -1; | |||||||||||||||||||||||||||||||||||||||
| 369 | } elsif (defined($imp->{$b})) { | ||||||||||||||||||||||||||||||||||||||||
| 370 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||
| 371 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 372 | 22 | $a cmp $b; | |||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||
| 374 | } keys %$self; | ||||||||||||||||||||||||||||||||||||||||
| 375 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | @keys = @{$$self->{in_order}}; | |||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||
| 379 | 28 | foreach my $key (@keys) { | |||||||||||||||||||||||||||||||||||||||
| 380 | 145 | ▶ | if (exists $self->{$key}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 381 | 145 | my $value = $self->{$key}; | |||||||||||||||||||||||||||||||||||||||
| 382 | # Skip whitespace-only fields. | ||||||||||||||||||||||||||||||||||||||||
| 383 | 145 | ▶ | next if $$self->{drop_empty} and $value !~ m/\S/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$$self->{"drop_empty"} and not $value =~ /\S/u
MC/DC100%2/2
$$self->{"drop_empty"} and not $value =~ /\S/u
$$self->{"drop_empty"}
not $value =~ /\S/u
Truth table100%3/3
A and not(B)
A= $$self->{"drop_empty"}B= not $value =~ /\S/u
| |||||||||||||||||||||||||||||||||||||||||
| 384 | # Escape data to follow control file syntax. | ||||||||||||||||||||||||||||||||||||||||
| 385 | 144 | my ($first_line, @lines) = split /\n/, $value; | |||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||
| 387 | 144 | my $kv = "$key:"; | |||||||||||||||||||||||||||||||||||||||
| 388 | 144 | ▶ | $kv .= ' ' . $first_line if length $first_line; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 389 | 144 | $kv .= "\n"; | |||||||||||||||||||||||||||||||||||||||
| 390 | 144 | foreach (@lines) { | |||||||||||||||||||||||||||||||||||||||
| 391 | 110 | s/\s+$//; | |||||||||||||||||||||||||||||||||||||||
| 392 | 110 | ▶ | if (length == 0 or /^\.+$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $_ == 0 or /^\.+$/u
MC/DC100%2/2
length $_ == 0 or /^\.+$/u
length $_ == 0
/^\.+$/u
Truth table100%3/3
A or B
A= length $_ == 0B= /^\.+$/u
| |||||||||||||||||||||||||||||||||||||||||
| 393 | 37 | $kv .= " .$_\n"; | |||||||||||||||||||||||||||||||||||||||
| 394 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 395 | 73 | $kv .= " $_\n"; | |||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||
| 398 | # Print it out. | ||||||||||||||||||||||||||||||||||||||||
| 399 | 144 | ▶ | if ($fh) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 400 | 19 | ▶ | print { $fh } $kv | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 401 | or syserr(g_('cannot write control data')); | ||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||
| 403 | 144 | ▶ | $str .= $kv if defined wantarray; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||
| 406 | 28 | return $str; | |||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||
| 409 | =item $ctrl->save($filename) | ||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||
| 411 | Write the string representation of the control information to a file. | ||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||
| 413 | =item $ctrl->set_output_order(@fields) | ||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||
| 415 | Define the order in which fields will be displayed in the output() method. | ||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||
| 417 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||
| 419 | 800 | ▶ | sub set_output_order { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_output_order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 420 | 800 | my ($self, @fields) = @_; | |||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||
| 422 | 800 | $$self->{out_order} = [ @fields ]; | |||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||
| 425 | =item $ctrl->apply_substvars($substvars) | ||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||
| 427 | Update all fields by replacing the variables references with | ||||||||||||||||||||||||||||||||||||||||
| 428 | the corresponding value stored in the L<Dpkg::Substvars> object. | ||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||
| 430 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||
| 432 | 2 | ▶ | sub apply_substvars { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_substvars: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 433 | 2 | my ($self, $substvars, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||
| 435 | # Add substvars to refer to other fields. | ||||||||||||||||||||||||||||||||||||||||
| 436 | 2 | $substvars->set_field_substvars($self, 'F'); | |||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||
| 438 | 2 | my %implicit_field; | |||||||||||||||||||||||||||||||||||||||
| 439 | 2 | foreach my $sv ($substvars->get_implicit_substvars()) { | |||||||||||||||||||||||||||||||||||||||
| 440 | 12 | my ($n, $f) = split /:/, $sv, 2; | |||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||
| 442 | 12 | push @{$implicit_field{$f}}, $n; | |||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||
| 445 | 2 | foreach my $f (keys %$self, keys %implicit_field) { | |||||||||||||||||||||||||||||||||||||||
| 446 | 9 | my $sep = field_get_sep_type($f); | |||||||||||||||||||||||||||||||||||||||
| 447 | 9 | my $v; | |||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||
| 449 | 9 | ▶ | if (exists $self->{$f}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 450 | 4 | $v = $substvars->substvars($self->{$f}, %opts); | |||||||||||||||||||||||||||||||||||||||
| 451 | } elsif (exists $implicit_field{$f}) { | ||||||||||||||||||||||||||||||||||||||||
| 452 | 5 | my $sep_str; | |||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||
| 454 | 5 | ▶ | if ($sep & FIELD_SEP_COMMA) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | $sep_str = ', '; | |||||||||||||||||||||||||||||||||||||||
| 456 | } elsif ($sep & FIELD_SEP_SPACE) { | ||||||||||||||||||||||||||||||||||||||||
| 457 | 2 | $sep_str = ' '; | |||||||||||||||||||||||||||||||||||||||
| 458 | } elsif ($sep & FIELD_SEP_LINE) { | ||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $sep_str = "\n "; | |||||||||||||||||||||||||||||||||||||||
| 460 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 461 | # For unknown separators, fallback to a space. | ||||||||||||||||||||||||||||||||||||||||
| 462 | 2 | $sep_str = ' '; | |||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||
| 465 | $v = join $sep_str, map { | ||||||||||||||||||||||||||||||||||||||||
| 466 | 10 | $substvars->get("$_:$f") | |||||||||||||||||||||||||||||||||||||||
| 467 | 5 | } sort @{$implicit_field{$f}}; | |||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||
| 470 | 9 | ▶ | if (not exists $self->{$f} or $v ne $self->{$f}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not exists $self->{$f} or $v ne $self->{$f}
MC/DC50%1/2
not exists $self->{$f} or $v ne $self->{$f}
not exists $self->{$f}
$v ne $self->{$f}
Truth table66%2/3
not(A) or B
A= not exists $self->{$f}B= $v ne $self->{$f}
| |||||||||||||||||||||||||||||||||||||||||
| 471 | # If we replaced stuff, ensure we are not breaking a dependency | ||||||||||||||||||||||||||||||||||||||||
| 472 | # field by introducing empty lines, or multiple commas. | ||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||
| 474 | 5 | ▶ | if ($sep & (FIELD_SEP_COMMA | FIELD_SEP_LINE)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 475 | # Drop empty/whitespace-only lines. | ||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | $v =~ s/\n[ \t]*(\n|$)/$1/; | |||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||
| 479 | 5 | ▶ | if ($sep & FIELD_SEP_COMMA) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | $v =~ s/,[\s,]*,/,/g; | |||||||||||||||||||||||||||||||||||||||
| 481 | 1 | $v =~ s/^\s*,\s*//; | |||||||||||||||||||||||||||||||||||||||
| 482 | 1 | $v =~ s/\s*,\s*$//; | |||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||
| 485 | # Replace ${} with $, which is otherwise an invalid substitution, but | ||||||||||||||||||||||||||||||||||||||||
| 486 | # this then makes it possible to use ${} as an escape sequence such | ||||||||||||||||||||||||||||||||||||||||
| 487 | # as ${}{VARIABLE}. | ||||||||||||||||||||||||||||||||||||||||
| 488 | 9 | $v =~ s/\$\{\}/\$/g; | |||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||
| 490 | 9 | $self->{$f} = $v; | |||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||
| 494 | =back | ||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||
| 496 | =head1 CHANGES | ||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||
| 498 | =head2 Version 1.02 (dpkg 1.21.0) | ||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||
| 500 | New option: "keep_duplicate" in new(). | ||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||
| 502 | =head2 Version 1.01 (dpkg 1.17.2) | ||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||
| 504 | New method: $c->parse_error(). | ||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||
| 506 | =head2 Version 1.00 (dpkg 1.17.0) | ||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||
| 508 | Mark the module as public. | ||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||
| 510 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||
| 512 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||