| 1 | # Copyright © 2007-2010 Raphaël Hertzog <hertzog@debian.org> | ||||||||||||||||||||
| 2 | # Copyright © 2009, 2012-2015 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::Info - parse files like debian/control | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | It provides a class to access data of files that follow the same | ||||||||||||||||||||
| 26 | syntax as F<debian/control>. | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | package Dpkg::Control::Info 1.01; | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | ▶ | use v5.36; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 2 | ▶ | use Dpkg::Control; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 2 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 2 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | ▶ | use parent qw(Dpkg::Interface::Storable); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | use overload | ||||||||||||||||||||
| 41 | 2 | ▶ | '@{}' => sub { return [ $_[0]->{source}, @{$_[0]->{packages}} ] }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =head1 METHODS | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =over 4 | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =item $ctrl_tmpl = Dpkg::Control::Info->new(%opts) | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | Create a new Dpkg::Control::Info object. Loads F<debian/control> by default. | ||||||||||||||||||||
| 50 | If a single scalar is passed, it will be used as the filename to load | ||||||||||||||||||||
| 51 | instead of the default. If filename is "-", it parses the standard input. | ||||||||||||||||||||
| 52 | If filename is undef no loading will be performed. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | Options: | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =over | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =item B<filename> | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | Loads the file from the filename, instead of F<debian/control>. | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =back | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 8 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.5
Pod
documented
| |||||||||||||||||||||
| 67 | 8 | my ($this, @args) = @_; | |||||||||||||||||||
| 68 | 8 | ▶ | 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
| |||||||||||||||||||||
| 69 | 8 | my $self = { | |||||||||||||||||||
| 70 | source => undef, | ||||||||||||||||||||
| 71 | packages => [], | ||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||
| 73 | 8 | bless $self, $class; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 8 | my %opts; | |||||||||||||||||||
| 76 | 8 | ▶ | if (scalar @args == 0) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 77 | 0 | $opts{filename} = 'debian/control'; | |||||||||||||||||||
| 78 | } elsif (scalar @args == 1) { | ||||||||||||||||||||
| 79 | 1 | $opts{filename} = $args[0]; | |||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||
| 81 | 7 | %opts = @args; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 8 | ▶ | $self->load($opts{filename}) if $opts{filename}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 8 | return $self; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =item $ctrl_tmpl->reset() | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | Resets what got read. | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 8 | ▶ | sub reset { | ||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 96 | 8 | my $self = shift; | |||||||||||||||||||
| 97 | 8 | $self->{source} = undef; | |||||||||||||||||||
| 98 | 8 | $self->{packages} = []; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =item $ctrl_tmpl->parse($fh, $description) | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Parse a control file from the given filehandle. Exits in case of errors. | ||||||||||||||||||||
| 104 | $description is used to describe the filehandle, ideally it's a filename | ||||||||||||||||||||
| 105 | or a description of where the data comes from. It is used in error messages. | ||||||||||||||||||||
| 106 | The data in the object is reset before parsing new control files. | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 8 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: called CC=6 SCAR=19.0
Pod
documented
| |||||||||||||||||||||
| 111 | 8 | my ($self, $fh, $desc) = @_; | |||||||||||||||||||
| 112 | 8 | $self->reset(); | |||||||||||||||||||
| 113 | 8 | my $cdata = Dpkg::Control->new(type => CTRL_TMPL_SRC); | |||||||||||||||||||
| 114 | 8 | ▶ | return if not $cdata->parse($fh, $desc); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | 8 | $self->{source} = $cdata; | |||||||||||||||||||
| 116 | 8 | ▶ | unless (exists $cdata->{Source}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 117 | 0 | $cdata->parse_error($desc, g_("first stanza lacks a '%s' field"), | |||||||||||||||||||
| 118 | 'Source'); | ||||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | 8 | while (1) { | |||||||||||||||||||
| 121 | 18 | $cdata = Dpkg::Control->new(type => CTRL_TMPL_PKG); | |||||||||||||||||||
| 122 | 18 | ▶ | last if not $cdata->parse($fh, $desc); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | 10 | push @{$self->{packages}}, $cdata; | |||||||||||||||||||
| 124 | 10 | ▶ | unless (exists $cdata->{Package}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | 0 | $cdata->parse_error($desc, g_("stanza lacks the '%s' field"), | |||||||||||||||||||
| 126 | 'Package'); | ||||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | 10 | ▶ | unless (exists $cdata->{Architecture}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | 0 | $cdata->parse_error($desc, g_("stanza lacks the '%s' field"), | |||||||||||||||||||
| 130 | 'Architecture'); | ||||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =item $ctrl_tmpl->load($file) | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | Load the content of $file. Exits in case of errors. If file is "-", it | ||||||||||||||||||||
| 138 | loads from the standard input. | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =item $ctrl = $ctrl_tmpl->[0] | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =item $ctrl = $ctrl_tmpl->get_source() | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | Returns a L<Dpkg::Control> object containing the fields concerning the | ||||||||||||||||||||
| 145 | source package. | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 8 | ▶ | sub get_source { | ||||||||||||||||||
|
Subroutine
get_source: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 150 | 8 | my $self = shift; | |||||||||||||||||||
| 151 | 8 | return $self->{source}; | |||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | =item $ctrl = $ctrl_tmpl->get_pkg_by_idx($idx) | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | Returns a L<Dpkg::Control> object containing the fields concerning the binary | ||||||||||||||||||||
| 157 | package numbered $idx (starting at 1). | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 2 | ▶ | sub get_pkg_by_idx { | ||||||||||||||||||
|
Subroutine
get_pkg_by_idx: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 162 | 2 | my ($self, $idx) = @_; | |||||||||||||||||||
| 163 | 2 | return $self->{packages}[--$idx]; | |||||||||||||||||||
| 164 | } | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =item $ctrl = $ctrl_tmpl->get_pkg_by_name($name) | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | Returns a L<Dpkg::Control> object containing the fields concerning the binary | ||||||||||||||||||||
| 169 | package named $name. | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 1 | ▶ | sub get_pkg_by_name { | ||||||||||||||||||
|
Subroutine
get_pkg_by_name: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 174 | 1 | my ($self, $name) = @_; | |||||||||||||||||||
| 175 | 1 | foreach my $pkg (@{$self->{packages}}) { | |||||||||||||||||||
| 176 | 3 | ▶ | return $pkg if ($pkg->{Package} eq $name); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 177 | } | ||||||||||||||||||||
| 178 | 0 | return; | |||||||||||||||||||
| 179 | } | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | =item @ctrl_list = $ctrl_tmpl->get_packages() | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | Returns a list containing the L<Dpkg::Control> objects for all binary packages. | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | =cut | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | 0 | ▶ | sub get_packages { | ||||||||||||||||||
|
Subroutine
get_packages: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 189 | 0 | my $self = shift; | |||||||||||||||||||
| 190 | 0 | return @{$self->{packages}}; | |||||||||||||||||||
| 191 | } | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | =item $string = "$ctrl_tmpl" | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | Return a string representation of the content. | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | =item $string = $ctrl_tmpl->output([$fh]) | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | Return the content info into a string. If $fh is specified print it into | ||||||||||||||||||||
| 200 | the filehandle. | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | =cut | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 1 | ▶ | sub output { | ||||||||||||||||||
|
Subroutine
output: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 205 | 1 | my ($self, $fh) = @_; | |||||||||||||||||||
| 206 | 1 | my $str; | |||||||||||||||||||
| 207 | 1 | $str .= $self->{source}->output($fh); | |||||||||||||||||||
| 208 | 1 | foreach my $pkg (@{$self->{packages}}) { | |||||||||||||||||||
| 209 | 3 | ▶ | print { $fh } "\n" if defined $fh; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 210 | 3 | $str .= "\n" . $pkg->output($fh); | |||||||||||||||||||
| 211 | } | ||||||||||||||||||||
| 212 | 1 | return $str; | |||||||||||||||||||
| 213 | } | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | =item @ctrl_list = @{$ctrl_tmpl} | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | Return a list of L<Dpkg::Control> objects, the first one is corresponding to | ||||||||||||||||||||
| 218 | source information and the following ones are the binary packages | ||||||||||||||||||||
| 219 | information. | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | =back | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | =head1 CHANGES | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | =head2 Version 1.01 (dpkg 1.18.0) | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | New argument: The $c->new() constructor accepts an %opts argument. | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | =head2 Version 1.00 (dpkg 1.15.6) | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | Mark the module as public. | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | 2 | 1; | |||||||||||||||||||