| 1 | # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*- | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # vim: ts=4 sts=4 sw=4: | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package CPAN::Exception::RecursiveDependency; | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use overload '""' => "as_string"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 24 | use vars qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | $VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 24 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 24 | $VERSION = "5.5001"; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package CPAN::Exception::RecursiveDependency::na; | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 24 | ▶ | use overload '""' => "as_string"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 24 | ▶ | sub new { bless {}, shift }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub as_string { "N/A" }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 24 | my $NA = CPAN::Exception::RecursiveDependency::na->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # a module sees its distribution (no version) | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # a distribution sees its prereqs (which are module names) (usually with versions) | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # a bundle sees its module names and/or its distributions (no version) | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | my($class) = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=20 SCAR=49.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my($deps_arg) = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | my (@deps,%seen,$loop_starts_with); | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | DCHAIN: for my $dep (@$deps_arg) { | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | push @deps, {name => $dep, display_as => $dep}; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | ▶ | if ($seen{$dep}++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $loop_starts_with = $dep; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | last DCHAIN; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | my $in_loop = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | my %mark; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | DWALK: for my $i (0..$#deps) { | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | my $x = $deps[$i]{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | ▶ | $in_loop ||= $loop_starts_with && $x eq $loop_starts_with; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$in_loop ||= $loop_starts_with && $x eq $loop_starts_with
$loop_starts_with && $x eq $loop_starts_with
MC/DC0%0/3
$in_loop ||= $loop_starts_with && $x eq $loop_starts_with
$in_loop
$loop_starts_with
$x eq $loop_starts_with
Truth table0%0/4
A ||= B && C
A= $in_loopB= $loop_starts_withC= $x eq $loop_starts_with
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | my $xo = CPAN::Shell->expandany($x) or next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($xo->isa("CPAN::Module")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $have = $xo->inst_version || $NA; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$xo->inst_version || $NA
MC/DC0%0/2
$xo->inst_version || $NA
$xo->inst_version
$NA
Truth table0%0/3
A || B
A= $xo->inst_versionB= $NA
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my($want,$d,$want_type); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ($i>0 and $d = $deps[$i-1]{name}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i > 0 and $d = $deps[$i - 1]{"name"}
MC/DC0%0/2
$i > 0 and $d = $deps[$i - 1]{"name"}
$i > 0
$d = $deps[$i - 1]{"name"}
Truth table0%0/3
A and B
A= $i > 0B= $d = $deps[$i - 1]{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $do = CPAN::Shell->expandany($d); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $want = $do->{prereq_pm}{requires}{$x}; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (defined $want) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $want_type = "requires: "; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $want = $do->{prereq_pm}{build_requires}{$x}; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (defined $want) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $want_type = "build_requires: "; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $want_type = "unknown status"; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $want = "???"; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $want = $xo->cpan_version; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $want_type = "want: "; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $deps[$i]{have} = $have; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $deps[$i]{want_type} = $want_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $deps[$i]{want} = $want; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $deps[$i]{display_as} = "$x (have: $have; $want_type$want)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ((! ref $have || !$have->isa('CPAN::Exception::RecursiveDependency::na')) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not ref $have && $have->isa("CPAN::Exception::RecursiveDependency::na") and "CPAN::Version"->vge($have, $want)
ref $have && $have->isa('CPAN::Exception::RecursiveDependency::na')
MC/DC0%0/3
not ref $have && $have->isa("CPAN::Exception::RecursiveDependency::na") and "CPAN::Version"->vge($have, $want)
ref $have
$have->isa('CPAN::Exception::RecursiveDependency::na')
"CPAN::Version"->vge($have, $want)
Truth table0%0/5
not(A && B) and C
A= ref $haveB= $have->isa('CPAN::Exception::RecursiveDependency::na')C= "CPAN::Version"->vge($have, $want)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | && CPAN::Version->vge($have, $want)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # https://rt.cpan.org/Ticket/Display.html?id=115340 | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | undef $loop_starts_with; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | last DWALK; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } elsif ($xo->isa("CPAN::Distribution")) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $pretty = $deps[$i]{display_as} = $xo->pretty_id; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $mark_as; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($in_loop) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $mark_as = CPAN::Distrostatus->new("NO cannot resolve circular dependency"); | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $mark_as = CPAN::Distrostatus->new("NO one dependency ($loop_starts_with) is a circular dependency"); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $mark{$pretty} = { xo => $xo, mark_as => $mark_as }; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | ▶ | if ($loop_starts_with) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | while (my($k,$v) = each %mark) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $xo = $v->{xo}; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $xo->{make} = $v->{mark_as}; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $xo->store_persistent_state; # otherwise I will not reach | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | # all involved parties for | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # the next session | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | bless { deps => \@deps, loop_starts_with => $loop_starts_with }, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | sub is_resolvable { | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | ! defined shift->{loop_starts_with}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_resolvable: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | my($self) = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my $deps = $self->{deps}; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | my $loop_starts_with = $self->{loop_starts_with}; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | unless ($loop_starts_with) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | return "--not a recursive/circular dependency--"; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | my $ret = "\nRecursive dependency detected:\n "; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | $ret .= join("\n => ", map {$_->{display_as}} @$deps); | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | $ret .= ".\nCannot resolve.\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||||||