File Coverage

File:Dpkg/Deps/Multiple.pm
Coverage:69.4%

linestmtbrancondsubpodtimecode
1# Copyright © 1998 Richard Braakman
2# Copyright © 1999 Darren Benham
3# Copyright © 2000 Sean 'Shaleh' Perry
4# Copyright © 2004 Frank Lichtenheld
5# Copyright © 2006 Russ Allbery
6# Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org>
7# Copyright © 2008-2009, 2012-2014 Guillem Jover <guillem@debian.org>
8#
9# This program is free software; you may redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21
22=encoding utf8
23
24 - 33
=head1 NAME

Dpkg::Deps::Multiple - base module to represent multiple dependencies

=head1 DESCRIPTION

The Dpkg::Deps::Multiple module provides objects implementing various types
of dependencies. It is the base class for Dpkg::Deps::{AND,OR,Union}.

=cut
34
35package Dpkg::Deps::Multiple 1.02;
36
37
12
12
12
7573
11
293
use strict;
38
12
12
12
22
11
323
use warnings;
39
40
12
12
12
28
12
560
use Carp;
41
42
12
12
12
31
14
618
use Dpkg::ErrorHandling;
43
44
12
12
12
33
10
102
use parent qw(Dpkg::Interface::Storable);
45
46 - 54
=head1 METHODS

=over 4

=item $dep = Dpkg::Deps::Multiple->new(%opts);

Creates a new object.

=cut
55
56sub new {
57
255
1
302
    my ($this, @deps) = @_;
58
255
555
    my $class = ref($this) || $this;
59
255
362
    my $self = { list => [ @deps ] };
60
61
255
255
    bless $self, $class;
62
255
296
    return $self;
63}
64
65 - 70
=item $dep->reset()

Clears any dependency information stored in $dep so that $dep->is_empty()
returns true.

=cut
71
72sub reset {
73
0
1
0
    my $self = shift;
74
75
0
0
    $self->{list} = [];
76}
77
78 - 82
=item $dep->add(@deps)

Adds new dependency objects at the end of the list.

=cut
83
84sub add {
85
741
1
541
    my ($self, @deps) = @_;
86
87
741
741
384
1183
    push @{$self->{list}}, @deps;
88}
89
90 - 94
=item $dep->get_deps()

Returns a list of sub-dependencies.

=cut
95
96sub get_deps {
97
582
1
370
    my $self = shift;
98
99
582
1548
582
354
1371
609
    return grep { not $_->is_empty() } @{$self->{list}};
100}
101
102 - 106
=item $dep->sort()

Sorts alphabetically the internal list of dependencies.

=cut
107
108sub sort {
109
6
1
4
    my $self = shift;
110
111
6
7
    my @res = ();
112
6
96
6
5
102
17
    @res = sort { Dpkg::Deps::deps_compare($a, $b) } @{$self->{list}};
113
6
18
    $self->{list} = [ @res ];
114}
115
116 - 121
=item $dep->arch_is_concerned($arch)

Returns true if at least one of the sub-dependencies apply to this
architecture.

=cut
122
123sub arch_is_concerned {
124
0
1
0
    my ($self, $host_arch) = @_;
125
126
0
0
    my $res = 0;
127
0
0
0
0
    foreach my $dep (@{$self->{list}}) {
128
0
0
        $res = 1 if $dep->arch_is_concerned($host_arch);
129    }
130
0
0
    return $res;
131}
132
133 - 141
=item $dep->reduce_arch($arch)

Simplifies the dependencies to contain only information relevant to the
given architecture. The non-relevant sub-dependencies are simply removed.

This trims off the architecture restriction list of L<Dpkg::Deps::Simple>
objects.

=cut
142
143sub reduce_arch {
144
0
1
0
    my ($self, $host_arch) = @_;
145
146
0
0
    my @new;
147
0
0
0
0
    foreach my $dep (@{$self->{list}}) {
148
0
0
        $dep->reduce_arch($host_arch);
149
0
0
        push @new, $dep if $dep->arch_is_concerned($host_arch);
150    }
151
0
0
    $self->{list} = [ @new ];
152}
153
154 - 158
=item $dep->has_arch_restriction()

Returns the list of package names that have such a restriction.

=cut
159
160sub has_arch_restriction {
161
0
1
0
    my $self = shift;
162
163
0
0
    my @res;
164
0
0
0
0
    foreach my $dep (@{$self->{list}}) {
165
0
0
        push @res, $dep->has_arch_restriction();
166    }
167
0
0
    return @res;
168}
169
170 - 174
=item $dep->profile_is_concerned()

Returns true if at least one of the sub-dependencies apply to this profile.

=cut
175
176sub profile_is_concerned {
177
12
1
15
    my ($self, $build_profiles) = @_;
178
179
12
8
    my $res = 0;
180
12
12
11
16
    foreach my $dep (@{$self->{list}}) {
181
12
17
        $res = 1 if $dep->profile_is_concerned($build_profiles);
182    }
183
12
18
    return $res;
184}
185
186 - 193
=item $dep->reduce_profiles()

Simplifies the dependencies to contain only information relevant to the
given profile. The non-relevant sub-dependencies are simply removed.

This trims off the profile restriction list of L<Dpkg::Deps::Simple> objects.

=cut
194
195sub reduce_profiles {
196
27
1
35
    my ($self, $build_profiles) = @_;
197
198
27
21
    my @new;
199
27
27
23
33
    foreach my $dep (@{$self->{list}}) {
200
198
229
        $dep->reduce_profiles($build_profiles);
201
198
207
        push @new, $dep if $dep->profile_is_concerned($build_profiles);
202    }
203
27
149
    $self->{list} = [ @new ];
204}
205
206 - 212
=item $dep->is_empty()

Returns true if the dependency is empty and doesn't contain any useful
information. This is true when a (descendant of) L<Dpkg::Deps::Multiple>
contains an empty list of dependencies.

=cut
213
214sub is_empty {
215
105
1
75
    my $self = shift;
216
217
105
105
76
167
    return scalar @{$self->{list}} == 0;
218}
219
220 - 224
=item $dep->merge_union($other_dep)

This method is not meaningful for this object, and will always croak.

=cut
225
226sub merge_union {
227
0
1
    croak 'method merge_union() is only valid for Dpkg::Deps::Simple';
228}
229
230=back
231
232 - 246
=head1 CHANGES

=head2 Version 1.02 (dpkg 1.17.10)

New methods: Add $dep->profile_is_concerned() and $dep->reduce_profiles().

=head2 Version 1.01 (dpkg 1.16.1)

New method: Add $dep->reset().

=head2 Version 1.00 (dpkg 1.15.6)

Mark the module as public.

=cut
247
2481;