| 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::OR - list of OR dependencies | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 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>. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | package Dpkg::Deps::OR 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 | 14 | ▶ | sub output { | ||||||||||||||||||||||||||
|
Subroutine
output: called CC=2 SCAR=7.5
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 14 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | my $res = join(' | ', map { | ||||||||||||||||||||||||||||
| 55 | 31 | $_->output() | |||||||||||||||||||||||||||
| 56 | } grep { | ||||||||||||||||||||||||||||
| 57 | 14 | not $_->is_empty() | |||||||||||||||||||||||||||
| 58 | } $self->get_deps()); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 14 | ▶ | if (defined $fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | print { $fh } $res; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 14 | 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 | 4 | ▶ | sub implies { | ||||||||||||||||||||||||||
|
Subroutine
implies: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 4 | my ($self, $o) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Special case for AND with a single member, replace it by its member. | ||||||||||||||||||||||||||||
| 78 | 4 | ▶ | if ($o->isa('Dpkg::Deps::AND')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 2 | my @subdeps = $o->get_deps(); | |||||||||||||||||||||||||||
| 80 | 2 | ▶ | if (scalar(@subdeps) == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 2 | $o = $subdeps[0]; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # In general, an OR dependency cannot imply anything except if each | ||||||||||||||||||||||||||||
| 86 | # of its member implies a member in the other OR dependency. | ||||||||||||||||||||||||||||
| 87 | 4 | ▶ | if ($o->isa('Dpkg::Deps::OR')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 3 | my $subset = 1; | |||||||||||||||||||||||||||
| 89 | 3 | foreach my $dep ($self->get_deps()) { | |||||||||||||||||||||||||||
| 90 | 19 | my $found = 0; | |||||||||||||||||||||||||||
| 91 | 19 | foreach my $odep ($o->get_deps()) { | |||||||||||||||||||||||||||
| 92 | 72 | ▶ | $found = 1 if $dep->implies($odep); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 19 | ▶ | $subset = 0 if not $found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 3 | ▶ | return 1 if $subset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 3 | return; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =item $tribool = $dep->get_evaluation($facts) | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Evaluates the dependency given a list of installed packages and a list of | ||||||||||||||||||||||||||||
| 104 | virtual packages provided. These lists are part of the | ||||||||||||||||||||||||||||
| 105 | L<Dpkg::Deps::KnownFacts> object given as parameters. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Returns 1 when it's true, 0 when it's false, undef when some information | ||||||||||||||||||||||||||||
| 108 | is lacking to conclude. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 12 | ▶ | sub get_evaluation { | ||||||||||||||||||||||||||
|
Subroutine
get_evaluation: called CC=5 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 12 | my ($self, $facts) = @_; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # Returns false if all members evaluates to 0. | ||||||||||||||||||||||||||||
| 116 | # Returns true if at least one member evaluates to true. | ||||||||||||||||||||||||||||
| 117 | # Returns undef otherwise. | ||||||||||||||||||||||||||||
| 118 | 12 | my $result = 0; | |||||||||||||||||||||||||||
| 119 | 12 | foreach my $dep ($self->get_deps()) { | |||||||||||||||||||||||||||
| 120 | 26 | my $eval = $dep->get_evaluation($facts); | |||||||||||||||||||||||||||
| 121 | 26 | ▶ | if (not defined $eval) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 122 | 0 | $result = undef; | |||||||||||||||||||||||||||
| 123 | } elsif ($eval == 1) { | ||||||||||||||||||||||||||||
| 124 | 3 | $result = 1; | |||||||||||||||||||||||||||
| 125 | 3 | last; | |||||||||||||||||||||||||||
| 126 | } elsif ($eval == 0) { | ||||||||||||||||||||||||||||
| 127 | # Still possible to have a false evaluation. | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 12 | return $result; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =item $dep->simplify_deps($facts, @assumed_deps) | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | Simplifies the dependency as much as possible given the list of facts (see | ||||||||||||||||||||||||||||
| 136 | object L<Dpkg::Deps::KnownFacts>) and a list of other dependencies that are | ||||||||||||||||||||||||||||
| 137 | known to be true. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub simplify_deps { | ||||||||||||||||||||||||||
|
Subroutine
simplify_deps: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 0 | my ($self, $facts) = @_; | |||||||||||||||||||||||||||
| 143 | 0 | my @new; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | WHILELOOP: while (@{$self->{list}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | my $dep = shift @{$self->{list}}; | |||||||||||||||||||||||||||
| 147 | 0 | my $eval = $dep->get_evaluation($facts); | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | if (defined $eval and $eval == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $eval and $eval == 1
MC/DC0%0/2
defined $eval and $eval == 1
defined $eval
$eval == 1
Truth table0%0/3
A and B
A= defined $evalB= $eval == 1
| |||||||||||||||||||||||||||||
| 149 | 0 | $self->{list} = []; | |||||||||||||||||||||||||||
| 150 | 0 | return; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 0 | foreach my $odep (@new, @{$self->{list}}) { | |||||||||||||||||||||||||||
| 153 | 0 | ▶ | next WHILELOOP if $odep->implies($dep); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 0 | push @new, $dep; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 0 | $self->{list} = [ @new ]; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =back | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head2 Version 1.00 (dpkg 1.15.6) | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | Mark the module as public. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =cut | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 4 | 1; | |||||||||||||||||||||||||||