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
22package Dpkg::Deps::Multiple;
23
24=encoding utf8
25
26 - 35
=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
36
37
1
1
1
311
1
11
use strict;
38
1
1
1
1
1
18
use warnings;
39
40our $VERSION = '1.02';
41
42
1
1
1
2
1
20
use Carp;
43
44
1
1
1
4
1
26
use Dpkg::ErrorHandling;
45
46
1
1
1
1
1
12
use parent qw(Dpkg::Interface::Storable);
47
48 - 56
=head1 METHODS

=over 4

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

Creates a new object.

=cut
57
58sub new {
59
77
1
43
    my $this = shift;
60
77
107
    my $class = ref($this) || $this;
61
77
73
    my $self = { list => [ @_ ] };
62
63
77
59
    bless $self, $class;
64
77
56
    return $self;
65}
66
67 - 72
=item $dep->reset()

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

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

Adds new dependency objects at the end of the list.

=cut
85
86sub add {
87
235
1
110
    my $self = shift;
88
89
235
235
115
247
    push @{$self->{list}}, @_;
90}
91
92 - 96
=item $dep->get_deps()

Returns a list of sub-dependencies.

=cut
97
98sub get_deps {
99
186
1
88
    my $self = shift;
100
101
186
504
186
86
316
127
    return grep { not $_->is_empty() } @{$self->{list}};
102}
103
104 - 108
=item $dep->sort()

Sorts alphabetically the internal list of dependencies.

=cut
109
110sub sort {
111
2
1
0
    my $self = shift;
112
113
2
2
    my @res = ();
114
2
32
2
0
21
4
    @res = sort { Dpkg::Deps::deps_compare($a, $b) } @{$self->{list}};
115
2
4
    $self->{list} = [ @res ];
116}
117
118 - 123
=item $dep->arch_is_concerned($arch)

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

=cut
124
125sub arch_is_concerned {
126
0
1
0
    my ($self, $host_arch) = @_;
127
128
0
0
    my $res = 0;
129
0
0
0
0
    foreach my $dep (@{$self->{list}}) {
130
0
0
        $res = 1 if $dep->arch_is_concerned($host_arch);
131    }
132
0
0
    return $res;
133}
134
135 - 143
=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 Dpkg::Deps::Simple
objects.

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

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

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

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

=cut
177
178sub profile_is_concerned {
179
4
1
1
    my ($self, $build_profiles) = @_;
180
181
4
3
    my $res = 0;
182
4
4
1
4
    foreach my $dep (@{$self->{list}}) {
183
4
3
        $res = 1 if $dep->profile_is_concerned($build_profiles);
184    }
185
4
3
    return $res;
186}
187
188 - 195
=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 Dpkg::Deps::Simple objects.

=cut
196
197sub reduce_profiles {
198
9
1
4
    my ($self, $build_profiles) = @_;
199
200
9
6
    my @new;
201
9
9
3
7
    foreach my $dep (@{$self->{list}}) {
202
66
51
        $dep->reduce_profiles($build_profiles);
203
66
54
        push @new, $dep if $dep->profile_is_concerned($build_profiles);
204    }
205
9
22
    $self->{list} = [ @new ];
206}
207
208 - 214
=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) Dpkg::Deps::Multiple
contains an empty list of dependencies.

=cut
215
216sub is_empty {
217
35
1
19
    my $self = shift;
218
219
35
35
16
40
    return scalar @{$self->{list}} == 0;
220}
221
222 - 226
=item $dep->merge_union($other_dep)

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

=cut
227
228sub merge_union {
229
0
1
    croak 'method merge_union() is only valid for Dpkg::Deps::Simple';
230}
231
232=back
233
234 - 248
=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
249
2501;