| File: | Dpkg/Deps/OR.pm |
| Coverage: | 67.7% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 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::OR - list of OR dependencies =head1 DESCRIPTION This class represents a list of dependencies of which only one must be met for the dependency to be true. It inherits from L<Dpkg::Deps::Multiple>. =cut | ||||||
| 34 | |||||||
| 35 | package Dpkg::Deps::OR 1.00; | ||||||
| 36 | |||||||
| 37 | 12 12 12 | 76 11 397 | use strict; | ||||
| 38 | 12 12 12 | 32 6 586 | use warnings; | ||||
| 39 | |||||||
| 40 | 12 12 12 | 38 8 38 | use parent qw(Dpkg::Deps::Multiple); | ||||
| 41 | |||||||
| 42 - 50 | =head1 METHODS =over 4 =item $dep->output([$fh]) The output() method uses " | " to join the list of sub-dependencies. =cut | ||||||
| 51 | |||||||
| 52 | sub output { | ||||||
| 53 | 42 | 1 | 47 | my ($self, $fh) = @_; | |||
| 54 | |||||||
| 55 | my $res = join(' | ', map { | ||||||
| 56 | 93 | 112 | $_->output() | ||||
| 57 | } grep { | ||||||
| 58 | 42 93 | 54 109 | not $_->is_empty() | ||||
| 59 | } $self->get_deps()); | ||||||
| 60 | |||||||
| 61 | 42 | 63 | if (defined $fh) { | ||||
| 62 | 0 0 | 0 0 | print { $fh } $res; | ||||
| 63 | } | ||||||
| 64 | 42 | 68 | return $res; | ||||
| 65 | } | ||||||
| 66 | |||||||
| 67 - 73 | =item $dep->implies($other_dep) Returns 1 when $dep implies $other_dep. Returns 0 when $dep implies NOT($other_dep). Returns undef when there's no implication. $dep and $other_dep do not need to be of the same type. =cut | ||||||
| 74 | |||||||
| 75 | sub implies { | ||||||
| 76 | 12 | 1 | 13 | my ($self, $o) = @_; | |||
| 77 | |||||||
| 78 | # Special case for AND with a single member, replace it by its member | ||||||
| 79 | 12 | 37 | if ($o->isa('Dpkg::Deps::AND')) { | ||||
| 80 | 6 | 11 | my @subdeps = $o->get_deps(); | ||||
| 81 | 6 | 18 | if (scalar(@subdeps) == 1) { | ||||
| 82 | 6 | 7 | $o = $subdeps[0]; | ||||
| 83 | } | ||||||
| 84 | } | ||||||
| 85 | |||||||
| 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 | 12 | 25 | if ($o->isa('Dpkg::Deps::OR')) { | ||||
| 89 | 9 | 7 | my $subset = 1; | ||||
| 90 | 9 | 12 | foreach my $dep ($self->get_deps()) { | ||||
| 91 | 57 | 40 | my $found = 0; | ||||
| 92 | 57 | 72 | foreach my $odep ($o->get_deps()) { | ||||
| 93 | 216 | 197 | $found = 1 if $dep->implies($odep); | ||||
| 94 | } | ||||||
| 95 | 57 | 76 | $subset = 0 if not $found; | ||||
| 96 | } | ||||||
| 97 | 9 | 17 | return 1 if $subset; | ||||
| 98 | } | ||||||
| 99 | 9 | 17 | return; | ||||
| 100 | } | ||||||
| 101 | |||||||
| 102 - 111 | =item $dep->get_evaluation($facts) Evaluates the dependency given a list of installed packages and a list of virtual packages provided. These lists are part of the L<Dpkg::Deps::KnownFacts> object given as parameters. Returns 1 when it's true, 0 when it's false, undef when some information is lacking to conclude. =cut | ||||||
| 112 | |||||||
| 113 | sub get_evaluation { | ||||||
| 114 | 36 | 1 | 45 | my ($self, $facts) = @_; | |||
| 115 | |||||||
| 116 | # Returns false if all members evaluates to 0 | ||||||
| 117 | # Returns true if at least one member evaluates to true | ||||||
| 118 | # Returns undef otherwise | ||||||
| 119 | 36 | 31 | my $result = 0; | ||||
| 120 | 36 | 55 | foreach my $dep ($self->get_deps()) { | ||||
| 121 | 78 | 95 | my $eval = $dep->get_evaluation($facts); | ||||
| 122 | 78 | 170 | if (not defined $eval) { | ||||
| 123 | 0 | 0 | $result = undef; | ||||
| 124 | } elsif ($eval == 1) { | ||||||
| 125 | 9 | 5 | $result = 1; | ||||
| 126 | 9 | 8 | last; | ||||
| 127 | } elsif ($eval == 0) { | ||||||
| 128 | # Still possible to have a false evaluation | ||||||
| 129 | } | ||||||
| 130 | } | ||||||
| 131 | 36 | 42 | return $result; | ||||
| 132 | } | ||||||
| 133 | |||||||
| 134 - 140 | =item $dep->simplify_deps($facts, @assumed_deps) Simplifies the dependency as much as possible given the list of facts (see object L<Dpkg::Deps::KnownFacts>) and a list of other dependencies that are known to be true. =cut | ||||||
| 141 | |||||||
| 142 | sub simplify_deps { | ||||||
| 143 | 0 | 1 | my ($self, $facts) = @_; | ||||
| 144 | 0 | my @new; | |||||
| 145 | |||||||
| 146 | WHILELOOP: | ||||||
| 147 | 0 0 | while (@{$self->{list}}) { | |||||
| 148 | 0 0 | my $dep = shift @{$self->{list}}; | |||||
| 149 | 0 | my $eval = $dep->get_evaluation($facts); | |||||
| 150 | 0 | if (defined $eval and $eval == 1) { | |||||
| 151 | 0 | $self->{list} = []; | |||||
| 152 | 0 | return; | |||||
| 153 | } | ||||||
| 154 | 0 0 | foreach my $odep (@new, @{$self->{list}}) { | |||||
| 155 | 0 | next WHILELOOP if $odep->implies($dep); | |||||
| 156 | } | ||||||
| 157 | 0 | push @new, $dep; | |||||
| 158 | } | ||||||
| 159 | 0 | $self->{list} = [ @new ]; | |||||
| 160 | } | ||||||
| 161 | |||||||
| 162 | =back | ||||||
| 163 | |||||||
| 164 - 170 | =head1 CHANGES =head2 Version 1.00 (dpkg 1.15.6) Mark the module as public. =cut | ||||||
| 171 | |||||||
| 172 | 1; | ||||||