| 1 | # Copyright © 2006-2024 Guillem Jover <guillem@debian.org> | ||||||||||||||||||||||||||||
| 2 | # Copyright © 2007-2010 Raphaël Hertzog <hertzog@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::Substvars - handle variable substitution in strings | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | It provides a class which is able to substitute variables in strings. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | package Dpkg::Substvars 2.04; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use Dpkg (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use Dpkg::Arch qw(get_host_arch); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use Dpkg::Vendor qw(get_current_vendor); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use Dpkg::Version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use parent qw(Dpkg::Interface::Storable); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | my $maxsubsts = 50; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 1 | SUBSTVAR_ATTR_USED => 1, | |||||||||||||||||||||||||||
| 46 | SUBSTVAR_ATTR_AUTO => 2, | ||||||||||||||||||||||||||||
| 47 | SUBSTVAR_ATTR_AGED => 4, | ||||||||||||||||||||||||||||
| 48 | SUBSTVAR_ATTR_OPT => 8, | ||||||||||||||||||||||||||||
| 49 | SUBSTVAR_ATTR_DEEP => 16, | ||||||||||||||||||||||||||||
| 50 | SUBSTVAR_ATTR_REQ => 32, | ||||||||||||||||||||||||||||
| 51 | SUBSTVAR_ATTR_IMPL => 64, | ||||||||||||||||||||||||||||
| 52 | 1 | }; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 METHODS | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =over 8 | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =item $sv = Dpkg::Substvars->new($file) | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | Create a new object that can do substitutions. By default it contains | ||||||||||||||||||||||||||||
| 61 | generic substitutions like ${Newline}, ${Space}, ${Tab}, ${dpkg:Version} | ||||||||||||||||||||||||||||
| 62 | and ${dpkg:Upstream-Version}. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Additional substitutions will be read from the $file passed as parameter. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | It keeps track of which substitutions were actually used (only counting | ||||||||||||||||||||||||||||
| 67 | substvars(), not get()), and warns about unused substvars when asked to. The | ||||||||||||||||||||||||||||
| 68 | substitutions that are always present are not included in these warnings. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 6 | my ($this, $arg) = @_; | |||||||||||||||||||||||||||
| 74 | 6 | ▶ | 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
| |||||||||||||||||||||||||||||
| 75 | 6 | my $self = { | |||||||||||||||||||||||||||
| 76 | vars => { | ||||||||||||||||||||||||||||
| 77 | 'Newline' => "\n", | ||||||||||||||||||||||||||||
| 78 | 'Space' => ' ', | ||||||||||||||||||||||||||||
| 79 | 'Tab' => "\t", | ||||||||||||||||||||||||||||
| 80 | 'dpkg:Version' => $Dpkg::PROGVERSION, | ||||||||||||||||||||||||||||
| 81 | 'dpkg:Upstream-Version' => $Dpkg::PROGVERSION, | ||||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||
| 83 | attr => {}, | ||||||||||||||||||||||||||||
| 84 | msg_prefix => '', | ||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||
| 86 | 6 | $self->{vars}{'dpkg:Upstream-Version'} =~ s/-[^-]+$//; | |||||||||||||||||||||||||||
| 87 | 6 | bless $self, $class; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 6 | my $attr = SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_AUTO; | |||||||||||||||||||||||||||
| 90 | 6 | $self->{attr}{$_} = $attr foreach keys %{$self->{vars}}; | |||||||||||||||||||||||||||
| 91 | 6 | ▶ | if ($arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 5 | ▶ | $self->load($arg) if -e $arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 6 | return $self; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =item $sv->set($key, $value) | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Add/replace a substitution. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =cut | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 77 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 77 | my ($self, $key, $value, $attr) = @_; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 77 | ▶ | $attr //= 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$attr //= 0
MC/DC100%1/1
$attr //= 0
$attr
Truth table100%2/2
A
A= $attr
| |||||||||||||||||||||||||||||
| 107 | 77 | ▶ | $attr |= SUBSTVAR_ATTR_DEEP if length $value && $value =~ m{\$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $value and $value =~ /\$/u
MC/DC50%1/2
length $value and $value =~ /\$/u
length $value
$value =~ /\$/u
Truth table66%2/3
A and B
A= length $valueB= $value =~ /\$/u
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 77 | $self->{vars}{$key} = $value; | |||||||||||||||||||||||||||
| 110 | 77 | $self->{attr}{$key} = $attr; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =item $sv->set_as_used($key, $value) | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | Add/replace a substitution and mark it as used (no warnings will be produced | ||||||||||||||||||||||||||||
| 116 | even if unused). | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | ▶ | sub set_as_used { | ||||||||||||||||||||||||||
|
Subroutine
set_as_used: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 1 | my ($self, $key, $value) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 1 | $self->set($key, $value, SUBSTVAR_ATTR_USED); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =item $sv->set_as_auto($key, $value) | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Add/replace a substitution and mark it as used and automatic (no warnings | ||||||||||||||||||||||||||||
| 129 | will be produced even if unused), and will not be emitted into the substvars | ||||||||||||||||||||||||||||
| 130 | file. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 7 | ▶ | sub set_as_auto { | ||||||||||||||||||||||||||
|
Subroutine
set_as_auto: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 7 | my ($self, $key, $value) = @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 7 | $self->set($key, $value, SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_AUTO); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =item $sv->set_as_optional($key, $value) | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | Add/replace a substitution and mark it as used and optional (no warnings | ||||||||||||||||||||||||||||
| 143 | will be produced even if unused). | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | ▶ | sub set_as_optional { | ||||||||||||||||||||||||||
|
Subroutine
set_as_optional: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 1 | my ($self, $key, $value) = @_; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 1 | $self->set($key, $value, SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_OPT); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =item $sv->set_as_required($key, $value) | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Add/replace a substitution and mark it as required (an error | ||||||||||||||||||||||||||||
| 156 | will be produced if it is not used). | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | ▶ | sub set_as_required { | ||||||||||||||||||||||||||
|
Subroutine
set_as_required: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 1 | my ($self, $key, $value) = @_; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 1 | $self->set($key, $value, SUBSTVAR_ATTR_REQ); | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =item $sv->set_as_implicit($key, $value) | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | Add/replace a substitution and mark it as implicit, where a field will be | ||||||||||||||||||||||||||||
| 169 | automatically instantiated if not already present. | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 6 | ▶ | sub set_as_implicit($self, $key, $value) | ||||||||||||||||||||||||||
|
Subroutine
set_as_implicit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||
| 175 | 6 | $self->set($key, $value, SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_IMPL); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =item $value = $sv->get($key) | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | Get the value of a given substitution. | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 50 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 185 | 50 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 186 | 50 | return $self->{vars}{$key}; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =item $value = $sv->delete($key) | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | Remove a given substitution. | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 23 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 196 | 23 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 197 | 23 | delete $self->{attr}{$key}; | |||||||||||||||||||||||||||
| 198 | 23 | return delete $self->{vars}{$key}; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =item $sv->mark_as_used($key) | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | Prevents warnings about a unused substitution, for example if it is provided by | ||||||||||||||||||||||||||||
| 204 | default. | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =cut | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 771 | ▶ | sub mark_as_used { | ||||||||||||||||||||||||||
|
Subroutine
mark_as_used: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 209 | 771 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 210 | 771 | $self->{attr}{$key} |= SUBSTVAR_ATTR_USED; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =item $count = $sv->parse($fh, $desc) | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | Add new substitutions read from the filehandle. $desc is used to identify | ||||||||||||||||||||||||||||
| 216 | the filehandle in error messages. | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | Returns the number of substitutions that have been parsed with success. | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =cut | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 6 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 223 | 6 | my ($self, $fh, $varlistfile) = @_; | |||||||||||||||||||||||||||
| 224 | 6 | my $count = 0; | |||||||||||||||||||||||||||
| 225 | 6 | local $_; | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 6 | binmode($fh); | |||||||||||||||||||||||||||
| 228 | 6 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 38 | ▶ | next if m/^\s*\#/ || ! m/\S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^\s*\#/u or not /\S/u
MC/DC100%2/2
/^\s*\#/u or not /\S/u
/^\s*\#/u
not /\S/u
Truth table100%3/3
A or not(B)
A= /^\s*\#/uB= not /\S/u
| |||||||||||||||||||||||||||||
| 230 | 32 | s/\s*\n$//; | |||||||||||||||||||||||||||
| 231 | 32 | ▶ | if (! m/^(\w[-:0-9A-Za-z]*)([?!\$])?\=(.*)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 0 | error(g_('bad line in substvars file %s at line %d'), | |||||||||||||||||||||||||||
| 233 | $varlistfile, $.); | ||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | 32 | ▶ | if (defined $2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 8 | ▶ | $self->set_as_optional($1, $3) if $2 eq '?'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 8 | ▶ | $self->set_as_required($1, $3) if $2 eq '!'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 8 | ▶ | $self->set_as_implicit($1, $3) if $2 eq '$'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||
| 240 | 24 | $self->set($1, $3); | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | 32 | $count++; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 6 | return $count | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | =item $sv->load($file) | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | Add new substitutions read from $file. | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =item $sv->set_version_substvars($sourceversion, $binaryversion) | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | Defines ${binary:Version}, ${source:Version} and | ||||||||||||||||||||||||||||
| 255 | ${source:Upstream-Version} based on the given version strings. | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | These will never be warned about when unused. | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =cut | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 3 | ▶ | sub set_version_substvars { | ||||||||||||||||||||||||||
|
Subroutine
set_version_substvars: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 262 | 3 | my ($self, $sourceversion, $binaryversion) = @_; | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | # Handle old function signature taking only one argument. | ||||||||||||||||||||||||||||
| 265 | 3 | ▶ | $binaryversion //= $sourceversion; | ||||||||||||||||||||||||||
|
Condition66%2/3
$binaryversion //= $sourceversion
MC/DC0%0/2
$binaryversion //= $sourceversion
$binaryversion
$sourceversion
Truth table66%2/3
A //= B
A= $binaryversionB= $sourceversion
| |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | # For backwards compatibility on binNMUs that do not use the Binary-Only | ||||||||||||||||||||||||||||
| 268 | # field on the changelog, always fix up the source version. | ||||||||||||||||||||||||||||
| 269 | 3 | $sourceversion =~ s/\+b[0-9]+$//; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 3 | my $vs = Dpkg::Version->new($sourceversion, check => 1); | |||||||||||||||||||||||||||
| 272 | 3 | ▶ | if (not defined $vs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | error(g_('invalid source version %s'), $sourceversion); | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | 3 | my $upstreamversion = $vs->as_string(omit_revision => 1); | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 3 | my $attr = SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_AUTO; | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 3 | $self->set('binary:Version', $binaryversion, $attr); | |||||||||||||||||||||||||||
| 280 | 3 | $self->set('source:Version', $sourceversion, $attr); | |||||||||||||||||||||||||||
| 281 | 3 | $self->set('source:Upstream-Version', $upstreamversion, $attr); | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | # XXX: Source-Version is now obsolete, remove in 1.19.x. | ||||||||||||||||||||||||||||
| 284 | 3 | $self->set('Source-Version', $binaryversion, $attr | SUBSTVAR_ATTR_AGED); | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =item $sv->set_arch_substvars() | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | Defines architecture variables: ${Arch}. | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | This will never be warned about when unused. | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =cut | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 1 | ▶ | sub set_arch_substvars { | ||||||||||||||||||||||||||
|
Subroutine
set_arch_substvars: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 296 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 1 | my $attr = SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_AUTO; | |||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 1 | $self->set('Arch', get_host_arch(), $attr); | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =item $sv->set_vendor_substvars() | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | Defines vendor variables: ${vendor:Name} and ${vendor:Id}. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | These will never be warned about when unused. | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =cut | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 1 | ▶ | sub set_vendor_substvars { | ||||||||||||||||||||||||||
|
Subroutine
set_vendor_substvars: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 312 | 1 | my ($self, $desc) = @_; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 1 | my $attr = SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_AUTO; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 1 | my $vendor = get_current_vendor(); | |||||||||||||||||||||||||||
| 317 | 1 | $self->set('vendor:Name', $vendor, $attr); | |||||||||||||||||||||||||||
| 318 | 1 | $self->set('vendor:Id', lc $vendor, $attr); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | =item $sv->set_desc_substvars() | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | Defines source description variables: ${source:Synopsis} and | ||||||||||||||||||||||||||||
| 324 | ${source:Extended-Description}. | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | These will never be warned about when unused. | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | =cut | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 1 | ▶ | sub set_desc_substvars { | ||||||||||||||||||||||||||
|
Subroutine
set_desc_substvars: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 331 | 1 | my ($self, $desc) = @_; | |||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 1 | my ($synopsis, $extended) = split /\n/, $desc, 2; | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 1 | my $attr = SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_AUTO; | |||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 1 | $self->set('source:Synopsis', $synopsis, $attr); | |||||||||||||||||||||||||||
| 338 | 1 | $self->set('source:Extended-Description', $extended, $attr); | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | =item $sv->set_field_substvars($ctrl, $prefix) | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | Defines field variables from a L<Dpkg::Control> object, with each variable | ||||||||||||||||||||||||||||
| 344 | having the form "${$prefix:$field}". | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | They will never be warned about when unused. | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | =cut | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 3 | ▶ | sub set_field_substvars { | ||||||||||||||||||||||||||
|
Subroutine
set_field_substvars: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 351 | 3 | my ($self, $ctrl, $prefix) = @_; | |||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 3 | foreach my $field (keys %{$ctrl}) { | |||||||||||||||||||||||||||
| 354 | 6 | $self->set_as_auto("$prefix:$field", $ctrl->{$field}); | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | =item @substvars = $sv->get_implicit_substvars() | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | Returns a list of implicit substitution variables to be used by the calling | ||||||||||||||||||||||||||||
| 361 | program, by appending them to specific text. | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | =cut | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 2 | ▶ | sub get_implicit_substvars($self) | ||||||||||||||||||||||||||
|
Subroutine
get_implicit_substvars: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 366 | { | ||||||||||||||||||||||||||||
| 367 | my @implicit = sort grep { | ||||||||||||||||||||||||||||
| 368 | 25 | $self->{attr}{$_} & SUBSTVAR_ATTR_IMPL | |||||||||||||||||||||||||||
| 369 | 2 | } keys %{$self->{vars}}; | |||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 2 | return @implicit; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | =item $newstring = $sv->substvars($string) | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | Substitutes variables in $string and return the result in $newstring. | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | =cut | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 15 | ▶ | sub substvars { | ||||||||||||||||||||||||||
|
Subroutine
substvars: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||
| 381 | 15 | my ($self, $v, %opts) = @_; | |||||||||||||||||||||||||||
| 382 | 15 | my %seen; | |||||||||||||||||||||||||||
| 383 | my $lhs; | ||||||||||||||||||||||||||||
| 384 | 15 | my $vn; | |||||||||||||||||||||||||||
| 385 | 15 | my $rhs = ''; | |||||||||||||||||||||||||||
| 386 | 15 | ▶ | $opts{msg_prefix} //= $self->{msg_prefix}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$opts{"msg_prefix"} //= $self->{"msg_prefix"}
MC/DC0%0/2
$opts{"msg_prefix"} //= $self->{"msg_prefix"}
$opts{"msg_prefix"}
$self->{"msg_prefix"}
Truth table33%1/3
A //= B
A= $opts{"msg_prefix"}B= $self->{"msg_prefix"}
| |||||||||||||||||||||||||||||
| 387 | 15 | ▶ | $opts{no_warn} //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"no_warn"} //= 0
MC/DC0%0/1
$opts{"no_warn"} //= 0
$opts{"no_warn"}
Truth table50%1/2
A
A= $opts{"no_warn"}
| |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 15 | ▶ | while ($v =~ m/^(.*?)\$\{([-:0-9a-z]+)\}(.*)$/si) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | 771 | $lhs = $1; | |||||||||||||||||||||||||||
| 391 | 771 | $vn = $2; | |||||||||||||||||||||||||||
| 392 | 771 | $rhs = $3; | |||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 771 | ▶ | if (defined($self->{vars}{$vn})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 395 | 770 | $v = $lhs . $self->{vars}{$vn} . $rhs; | |||||||||||||||||||||||||||
| 396 | 770 | $self->mark_as_used($vn); | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 770 | ▶ | if ($self->{attr}{$vn} & SUBSTVAR_ATTR_DEEP) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 212 | $seen{$vn}++; | |||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | 770 | ▶ | if (exists $seen{$vn} && $seen{$vn} >= $maxsubsts) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $seen{$vn} and $seen{$vn} >= $maxsubsts
MC/DC100%2/2
exists $seen{$vn} and $seen{$vn} >= $maxsubsts
exists $seen{$vn}
$seen{$vn} >= $maxsubsts
Truth table100%3/3
A and B
A= exists $seen{$vn}B= $seen{$vn} >= $maxsubsts
| |||||||||||||||||||||||||||||
| 402 | error($opts{msg_prefix} . | ||||||||||||||||||||||||||||
| 403 | 2 | g_("too many \${%s} substitutions (recursive?) in '%s'"), | |||||||||||||||||||||||||||
| 404 | $vn, $v); | ||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 768 | ▶ | if ($self->{attr}{$vn} & SUBSTVAR_ATTR_AGED) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | error($opts{msg_prefix} . | ||||||||||||||||||||||||||||
| 409 | 0 | g_('obsolete substitution variable ${%s}'), $vn); | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | } else { | ||||||||||||||||||||||||||||
| 412 | warning($opts{msg_prefix} . | ||||||||||||||||||||||||||||
| 413 | g_('substitution variable ${%s} used, but is not defined'), | ||||||||||||||||||||||||||||
| 414 | 1 | ▶ | $vn) unless $opts{no_warn}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 1 | $v = $lhs . $rhs; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | 13 | return $v; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | =item $sv->warn_about_unused() | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | Issues warning about any variables that were set, but not used. | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | =cut | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 3 | ▶ | sub warn_about_unused { | ||||||||||||||||||||||||||
|
Subroutine
warn_about_unused: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||
| 428 | 3 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||
| 429 | 3 | ▶ | $opts{msg_prefix} //= $self->{msg_prefix}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$opts{"msg_prefix"} //= $self->{"msg_prefix"}
MC/DC0%0/2
$opts{"msg_prefix"} //= $self->{"msg_prefix"}
$opts{"msg_prefix"}
$self->{"msg_prefix"}
Truth table33%1/3
A //= B
A= $opts{"msg_prefix"}B= $self->{"msg_prefix"}
| |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 3 | foreach my $vn (sort keys %{$self->{vars}}) { | |||||||||||||||||||||||||||
| 432 | 87 | ▶ | next if $self->{attr}{$vn} & SUBSTVAR_ATTR_USED; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | # Empty substitutions variables are ignored on the basis that they | ||||||||||||||||||||||||||||
| 434 | # are not required in the current situation. | ||||||||||||||||||||||||||||
| 435 | # Example: debhelper's misc:Depends in many cases. | ||||||||||||||||||||||||||||
| 436 | 2 | ▶ | next if $self->{vars}{$vn} eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 2 | ▶ | if ($self->{attr}{$vn} & SUBSTVAR_ATTR_REQ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | error($opts{msg_prefix} . | ||||||||||||||||||||||||||||
| 440 | 1 | g_('required substitution variable ${%s} not used'), | |||||||||||||||||||||||||||
| 441 | $vn); | ||||||||||||||||||||||||||||
| 442 | } else { | ||||||||||||||||||||||||||||
| 443 | warning($opts{msg_prefix} . | ||||||||||||||||||||||||||||
| 444 | 1 | g_('substitution variable ${%s} unused, but is defined'), | |||||||||||||||||||||||||||
| 445 | $vn); | ||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | =item $sv->set_msg_prefix($prefix) | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | Define a prefix displayed before all warnings/error messages output | ||||||||||||||||||||||||||||
| 453 | by the module. | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | =cut | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 1 | ▶ | sub set_msg_prefix { | ||||||||||||||||||||||||||
|
Subroutine
set_msg_prefix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 458 | 1 | my ($self, $prefix) = @_; | |||||||||||||||||||||||||||
| 459 | 1 | $self->{msg_prefix} = $prefix; | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | =item $sv->filter(%opts) | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | Filter the substitution variables. | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | Options: | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | =over | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | =item B<remove> | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | A function returning a boolean, | ||||||||||||||||||||||||||||
| 473 | used to decide whether to remove a substitution variable, | ||||||||||||||||||||||||||||
| 474 | executed as $opts{remove}->($var). | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | =item B<keep> | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | A function returning a boolean, | ||||||||||||||||||||||||||||
| 479 | used to decide whether to keep the substitution variable, | ||||||||||||||||||||||||||||
| 480 | executed as $opts{keep}->($var). | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | =back | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | =cut | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 3 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 487 | 3 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 3 | ▶ | my $remove = $opts{remove} // sub { 0 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$opts{"remove"} // sub {
0;
}
MC/DC0%0/2
$opts{"remove"} // sub {
0;
}
$opts{"remove"}
sub {
0;
}
Truth table66%2/3
A // B
A= $opts{"remove"}B= sub {
0;
}
| |||||||||||||||||||||||||||||
| 490 | 3 | ▶ | my $keep = $opts{keep} // sub { 1 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$opts{"keep"} // sub {
1;
}
MC/DC0%0/2
$opts{"keep"} // sub {
1;
}
$opts{"keep"}
sub {
1;
}
Truth table66%2/3
A // B
A= $opts{"keep"}B= sub {
1;
}
| |||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 3 | foreach my $vn (keys %{$self->{vars}}) { | |||||||||||||||||||||||||||
| 493 | 36 | ▶ | $self->delete($vn) if $remove->($vn) or not $keep->($vn); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&$remove($vn) or not &$keep($vn)
MC/DC100%2/2
&$remove($vn) or not &$keep($vn)
&$remove($vn)
not &$keep($vn)
Truth table100%3/3
A or not(B)
A= &$remove($vn)B= not &$keep($vn)
| |||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | =item $string = "$sv" | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | Return a string representation of all substitutions variables except the | ||||||||||||||||||||||||||||
| 500 | automatic ones. | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | =item $string = $sv->output([$fh]) | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | Return all substitutions variables except the automatic ones. If $fh | ||||||||||||||||||||||||||||
| 505 | is passed print them into the filehandle. | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | =cut | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 6 | ▶ | sub output { | ||||||||||||||||||||||||||
|
Subroutine
output: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 510 | 6 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 511 | 6 | my $str = ''; | |||||||||||||||||||||||||||
| 512 | # Store all non-automatic substitutions only. | ||||||||||||||||||||||||||||
| 513 | 6 | foreach my $vn (sort keys %{$self->{vars}}) { | |||||||||||||||||||||||||||
| 514 | 42 | ▶ | next if $self->{attr}{$vn} & SUBSTVAR_ATTR_AUTO; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 515 | 21 | my $op; | |||||||||||||||||||||||||||
| 516 | 21 | ▶ | if ($self->{attr}{$vn} & SUBSTVAR_ATTR_OPT) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 517 | 1 | $op = '?='; | |||||||||||||||||||||||||||
| 518 | } elsif ($self->{attr}{$vn} & SUBSTVAR_ATTR_REQ) { | ||||||||||||||||||||||||||||
| 519 | 1 | $op = '!='; | |||||||||||||||||||||||||||
| 520 | } elsif ($self->{attr}{$vn} & SUBSTVAR_ATTR_IMPL) { | ||||||||||||||||||||||||||||
| 521 | 6 | $op = '$='; | |||||||||||||||||||||||||||
| 522 | } else { | ||||||||||||||||||||||||||||
| 523 | 13 | $op = '='; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | 21 | my $line = "$vn$op" . $self->{vars}{$vn} . "\n"; | |||||||||||||||||||||||||||
| 526 | 0 | ▶ | print { $fh } $line if defined $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 527 | 21 | $str .= $line; | |||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||
| 529 | 6 | return $str; | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | =item $sv->save($file) | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | Store all substitutions variables except the automatic ones in the | ||||||||||||||||||||||||||||
| 535 | indicated file. | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | =back | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | =head2 Version 2.04 (dpkg 1.23.0) | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | New feature: Add support for implicit substitution variables. | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | New method: $sv->set_as_implicit(), $sv->get_implicit_substvars(). | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | =head2 Version 2.03 (dpkg 1.22.15) | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | New methods: $sv->set_as_optional(), $sv->set_as_required(). | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | =head2 Version 2.02 (dpkg 1.22.7) | ||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | New feature: Add support for required substitution variables. | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | =head2 Version 2.01 (dpkg 1.21.8) | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | New feature: Add support for optional substitution variables. | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | =head2 Version 2.00 (dpkg 1.20.0) | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | Remove method: $sv->no_warn(). | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | New method: $sv->set_vendor_substvars(). | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | =head2 Version 1.06 (dpkg 1.19.0) | ||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | New method: $sv->set_desc_substvars(). | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | =head2 Version 1.05 (dpkg 1.18.11) | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | Obsolete substvar: Emit an error on Source-Version substvar usage. | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | New return: $sv->parse() now returns the number of parsed substvars. | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | New method: $sv->set_field_substvars(). | ||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | =head2 Version 1.04 (dpkg 1.18.0) | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | New method: $sv->filter(). | ||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | =head2 Version 1.03 (dpkg 1.17.11) | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | New method: $sv->set_as_auto(). | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | =head2 Version 1.02 (dpkg 1.16.5) | ||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | New argument: Accept a $binaryversion in $sv->set_version_substvars(), | ||||||||||||||||||||||||||||
| 588 | passing a single argument is still supported. | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | New method: $sv->mark_as_used(). | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | Deprecated method: $sv->no_warn(), use $sv->mark_as_used() instead. | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | =head2 Version 1.01 (dpkg 1.16.4) | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | New method: $sv->set_as_used(). | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | =head2 Version 1.00 (dpkg 1.15.6) | ||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | Mark the module as public. | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | =cut | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 1 | 1; | |||||||||||||||||||||||||||