1 # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2 # vim: ts=4 sts=4 sw=4:
3 package CPAN::Exception::RecursiveDependency;
5 use overload '""' => "as_string";
12 # a module sees its distribution (no version)
13 # a distribution sees its prereqs (which are module names) (usually with versions)
14 # a bundle sees its module names and/or its distributions (no version)
18 my($deps_arg) = shift;
19 my (@deps,%seen,$loop_starts_with);
20 DCHAIN: for my $dep (@$deps_arg) {
21 push @deps, {name => $dep, display_as => $dep};
23 $loop_starts_with = $dep;
28 for my $i (0..$#deps) {
29 my $x = $deps[$i]{name};
30 $in_loop ||= $loop_starts_with && $x eq $loop_starts_with;
31 my $xo = CPAN::Shell->expandany($x) or next;
32 if ($xo->isa("CPAN::Module")) {
33 my $have = $xo->inst_version || "N/A";
34 my($want,$d,$want_type);
35 if ($i>0 and $d = $deps[$i-1]{name}) {
36 my $do = CPAN::Shell->expandany($d);
37 $want = $do->{prereq_pm}{requires}{$x};
39 $want_type = "requires: ";
41 $want = $do->{prereq_pm}{build_requires}{$x};
43 $want_type = "build_requires: ";
45 $want_type = "unknown status";
50 $want = $xo->cpan_version;
51 $want_type = "want: ";
53 $deps[$i]{have} = $have;
54 $deps[$i]{want_type} = $want_type;
55 $deps[$i]{want} = $want;
56 $deps[$i]{display_as} = "$x (have: $have; $want_type$want)";
57 } elsif ($xo->isa("CPAN::Distribution")) {
58 $deps[$i]{display_as} = $xo->pretty_id;
60 $xo->{make} = CPAN::Distrostatus->new("NO cannot resolve circular dependency");
62 $xo->{make} = CPAN::Distrostatus->new("NO one dependency ($loop_starts_with) is a circular dependency");
64 $xo->store_persistent_state; # otherwise I will not reach
65 # all involved parties for
69 bless { deps => \@deps, loop_starts_with => $loop_starts_with }, $class;
74 my $deps = $self->{deps};
75 my $loop_starts_with = $self->{loop_starts_with};
76 unless ($loop_starts_with) {
77 return "--not a recursive/circular dependency--";
79 my $ret = "\nRecursive dependency detected:\n ";
80 $ret .= join("\n => ", map {$_->{display_as}} @$deps);
81 $ret .= ".\nCannot resolve.\n";