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>
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.
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.
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/>.
26 Dpkg::Deps::OR - list of OR dependencies
30 This class represents a list of dependencies of which only one must be met
31 for the dependency to be true. It inherits from L<Dpkg::Deps::Multiple>.
35 package Dpkg
::Deps
::OR
1.00;
40 use parent
qw(Dpkg::Deps::Multiple);
46 =item $dep->output([$fh])
48 The output() method uses " | " to join the list of sub-dependencies.
55 my $res = join(' | ', map {
67 =item $dep->implies($other_dep)
69 Returns 1 when $dep implies $other_dep. Returns 0 when $dep implies
70 NOT($other_dep). Returns undef when there's no implication. $dep and
71 $other_dep do not need to be of the same type.
78 # Special case for AND with a single member, replace it by its member
79 if ($o->isa('Dpkg::Deps::AND')) {
80 my @subdeps = $o->get_deps();
81 if (scalar(@subdeps) == 1) {
86 # In general, an OR dependency can't imply anything except if each
87 # of its member implies a member in the other OR dependency
88 if ($o->isa('Dpkg::Deps::OR')) {
90 foreach my $dep ($self->get_deps()) {
92 foreach my $odep ($o->get_deps()) {
93 $found = 1 if $dep->implies($odep);
95 $subset = 0 if not $found;
102 =item $dep->get_evaluation($facts)
104 Evaluates the dependency given a list of installed packages and a list of
105 virtual packages provided. These lists are part of the
106 L<Dpkg::Deps::KnownFacts> object given as parameters.
108 Returns 1 when it's true, 0 when it's false, undef when some information
109 is lacking to conclude.
114 my ($self, $facts) = @_;
116 # Returns false if all members evaluates to 0
117 # Returns true if at least one member evaluates to true
118 # Returns undef otherwise
120 foreach my $dep ($self->get_deps()) {
121 my $eval = $dep->get_evaluation($facts);
122 if (not defined $eval) {
124 } elsif ($eval == 1) {
127 } elsif ($eval == 0) {
128 # Still possible to have a false evaluation
134 =item $dep->simplify_deps($facts, @assumed_deps)
136 Simplifies the dependency as much as possible given the list of facts (see
137 object L<Dpkg::Deps::KnownFacts>) and a list of other dependencies that are
143 my ($self, $facts) = @_;
147 while (@
{$self->{list
}}) {
148 my $dep = shift @
{$self->{list
}};
149 my $eval = $dep->get_evaluation($facts);
150 if (defined $eval and $eval == 1) {
154 foreach my $odep (@new, @
{$self->{list
}}) {
155 next WHILELOOP
if $odep->implies($dep);
159 $self->{list
} = [ @new ];
166 =head2 Version 1.00 (dpkg 1.15.6)
168 Mark the module as public.