| 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 can 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 program 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 | =head1 NAME | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | Dpkg::Deps::AND - list of AND dependencies | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | This class represents a list of dependencies that must be met at the same | ||||||||||||||||||||||||||||
| 31 | time. It inherits from L<Dpkg::Deps::Multiple>. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | package Dpkg::Deps::AND 1.00; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 4 | ▶ | use parent qw(Dpkg::Deps::Multiple); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =over 4 | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =item $string = $dep->output([$fh]) | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | The output() method uses ", " to join the list of sub-dependencies. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 46 | ▶ | sub output { | ||||||||||||||||||||||||||
|
Subroutine
output: called CC=2 SCAR=7.5
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 46 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | my $res = join(', ', map { | ||||||||||||||||||||||||||||
| 55 | 122 | $_->output() | |||||||||||||||||||||||||||
| 56 | } grep { | ||||||||||||||||||||||||||||
| 57 | 46 | not $_->is_empty() | |||||||||||||||||||||||||||
| 58 | } $self->get_deps()); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 46 | ▶ | if (defined $fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | print { $fh } $res; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 46 | return $res; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =item $tribool = $dep->implies($other_dep) | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Returns 1 when $dep implies $other_dep. Returns 0 when $dep implies | ||||||||||||||||||||||||||||
| 69 | NOT($other_dep). Returns undef when there's no implication. $dep and | ||||||||||||||||||||||||||||
| 70 | $other_dep do not need to be of the same type. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 23 | ▶ | sub implies { | ||||||||||||||||||||||||||
|
Subroutine
implies: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 23 | my ($self, $o) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # If any individual member can imply $o or NOT $o, we are fine. | ||||||||||||||||||||||||||||
| 78 | 23 | foreach my $dep ($self->get_deps()) { | |||||||||||||||||||||||||||
| 79 | 34 | my $implication = $dep->implies($o); | |||||||||||||||||||||||||||
| 80 | 34 | ▶ | return 1 if defined $implication and $implication == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $implication and $implication == 1
MC/DC100%2/2
defined $implication and $implication == 1
defined $implication
$implication == 1
Truth table100%3/3
A and B
A= defined $implicationB= $implication == 1
| |||||||||||||||||||||||||||||
| 81 | 28 | ▶ | return 0 if defined $implication and $implication == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $implication and $implication == 0
MC/DC50%1/2
defined $implication and $implication == 0
defined $implication
$implication == 0
Truth table66%2/3
A and B
A= defined $implicationB= $implication == 0
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # If $o is an AND, we might have an implication, if we find an | ||||||||||||||||||||||||||||
| 85 | # implication within us for each predicate in $o. | ||||||||||||||||||||||||||||
| 86 | 16 | ▶ | if ($o->isa('Dpkg::Deps::AND')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 9 | my $subset = 1; | |||||||||||||||||||||||||||
| 88 | 9 | foreach my $odep ($o->get_deps()) { | |||||||||||||||||||||||||||
| 89 | 20 | my $found = 0; | |||||||||||||||||||||||||||
| 90 | 20 | foreach my $dep ($self->get_deps()) { | |||||||||||||||||||||||||||
| 91 | 67 | ▶ | $found = 1 if $dep->implies($odep); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 20 | ▶ | $subset = 0 if not $found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 9 | ▶ | return 1 if $subset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 15 | return; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =item $tribool = $dep->get_evaluation($facts) | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Evaluates the dependency given a list of installed packages and a list of | ||||||||||||||||||||||||||||
| 103 | virtual packages provided. These lists are part of the | ||||||||||||||||||||||||||||
| 104 | L<Dpkg::Deps::KnownFacts> object given as parameters. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Returns 1 when it's true, 0 when it's false, undef when some information | ||||||||||||||||||||||||||||
| 107 | is lacking to conclude. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub get_evaluation { | ||||||||||||||||||||||||||
|
Subroutine
get_evaluation: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 0 | my ($self, $facts) = @_; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # Return 1 only if all members evaluates to true. | ||||||||||||||||||||||||||||
| 115 | # Return 0 if at least one member evaluates to false. | ||||||||||||||||||||||||||||
| 116 | # Return undef otherwise. | ||||||||||||||||||||||||||||
| 117 | 0 | my $result = 1; | |||||||||||||||||||||||||||
| 118 | 0 | foreach my $dep ($self->get_deps()) { | |||||||||||||||||||||||||||
| 119 | 0 | my $eval = $dep->get_evaluation($facts); | |||||||||||||||||||||||||||
| 120 | 0 | ▶ | if (not defined $eval) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 121 | 0 | $result = undef; | |||||||||||||||||||||||||||
| 122 | } elsif ($eval == 0) { | ||||||||||||||||||||||||||||
| 123 | 0 | $result = 0; | |||||||||||||||||||||||||||
| 124 | 0 | last; | |||||||||||||||||||||||||||
| 125 | } elsif ($eval == 1) { | ||||||||||||||||||||||||||||
| 126 | # Still possible. | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 0 | return $result; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =item $dep->simplify_deps($facts, @assumed_deps) | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Simplifies the dependency as much as possible given the list of facts (see | ||||||||||||||||||||||||||||
| 135 | object L<Dpkg::Deps::KnownFacts>) and a list of other dependencies that are | ||||||||||||||||||||||||||||
| 136 | known to be true. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 23 | ▶ | sub simplify_deps { | ||||||||||||||||||||||||||
|
Subroutine
simplify_deps: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 23 | my ($self, $facts, @knowndeps) = @_; | |||||||||||||||||||||||||||
| 142 | 23 | my @new; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 23 | ▶ | WHILELOOP: while (@{$self->{list}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 42 | my $dep = shift @{$self->{list}}; | |||||||||||||||||||||||||||
| 146 | 42 | my $eval = $dep->get_evaluation($facts); | |||||||||||||||||||||||||||
| 147 | 42 | ▶ | next if defined $eval and $eval == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $eval and $eval == 1
MC/DC50%1/2
defined $eval and $eval == 1
defined $eval
$eval == 1
Truth table66%2/3
A and B
A= defined $evalB= $eval == 1
| |||||||||||||||||||||||||||||
| 148 | 31 | foreach my $odep (@knowndeps, @new) { | |||||||||||||||||||||||||||
| 149 | 18 | ▶ | next WHILELOOP if $odep->implies($dep); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | # When a dependency is implied by another dependency that follows, | ||||||||||||||||||||||||||||
| 152 | # then invert them. "a | b, c, a" becomes "a, c" and not "c, a". | ||||||||||||||||||||||||||||
| 153 | 30 | my $i = 0; | |||||||||||||||||||||||||||
| 154 | 30 | foreach my $odep (@{$self->{list}}) { | |||||||||||||||||||||||||||
| 155 | 27 | ▶ | if (defined $odep and $odep->implies($dep)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $odep and $odep->implies($dep)
MC/DC50%1/2
defined $odep and $odep->implies($dep)
defined $odep
$odep->implies($dep)
Truth table66%2/3
A and B
A= defined $odepB= $odep->implies($dep)
| |||||||||||||||||||||||||||||
| 156 | 4 | splice @{$self->{list}}, $i, 1; | |||||||||||||||||||||||||||
| 157 | 4 | unshift @{$self->{list}}, $odep; | |||||||||||||||||||||||||||
| 158 | 4 | next WHILELOOP; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | 23 | $i++; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | 26 | push @new, $dep; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 23 | $self->{list} = [ @new ]; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =back | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head2 Version 1.00 (dpkg 1.15.6) | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | Mark the module as public. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 4 | 1; | |||||||||||||||||||||||||||