File: | Dpkg/Deps/AND.pm |
Coverage: | 80.2% |
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::AND - list of AND dependencies =head1 DESCRIPTION This class represents a list of dependencies that must be met at the same time. It inherits from L<Dpkg::Deps::Multiple>. =cut | ||||||
34 | |||||||
35 | package Dpkg::Deps::AND 1.00; | ||||||
36 | |||||||
37 | 12 12 12 | 43 7 274 | use strict; | ||||
38 | 12 12 12 | 19 33 360 | use warnings; | ||||
39 | |||||||
40 | 12 12 12 | 33 14 36 | 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 | 138 | 1 | 146 | my ($self, $fh) = @_; | |||
54 | |||||||
55 | my $res = join(', ', map { | ||||||
56 | 366 | 350 | $_->output() | ||||
57 | } grep { | ||||||
58 | 138 366 | 207 315 | not $_->is_empty() | ||||
59 | } $self->get_deps()); | ||||||
60 | |||||||
61 | 138 | 173 | if (defined $fh) { | ||||
62 | 0 0 | 0 0 | print { $fh } $res; | ||||
63 | } | ||||||
64 | 138 | 292 | 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 | 69 | 1 | 75 | my ($self, $o) = @_; | |||
77 | |||||||
78 | # If any individual member can imply $o or NOT $o, we're fine | ||||||
79 | 69 | 100 | foreach my $dep ($self->get_deps()) { | ||||
80 | 102 | 121 | my $implication = $dep->implies($o); | ||||
81 | 102 | 163 | return 1 if defined $implication and $implication == 1; | ||||
82 | 84 | 95 | return 0 if defined $implication and $implication == 0; | ||||
83 | } | ||||||
84 | |||||||
85 | # If o is an AND, we might have an implication, if we find an | ||||||
86 | # implication within us for each predicate in o | ||||||
87 | 48 | 82 | if ($o->isa('Dpkg::Deps::AND')) { | ||||
88 | 27 | 22 | my $subset = 1; | ||||
89 | 27 | 44 | foreach my $odep ($o->get_deps()) { | ||||
90 | 60 | 39 | my $found = 0; | ||||
91 | 60 | 48 | foreach my $dep ($self->get_deps()) { | ||||
92 | 201 | 162 | $found = 1 if $dep->implies($odep); | ||||
93 | } | ||||||
94 | 60 | 62 | $subset = 0 if not $found; | ||||
95 | } | ||||||
96 | 27 | 41 | return 1 if $subset; | ||||
97 | } | ||||||
98 | 45 | 74 | return; | ||||
99 | } | ||||||
100 | |||||||
101 - 110 | =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 | ||||||
111 | |||||||
112 | sub get_evaluation { | ||||||
113 | 0 | 1 | 0 | my ($self, $facts) = @_; | |||
114 | |||||||
115 | # Return 1 only if all members evaluates to true | ||||||
116 | # Return 0 if at least one member evaluates to false | ||||||
117 | # Return undef otherwise | ||||||
118 | 0 | 0 | my $result = 1; | ||||
119 | 0 | 0 | foreach my $dep ($self->get_deps()) { | ||||
120 | 0 | 0 | my $eval = $dep->get_evaluation($facts); | ||||
121 | 0 | 0 | if (not defined $eval) { | ||||
122 | 0 | 0 | $result = undef; | ||||
123 | } elsif ($eval == 0) { | ||||||
124 | 0 | 0 | $result = 0; | ||||
125 | 0 | 0 | last; | ||||
126 | } elsif ($eval == 1) { | ||||||
127 | # Still possible | ||||||
128 | } | ||||||
129 | } | ||||||
130 | 0 | 0 | return $result; | ||||
131 | } | ||||||
132 | |||||||
133 - 139 | =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 | ||||||
140 | |||||||
141 | sub simplify_deps { | ||||||
142 | 69 | 1 | 92 | my ($self, $facts, @knowndeps) = @_; | |||
143 | 69 | 51 | my @new; | ||||
144 | |||||||
145 | WHILELOOP: | ||||||
146 | 69 195 | 50 228 | while (@{$self->{list}}) { | ||||
147 | 126 126 | 86 150 | my $dep = shift @{$self->{list}}; | ||||
148 | 126 | 199 | my $eval = $dep->get_evaluation($facts); | ||||
149 | 126 | 319 | next if defined $eval and $eval == 1; | ||||
150 | 93 | 86 | foreach my $odep (@knowndeps, @new) { | ||||
151 | 54 | 53 | next WHILELOOP if $odep->implies($dep); | ||||
152 | } | ||||||
153 | # When a dependency is implied by another dependency that | ||||||
154 | # follows, then invert them | ||||||
155 | # "a | b, c, a" becomes "a, c" and not "c, a" | ||||||
156 | 90 | 71 | my $i = 0; | ||||
157 | 90 90 | 53 84 | foreach my $odep (@{$self->{list}}) { | ||||
158 | 81 | 116 | if (defined $odep and $odep->implies($dep)) { | ||||
159 | 12 12 | 10 11 | splice @{$self->{list}}, $i, 1; | ||||
160 | 12 12 | 12 12 | unshift @{$self->{list}}, $odep; | ||||
161 | 12 | 32 | next WHILELOOP; | ||||
162 | } | ||||||
163 | 69 | 51 | $i++; | ||||
164 | } | ||||||
165 | 78 | 73 | push @new, $dep; | ||||
166 | } | ||||||
167 | 69 | 139 | $self->{list} = [ @new ]; | ||||
168 | } | ||||||
169 | |||||||
170 | =back | ||||||
171 | |||||||
172 - 178 | =head1 CHANGES =head2 Version 1.00 (dpkg 1.15.6) Mark the module as public. =cut | ||||||
179 | |||||||
180 | 1; |