| 1 | # Copyright © 2008-2011 Raphaël Hertzog <hertzog@debian.org> | ||||||||||||||||||||||||||||
| 2 | # Copyright © 2008-2018 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::Source::Format - manipulate debian/source/format files | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | This module provides a class that can manipulate Debian source | ||||||||||||||||||||||||||||
| 26 | package F<debian/source/format> files. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | package Dpkg::Source::Format 1.00; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use parent qw(Dpkg::Interface::Storable); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head1 METHODS | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =over 4 | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =item $format = Dpkg::Source::Format->new(%opts) | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Creates a new object corresponding to a source package's | ||||||||||||||||||||||||||||
| 46 | F<debian/source/format> file. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Options: | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =over | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item B<filename> | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Set the filename to use to parse and set the format. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item B<format> | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Set and validate the format to use instead of loading the default file, | ||||||||||||||||||||||||||||
| 59 | if no filename has been specified. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =back | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 2 | my ($this, %opts) = @_; | |||||||||||||||||||||||||||
| 67 | 2 | ▶ | 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
| |||||||||||||||||||||||||||||
| 68 | 2 | my $self = { | |||||||||||||||||||||||||||
| 69 | filename => undef, | ||||||||||||||||||||||||||||
| 70 | major => undef, | ||||||||||||||||||||||||||||
| 71 | minor => undef, | ||||||||||||||||||||||||||||
| 72 | variant => undef, | ||||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||
| 74 | 2 | bless $self, $class; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | if (exists $opts{filename}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 77 | 0 | $self->load($opts{filename}, compression => 0); | |||||||||||||||||||||||||||
| 78 | } elsif ($opts{format}) { | ||||||||||||||||||||||||||||
| 79 | 0 | $self->set($opts{format}); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 2 | return $self; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =item $format->set_from_parts($major[, $minor[, $variant]]) | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Sets the source format from its parts. The $major part is mandatory. | ||||||||||||||||||||||||||||
| 87 | The $minor and $variant parts are optional. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | B<Notice>: This function performs no validation. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 3 | ▶ | sub set_from_parts { | ||||||||||||||||||||||||||
|
Subroutine
set_from_parts: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 3 | my ($self, $major, $minor, $variant) = @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | $self->{major} = $major; | |||||||||||||||||||||||||||
| 97 | 3 | ▶ | $self->{minor} = $minor // 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$minor // 0
MC/DC100%1/1
$minor // 0
$minor
Truth table100%2/2
A
A= $minor
| |||||||||||||||||||||||||||||
| 98 | 3 | $self->{variant} = $variant; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =item ($major, $minor, $variant) = $format->set($format) | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Sets (and validates) the source $format specified. Will return the parsed | ||||||||||||||||||||||||||||
| 104 | format parts as a list, the optional $minor and $variant parts might be | ||||||||||||||||||||||||||||
| 105 | undef. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 11 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 11 | my ($self, $format) = @_; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 11 | ▶ | if ($format =~ /^(\d+)(?:\.(\d+))?(?:\s+\(([a-z0-9]+)\))?$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 3 | my ($major, $minor, $variant) = ($1, $2, $3); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 3 | $self->set_from_parts($major, $minor, $variant); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 3 | return ($major, $minor, $variant); | |||||||||||||||||||||||||||
| 118 | } else { | ||||||||||||||||||||||||||||
| 119 | 8 | error(g_("source package format '%s' is invalid"), $format); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =item ($major, $minor, $variant) = $format->get() | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =item $format = $format->get() | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | Gets the source format, either as properly formatted scalar, or as a list | ||||||||||||||||||||||||||||
| 128 | of its parts, where the optional $minor and $variant parts might be undef. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 5 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 5 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | return ($self->{major}, $self->{minor}, $self->{variant}); | |||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||
| 138 | 4 | my $format = "$self->{major}.$self->{minor}"; | |||||||||||||||||||||||||||
| 139 | 4 | ▶ | $format .= " ($self->{variant})" if defined $self->{variant}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 4 | return $format; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =item $count = $format->parse($fh, $desc) | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | Parse the source format string from $fh, with filehandle description $desc. | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 0 | my ($self, $fh, $desc) = @_; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | my $format = <$fh>; | |||||||||||||||||||||||||||
| 155 | 0 | ▶ | chomp $format if defined $format; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | error(g_('%s is empty'), $desc) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $format and length $format
MC/DC0%0/2
defined $format and length $format
defined $format
length $format
Truth table0%0/3
A and B
A= defined $formatB= length $format
| |||||||||||||||||||||||||||||
| 157 | unless defined $format and length $format; | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | $self->set($format); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | return 1; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =item $count = $format->load($filename) | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | Parse $filename contents for a source package format string. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =item $string = "$format" | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =item $string = $format->output([$fh]) | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Returns a string representing the source package format version. | ||||||||||||||||||||||||||||
| 173 | If $fh is set, it prints the string to the filehandle. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | ▶ | sub output { | ||||||||||||||||||||||||||
|
Subroutine
output: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 178 | 1 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1 | my $str = $self->get(); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | print { $fh } "$str\n" if defined $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 1 | return $str; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =item $format->save($filename) | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Save the source package format into the given $filename. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =back | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =head2 Version 1.00 (dpkg 1.19.3) | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | Mark the module as public. | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =cut | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 2 | 1; | |||||||||||||||||||||||||||