blib/lib/CPAN/Queue.pm

filter: Statementstmt 22.0% 37 / 168 Branchbran 5.5% 4 / 72 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 32.3% 11 / 34 Podpod 0.0% 0 / 22 totaltotal 16.4% 52 / 316 CC 47 SCAR 38.3
CC
47
Cov
16%
jumpqueue
132.0
jumpqueue
132.0
reqtype_of
42.0
CRAP 46.1
« blib/lib/CPAN/FTP/netrc.pm ↑ Summary blib/lib/CPAN/HTTP/Client.pm »
1 # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package CPAN::Queue::Item;
4  
5 # CPAN::Queue::Item::new ;
6 7 ▶sub new {
Subroutine new: called CC=1 SCAR=1.2
7 0 ▶ my($class,@attr) = @_;
Subroutine new: not called CC=1 SCAR=1.2
8 0 my $self = bless { @attr }, $class;
9 0 return $self;
10 }
11  
12 7 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=1.2
13 0 ▶ my($self) = @_;
Subroutine as_string: not called CC=1 SCAR=1.2
14 0 $self->{qmod};
15 }
16  
17 # r => requires, b => build_requires, c => commandline
18 7 ▶sub reqtype {
Subroutine reqtype: called CC=1 SCAR=1.2
19 0 ▶ my($self) = @_;
Subroutine reqtype: not called CC=1 SCAR=1.2
20 0 $self->{reqtype};
21 }
22  
23 7 ▶sub optional {
Subroutine optional: called CC=1 SCAR=1.2
24 0 ▶ my($self) = @_;
Subroutine optional: not called CC=1 SCAR=1.2
25 0 $self->{optional};
26 }
27  
28 package CPAN::Queue;
29  
30 # One use of the queue is to determine if we should or shouldn't
31 # announce the availability of a new CPAN module
32  
33 # Now we try to use it for dependency tracking. For that to happen
34 # we need to draw a dependency tree and do the leaves first. This can
35 # easily be reached by running CPAN.pm recursively, but we don't want
36 # to waste memory and run into deep recursion. So what we can do is
37 # this:
38  
39 # CPAN::Queue is the package where the queue is maintained. Dependencies
40 # often have high priority and must be brought to the head of the queue,
41 # possibly by jumping the queue if they are already there. My first code
42 # attempt tried to be extremely correct. Whenever a module needed
43 # immediate treatment, I either unshifted it to the front of the queue,
44 # or, if it was already in the queue, I spliced and let it bypass the
45 # others. This became a too correct model that made it impossible to put
46 # an item more than once into the queue. Why would you need that? Well,
47 # you need temporary duplicates as the manager of the queue is a loop
48 # that
49 #
50 # (1) looks at the first item in the queue without shifting it off
51 #
52 # (2) cares for the item
53 #
54 # (3) removes the item from the queue, *even if its agenda failed and
55 # even if the item isn't the first in the queue anymore* (that way
56 # protecting against never ending queues)
57 #
58 # So if an item has prerequisites, the installation fails now, but we
59 # want to retry later. That's easy if we have it twice in the queue.
60 #
61 # I also expect insane dependency situations where an item gets more
62 # than two lives in the queue. Simplest example is triggered by 'install
63 # Foo Foo Foo'. People make this kind of mistakes and I don't want to
64 # get in the way. I wanted the queue manager to be a dumb servant, not
65 # one that knows everything.
66 #
67 # Who would I tell in this model that the user wants to be asked before
68 # processing? I can't attach that information to the module object,
69 # because not modules are installed but distributions. So I'd have to
70 # tell the distribution object that it should ask the user before
71 # processing. Where would the question be triggered then? Most probably
72 # in CPAN::Distribution::rematein.
73  
74 26 ▶use vars qw{ @All $VERSION };
Subroutine BEGIN: called CC=1 SCAR=0.0
75 26 $VERSION = "5.5003";
76  
77 # CPAN::Queue::queue_item ;
78 7 ▶sub queue_item {
Subroutine queue_item: called CC=1 SCAR=1.2
Pod undocumented
79 0 ▶ my($class,@attr) = @_;
Subroutine queue_item: not called CC=1 SCAR=1.2
Pod undocumented
80 0 my $item = "$class\::Item"->new(@attr);
81 0 $class->qpush($item);
82 0 return 1;
83 }
84  
85 # CPAN::Queue::qpush ;
86 7 ▶sub qpush {
Subroutine qpush: called CC=2 SCAR=11.6
Pod undocumented
87 0 ▶ my($class,$obj) = @_;
Subroutine qpush: not called CC=2 SCAR=11.6
Pod undocumented
88 0 push @All, $obj;
89 CPAN->debug(sprintf("in new All[%s]",
90 0 ▶ join("",map {sprintf " %s\[%s][%s]\n",$_->{qmod},$_->{reqtype},$_->{optional}} @All),
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 7 7
if $CPAN::DEBUG 0 0 0
91 )) if $CPAN::DEBUG;
92 }
93  
94 # CPAN::Queue::first ;
95 12 ▶sub first {
Subroutine first: called CC=1 SCAR=1.2
Pod undocumented
96 0 ▶ my $obj = $All[0];
Subroutine first: not called CC=1 SCAR=1.2
Pod undocumented
97 0 $obj;
98 }
99  
100 # CPAN::Queue::delete_first ;
101 5 ▶sub delete_first {
Subroutine delete_first: called CC=4 SCAR=20.7
Pod undocumented
102 0 ▶ my($class,$what) = @_;
Subroutine delete_first: not called CC=4 SCAR=20.7
Pod undocumented
103 0 my $i;
104 0 for my $i (0..$#All) {
105 0 ▶ if ( $All[$i]->{qmod} eq $what ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::Queue::All[$i]{"qmod"} eq $what) 4 0 4
if ($CPAN::Queue::All[$i]{"qmod"} eq $what) 0 0 0
106 0 splice @All, $i, 1;
107 0 last;
108 }
109 }
110 CPAN->debug(sprintf("after delete_first mod[%s] All[%s]",
111 $what,
112 0 ▶ join("",map {sprintf " %s\[%s][%s]\n",$_->{qmod},$_->{reqtype},$_->{optional}} @All)
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 5 5
if $CPAN::DEBUG 0 0 0
113 )) if $CPAN::DEBUG;
114 }
115  
116 # CPAN::Queue::jumpqueue ;
117 0 ▶sub jumpqueue {
Subroutine jumpqueue: not called CC=11 SCAR=48.8
Pod undocumented
118 0 ▶ my $class = shift;
Subroutine jumpqueue: not called CC=11 SCAR=48.8
Pod undocumented
119 0 my @what = @_;
120 CPAN->debug(sprintf("before jumpqueue All[%s] what[%s]",
121 0 join("",map {sprintf " %s\[%s][%s]\n",$_->{qmod},$_->{reqtype},$_->{optional}} @All),
122 0 ▶ join("",map {sprintf " %s\[%s][%s]\n",$_->{qmod},$_->{reqtype},$_->{optional}} @what),
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
123 )) if $CPAN::DEBUG;
124 0 ▶ unless (defined $what[0]{reqtype}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $what[0]{"reqtype"}) 0 0 0
unless (defined $what[0]{"reqtype"}) 0 0 0
125 # apparently it was not the Shell that sent us this enquiry,
126 # treat it as commandline
127 0 $what[0]{reqtype} = "c";
128 }
129 0 ▶ my $inherit_reqtype = $what[0]{reqtype} =~ /^(c|r)$/ ? "r" : "b";
Branch: 2 branches
BranchTrueFalseTotal
$what[0]{'reqtype'} =~ /^(c|r)$/ ? : 0 0 0
$what[0]{'reqtype'} =~ /^(c|r)$/ ? : 0 0 0
130 0 WHAT: for my $what_tuple (@what) {
131 0 my($qmod,$reqtype,$optional) = @$what_tuple{qw(qmod reqtype optional)};
132 0 ▶ if ($reqtype eq "r"
Branch: 2 branches
BranchTrueFalseTotal
if ($reqtype eq "r" and $inherit_reqtype eq "b") 0 0 0
if ($reqtype eq "r" and $inherit_reqtype eq "b") 0 0 0
Condition0%0/6
$reqtype eq "r" and $inherit_reqtype eq "b"
!ll&&!rl&&r
000
$reqtype eq "r" and $inherit_reqtype eq "b"
!ll&&!rl&&r
000
MC/DC0%0/2
$reqtype eq "r" and $inherit_reqtype eq "b"
$reqtype eq "r" $inherit_reqtype eq "b"
MC/DC0%0/2
$reqtype eq "r" and $inherit_reqtype eq "b"
$reqtype eq "r" $inherit_reqtype eq "b"
Truth table0%0/3
A and B
A= $reqtype eq "r"B= $inherit_reqtype eq "b"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $reqtype eq "r"B= $inherit_reqtype eq "b"
ABresult
0X0
100
111
133 &&
134 $inherit_reqtype eq "b"
135 ) {
136 0 $reqtype = "b";
137 }
138 0 my $jumped = 0;
139 0 ▶ for (my $i=0; $i<$#All;$i++) { #prevent deep recursion
Branch: 2 branches
BranchTrueFalseTotal
if ($i < $#CPAN::Queue::All) 0 0 0
if ($i < $#CPAN::Queue::All) 0 0 0
140 0 ▶ if ($All[$i]{qmod} eq $qmod) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::Queue::All[$i]{"qmod"} eq $qmod) 0 0 0
if ($CPAN::Queue::All[$i]{"qmod"} eq $qmod) 0 0 0
141 0 $jumped++;
142 }
143 }
144 # high jumped values are normal for popular modules when
145 # dealing with large bundles: XML::Simple,
146 # namespace::autoclean, UNIVERSAL::require
147 0 ▶ CPAN->debug("qmod[$qmod]jumped[$jumped]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
148 0 my $obj = "$class\::Item"->new(
149 qmod => $qmod,
150 reqtype => $reqtype,
151 optional => !! $optional,
152 );
153 0 unshift @All, $obj;
154 }
155 CPAN->debug(sprintf("after jumpqueue All[%s]",
156 0 ▶ join("",map {sprintf " %s\[%s][%s]\n",$_->{qmod},$_->{reqtype},$_->{optional}} @All)
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
157 )) if $CPAN::DEBUG;
158 }
159  
160 # CPAN::Queue::exists ;
161 0 ▶sub exists {
Subroutine exists: not called CC=1 SCAR=6.9
Pod undocumented
162 0 ▶ my($self,$what) = @_;
Subroutine exists: not called CC=1 SCAR=6.9
Pod undocumented
163 0 my @all = map { $_->{qmod} } @All;
164 0 my $exists = grep { $_->{qmod} eq $what } @All;
165 # warn "in exists what[$what] all[@all] exists[$exists]";
166 0 $exists;
167 }
168  
169 # CPAN::Queue::delete ;
170 1 ▶sub delete {
Subroutine delete: called CC=2 SCAR=11.2
Pod undocumented
171 0 ▶ my($self,$mod) = @_;
Subroutine delete: not called CC=2 SCAR=11.2
Pod undocumented
172 0 @All = grep { $_->{qmod} ne $mod } @All;
173 CPAN->debug(sprintf("after delete mod[%s] All[%s]",
174 $mod,
175 0 ▶ join("",map {sprintf " %s\[%s][%s]\n",$_->{qmod},$_->{reqtype},$_->{optional}} @All)
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 1 1
if $CPAN::DEBUG 0 0 0
176 )) if $CPAN::DEBUG;
177 }
178  
179 # CPAN::Queue::nullify_queue ;
180 0 ▶sub nullify_queue {
Subroutine nullify_queue: not called CC=1 SCAR=6.9
Pod undocumented
181 0 ▶ @All = ();
Subroutine nullify_queue: not called CC=1 SCAR=6.9
Pod undocumented
182 }
183  
184 # CPAN::Queue::size ;
185 0 ▶sub size {
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
186 0 ▶ return scalar @All;
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
187 }
188  
189 0 ▶sub reqtype_of {
Subroutine reqtype_of: not called CC=6 SCAR=37.4
Pod undocumented
190 0 ▶ my($self,$mod) = @_;
Subroutine reqtype_of: not called CC=6 SCAR=37.4
Pod undocumented
191 0 my $best = "";
192 0 for my $item (grep { $_->{qmod} eq $mod } @All) {
193 0 my $c = $item->{reqtype};
194 0 ▶ if ($c eq "c") {
Branch: 6 branches
BranchTrueFalseTotal
if ($c eq 'c') { } 0 0 0
elsif ($c eq 'r') { } 0 0 0
elsif ($c eq 'b') { } 0 0 0
if ($c eq 'c') { } 0 0 0
elsif ($c eq 'r') { } 0 0 0
elsif ($c eq 'b') { } 0 0 0
195 0 $best = $c;
196 0 last;
197 } elsif ($c eq "r") {
198 0 $best = $c;
199 } elsif ($c eq "b") {
200 0 ▶ if ($best eq "") {
Branch: 2 branches
BranchTrueFalseTotal
if ($best eq "") 0 0 0
if ($best eq "") 0 0 0
201 0 $best = $c;
202 }
203 } else {
204 0 die "Panic: in reqtype_of: reqtype[$c] seen, should never happen";
205 }
206 }
207 0 return $best;
208 }
209  
210 0 ▶sub iterator {
Subroutine iterator: not called CC=1 SCAR=6.9
Pod undocumented
211 0 ▶ my $i = 0;
Subroutine iterator: not called CC=1 SCAR=6.9
Pod undocumented
212 0 ▶ return sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
213 0 ▶ until ($All[$i] || $i > $#All) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 2 branches
BranchTrueFalseTotal
unless ($CPAN::Queue::All[$i] or $i > $#CPAN::Queue::All) 0 0 0
unless ($CPAN::Queue::All[$i] or $i > $#CPAN::Queue::All) 0 0 0
Condition0%0/6
$CPAN::Queue::All[$i] or $i > $#CPAN::Queue::All
l!l&&r!l&&!r
000
$CPAN::Queue::All[$i] or $i > $#CPAN::Queue::All
l!l&&r!l&&!r
000
MC/DC0%0/2
$CPAN::Queue::All[$i] or $i > $#CPAN::Queue::All
$CPAN::Queue::All[$i] $i > $#CPAN::Queue::All
MC/DC0%0/2
$CPAN::Queue::All[$i] or $i > $#CPAN::Queue::All
$CPAN::Queue::All[$i] $i > $#CPAN::Queue::All
Truth table0%0/3
A or B
A= $CPAN::Queue::All[$i]B= $i > $#CPAN::Queue::All
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $CPAN::Queue::All[$i]B= $i > $#CPAN::Queue::All
ABresult
1X1
011
000
214 0 $i++;
215 }
216 0 ▶ return if $i > $#All;
Branch: 2 branches
BranchTrueFalseTotal
if $i > $#CPAN::Queue::All 0 0 0
if $i > $#CPAN::Queue::All 0 0 0
217 0 return $All[$i++]
218 0 };
219 }
220  
221 26 1;
222  
223 __END__
« blib/lib/CPAN/FTP/netrc.pm ↑ Summary blib/lib/CPAN/HTTP/Client.pm »