blib/lib/Perl/Repository/APC/BAP.pm

filter: Statementstmt 13.7% 12 / 87 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 50.0% 3 / 6 Podpod 33.3% 1 / 3 totaltotal 7.8% 16 / 203 CC 41 SCAR 67.0
CC
41
Cov
7%
translate
1122.0
neighbors
56.0
new
12.0
CRAP 814.3
↑ Summary scripts/binsearchaperl »
1 package Perl::Repository::APC::BAP;
2 5 ▶use Perl::Repository::APC;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 my $Id = q$Id: BAP.pm 294 2008-02-22 10:42:30Z k $;
8 5 our $VERSION = sprintf "%.3f", 1 + substr(q$Rev: 294 $,4)/1000;
9  
10 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
11 0 ▶ unless (@_ == 2){
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ == 2) 0 0 0
12 0 require Carp;
13 0 Carp::croak(sprintf "Not enough arguments for %s -> new ()\n", __PACKAGE__);
14 }
15 0 my $proto = shift;
16 0 ▶ my $class = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
17  
18 0 my $apc = shift;
19 0 my $self;
20  
21 0 $self->{APC} = $apc;
22  
23 0 bless $self => $class;
24 }
25  
26 0 ▶sub translate {
Subroutine translate: not called CC=33 SCAR=70.2
Pod documented
27 0 my($self,$branch,$baseperl,$patchlevel) = @_;
28 0 ▶ die sprintf "%s -> translate called without a branch argument", __PACKAGE__
Branch: 1 branch
BranchTrueFalseTotal
unless $branch 0 0 0
29 unless $branch;
30 0 my($prev, $nextperl, @patches, @ver);
31 0 my $apc = $self->{APC};
32 0 ▶ if ($branch eq "perl") {
Branch: 2 branches
BranchTrueFalseTotal
if ($branch eq 'perl') { } 0 0 0
elsif (my($bv) = $branch =~ /^maint-(.*)/) { } 0 0 0
33 0 $prev = "0";
34 } elsif (my($bv) = $branch =~ /^maint-(.*)/) {
35 # maintainance nightmare: we currently (rev 123) have no access to
36 # any metadata that tell us the perl we need
37 0 ▶ if ($bv eq "5.004") {
Branch: 2 branches
BranchTrueFalseTotal
if ($bv eq '5.004') { } 0 0 0
elsif ($branch =~ m[/]) { } 0 0 0
38 0 $prev = "0";
39 } elsif ($branch =~ /\//) { # currently only "maint-5.6/perl-5.6.2"
40 0 ▶ if ($branch eq "maint-5.6/perl-5.6.2") {
Branch: 1 branch
BranchTrueFalseTotal
if ($branch eq 'maint-5.6/perl-5.6.2') { } 0 0 0
41 0 $prev = "5.6.1";
42 } else {
43 0 die "Illegal value for branch[$branch]"; # carp doesn't make it better
44 }
45 } else {
46 0 $prev = "$bv.0"; # 5.6 -> 5.6.0 etc.
47 }
48 }
49 0 @ver = $prev;
50 0 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($next) 0 0 0
51 my $next = $apc->first_in_branch($branch);
52 $next;
53 $next = $apc->next_in_branch($next)
54 ) {
55 0 $nextperl = $next;
56 0 @patches = @{$apc->patches($next)};
57 0 push @ver, $next;
58 0 ▶ if ($patchlevel && $patchlevel >= $patches[0] && $patchlevel <= $patches[-1]){
Branch: 2 branches
BranchTrueFalseTotal
if ($patchlevel and $patchlevel >= $patches[0] and $patchlevel <= $patches[-1]) { } 0 0 0
elsif (defined $baseperl and length $baseperl) { } 0 0 0
Condition0%0/6
$patchlevel and $patchlevel >= $patches[0] and $patchlevel <= $patches[-1]
!ll&&!rl&&r
000
$patchlevel and $patchlevel >= $patches[0]
!ll&&!rl&&r
000
MC/DC0%0/3
$patchlevel and $patchlevel >= $patches[0] and $patchlevel <= $patches[-1]
$patchlevel $patchlevel >= $patches[0] $patchlevel <= $patches[-1]
Truth table0%0/4
A and B and C
A= $patchlevelB= $patchlevel >= $patches[0]C= $patchlevel <= $patches[-1]
ABCresult
0XX0
10X0
1100
1111
59 0 ▶ if (defined $baseperl && length $baseperl &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $baseperl and length $baseperl and grep {$_ eq $baseperl;} @ver) 0 0 0
Condition0%0/6
defined $baseperl and length $baseperl and grep {$_ eq $baseperl;} @ver
!ll&&!rl&&r
000
defined $baseperl and length $baseperl
!ll&&!rl&&r
000
MC/DC0%0/3
defined $baseperl and length $baseperl and grep {$_ eq $baseperl;} @ver
defined $baseperl length $baseperl grep {$_ eq $baseperl;} @ver
Truth table0%0/4
A and B and C
A= defined $baseperlB= length $baseperlC= grep {$_ eq $baseperl;} @ver
ABCresult
0XX0
10X0
1100
1111
60 0 grep { $_ eq $baseperl } @ver) {
61 0 ▶ unless ($prev eq $baseperl){
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev eq $baseperl) 0 0 0
62 0 die "Fatal error: patch $patchlevel is outside the patchset based on $baseperl\n";
63 }
64 }
65 0 last;
66 ▶ } elsif (defined $baseperl && length($baseperl)) {
Condition0%0/3
defined $baseperl and length $baseperl
!ll&&!rl&&r
000
MC/DC0%0/2
defined $baseperl and length $baseperl
defined $baseperl length $baseperl
Truth table0%0/3
A and B
A= defined $baseperlB= length $baseperl
ABresult
0X0
100
111
67 0 ▶ if ($baseperl eq "0") {
Branch: 1 branch
BranchTrueFalseTotal
if ($baseperl eq '0') { } 0 0 0
68 0 ▶ if ($ver[0] eq "0") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ver[0] eq '0') { } 0 0 0
69 0 last;
70 } else {
71 0 die "Fatal error: 0 is not starting point for branch $branch\n";
72 }
73 } else {
74 0 ▶ last if $prev && $baseperl eq $prev || @ver>1 && $baseperl eq $ver[-2];
Branch: 1 branch
BranchTrueFalseTotal
if $prev and $baseperl eq $prev or @ver > 1 and $baseperl eq $ver[-2] 0 0 0
Condition0%0/9
$prev and $baseperl eq $prev or @ver > 1 and $baseperl eq $ver[-2]
l!l&&r!l&&!r
000
$prev and $baseperl eq $prev
!ll&&!rl&&r
000
@ver > 1 and $baseperl eq $ver[-2]
!ll&&!rl&&r
000
MC/DC0%0/4
$prev and $baseperl eq $prev or @ver > 1 and $baseperl eq $ver[-2]
$prev $baseperl eq $prev @ver > 1 $baseperl eq $ver[-2]
Truth table0%0/7
A and B or C and D
A= $prevB= $baseperl eq $prevC= @ver > 1D= $baseperl eq $ver[-2]
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
75 }
76 }
77 0 $prev = $next;
78 }
79 0 ▶ if (defined $baseperl && length $baseperl) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $baseperl and length $baseperl) { } 0 0 0
Condition0%0/3
defined $baseperl and length $baseperl
!ll&&!rl&&r
000
MC/DC0%0/2
defined $baseperl and length $baseperl
defined $baseperl length $baseperl
Truth table0%0/3
A and B
A= defined $baseperlB= length $baseperl
ABresult
0X0
100
111
80 0 ▶ if ($baseperl eq "0") {
Branch: 1 branch
BranchTrueFalseTotal
if ($baseperl eq '0') { } 0 0 0
81 # always OK?
82 } else {
83 0 ▶ unless (grep { $_ eq $baseperl } @ver){
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $baseperl;} @ver) 0 0 0
84 0 die "Fatal error: $baseperl is not part of branch $branch";
85 }
86 }
87 } else {
88 0 ▶ if (@ver > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@ver > 1) { } 0 0 0
elsif (@ver == 1) { } 0 0 0
89 0 $baseperl = $ver[-2];
90 } elsif (@ver == 1) {
91 0 $baseperl = $ver[0];
92 0 $baseperl =~ s/1$/0/;
93 } else {
94 0 die "Could not determine base perl version";
95 }
96 }
97 0 ▶ if ($patchlevel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($patchlevel) { } 0 0 0
98 0 ▶ unless (grep { $_ eq $patchlevel } @patches){
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $patchlevel;} @patches) 0 0 0
99 0 my @neighbors = $self->neighbors($patchlevel,\@patches);
100 0 my $tellmore;
101 0 ▶ if (@neighbors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@neighbors) { } 0 0 0
102 0 ▶ if (@neighbors == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@neighbors == 1) { } 0 0 0
103 0 $tellmore = "$neighbors[0] would be";
104 } else {
105 0 $tellmore = "$neighbors[0] or $neighbors[1] would be";
106 }
107 } else {
108 0 $tellmore = "Range is from $patches[0] to $patches[-1]";
109 }
110 0 die "Fatal error: patch $patchlevel is not part of the patchset for $baseperl
111 ($tellmore)\n";
112 }
113 } else {
114 0 $patchlevel = $patches[-1];
115 }
116 0 my $firstpatch = $patches[0];
117 0 my $dir = $apc->get_diff_dir($branch,$patchlevel);
118 0 return ($baseperl, $nextperl, $firstpatch, $patchlevel, $dir);
119 }
120  
121 0 ▶sub neighbors {
Subroutine neighbors: not called CC=7 SCAR=40.3
Pod undocumented
122 0 my($self,$x,$arr) = @_;
123 0 ▶ return if $x < $arr->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $x < $arr->[0] 0 0 0
124 0 ▶ return if $x > $arr->[-1];
Branch: 1 branch
BranchTrueFalseTotal
if $x > $arr->[-1] 0 0 0
125 0 my @res;
126 0 for my $i (0..$#$arr) {
127 0 ▶ if ($arr->[$i] < $x) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arr->[$i] < $x) { } 0 0 0
elsif ($arr->[$i] > $x) { } 0 0 0
128 0 $res[0] = $arr->[$i];
129 } elsif ($arr->[$i] > $x) {
130 0 ▶ $res[1] ||= $arr->[$i];
Condition0%0/3
$res[1] ||= $arr->[$i]
l!l&&r!l&&!r
000
MC/DC0%0/2
$res[1] ||= $arr->[$i]
$res[1] $arr->[$i]
Truth table0%0/3
A ||= B
A= $res[1]B= $arr->[$i]
ABresult
1X1
011
000
131 0 last;
132 } else {
133 # must not happen
134 0 die "Panic: neighbors called with matching element";
135 }
136 }
137 0 @res;
138 }
139  
140 5 1;
141  
142 __END__
↑ Summary scripts/binsearchaperl »