<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
# vim: ts=4 sts=4 sw=4:
package CPAN::Distribution;
use strict;
use Cwd qw(chdir);
use CPAN::Distroprefs;
use CPAN::InfoObj;
use File::Path ();
@CPAN::Distribution::ISA = qw(CPAN::InfoObj);
use vars qw($VERSION);
$VERSION = "2.22";

# no prepare, because prepare is not a command on the shell command line
# TODO: clear instance cache on reload
my %instance;
for my $method (qw(get make test install)) {
    no strict 'refs';
    for my $prefix (qw(pre post)) {
        my $hookname = sprintf "%s_%s", $prefix, $method;
        *$hookname = sub {
            my($self) = @_;
            for my $plugin (@{$CPAN::Config-&gt;{plugin_list}}) {
                my($plugin_proper,$args) = split /=/, $plugin, 2;
                $args = "" unless defined $args;
                if ($CPAN::META-&gt;has_inst($plugin_proper)){
                    my @args = split /,/, $args;
                    $instance{$plugin} ||= $plugin_proper-&gt;new(@args);
                    if ($instance{$plugin}-&gt;can($hookname)) {
                        $instance{$plugin}-&gt;$hookname($self);
                    }
                } else {
                    $CPAN::Frontend-&gt;mydie("Plugin '$plugin_proper' not found for hook '$hookname'");
                }
            }
        };
    }
}

# Accessors
sub cpan_comment {
    my $self = shift;
    my $ro = $self-&gt;ro or return;
    $ro-&gt;{CPAN_COMMENT}
}

#-&gt; CPAN::Distribution::undelay
sub undelay {
    my $self = shift;
    for my $delayer (
                     "configure_requires_later",
                     "configure_requires_later_for",
                     "later",
                     "later_for",
                    ) {
        delete $self-&gt;{$delayer};
    }
}

#-&gt; CPAN::Distribution::is_dot_dist
sub is_dot_dist {
    my($self) = @_;
    return substr($self-&gt;id,-1,1) eq ".";
}

# add the A/AN/ stuff
#-&gt; CPAN::Distribution::normalize
sub normalize {
    my($self,$s) = @_;
    $s = $self-&gt;id unless defined $s;
    if (substr($s,-1,1) eq ".") {
        # using a global because we are sometimes called as static method
        if (!$CPAN::META-&gt;{LOCK}
            &amp;&amp; !$CPAN::Have_warned-&gt;{"$s is unlocked"}++
           ) {
            $CPAN::Frontend-&gt;mywarn("You are visiting the local directory
  '$s'
  without lock, take care that concurrent processes do not do likewise.\n");
            $CPAN::Frontend-&gt;mysleep(1);
        }
        if ($s eq ".") {
            $s = "$CPAN::iCwd/.";
        } elsif (File::Spec-&gt;file_name_is_absolute($s)) {
        } elsif (File::Spec-&gt;can("rel2abs")) {
            $s = File::Spec-&gt;rel2abs($s);
        } else {
            $CPAN::Frontend-&gt;mydie("Your File::Spec is too old, please upgrade File::Spec");
        }
        CPAN-&gt;debug("s[$s]") if $CPAN::DEBUG;
        unless ($CPAN::META-&gt;exists("CPAN::Distribution", $s)) {
            for ($CPAN::META-&gt;instance("CPAN::Distribution", $s)) {
                $_-&gt;{build_dir} = $s;
                $_-&gt;{archived} = "local_directory";
                $_-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("YES -- local_directory");
            }
        }
    } elsif (
        $s =~ tr|/|| == 1
        or
        $s !~ m|[A-Z]/[A-Z-0-9]{2}/[A-Z-0-9]{2,}/|
       ) {
        return $s if $s =~ m:^N/A|^Contact Author: ;
        $s =~ s|^(.)(.)([^/]*/)(.+)$|$1/$1$2/$1$2$3$4|;
        CPAN-&gt;debug("s[$s]") if $CPAN::DEBUG;
    }
    $s;
}

#-&gt; sub CPAN::Distribution::author ;
sub author {
    my($self) = @_;
    my($authorid);
    if (substr($self-&gt;id,-1,1) eq ".") {
        $authorid = "LOCAL";
    } else {
        ($authorid) = $self-&gt;pretty_id =~ /^([\w\-]+)/;
    }
    CPAN::Shell-&gt;expand("Author",$authorid);
}

# tries to get the yaml from CPAN instead of the distro itself:
# EXPERIMENTAL, UNDOCUMENTED AND UNTESTED, for Tels
sub fast_yaml {
    my($self) = @_;
    my $meta = $self-&gt;pretty_id;
    $meta =~ s/\.(tar.gz|tgz|zip|tar.bz2)/.meta/;
    my(@ls) = CPAN::Shell-&gt;globls($meta);
    my $norm = $self-&gt;normalize($meta);

    my($local_file);
    my($local_wanted) =
        File::Spec-&gt;catfile(
                            $CPAN::Config-&gt;{keep_source_where},
                            "authors",
                            "id",
                            split(/\//,$norm)
                           );
    $self-&gt;debug("Doing localize") if $CPAN::DEBUG;
    unless ($local_file =
            CPAN::FTP-&gt;localize("authors/id/$norm",
                                $local_wanted)) {
        $CPAN::Frontend-&gt;mydie("Giving up on downloading yaml file '$local_wanted'\n");
    }
    my $yaml = CPAN-&gt;_yaml_loadfile($local_file)-&gt;[0];
}

#-&gt; sub CPAN::Distribution::cpan_userid
sub cpan_userid {
    my $self = shift;
    if ($self-&gt;{ID} =~ m{[A-Z]/[A-Z\-]{2}/([A-Z\-]+)/}) {
        return $1;
    }
    return $self-&gt;SUPER::cpan_userid;
}

#-&gt; sub CPAN::Distribution::pretty_id
sub pretty_id {
    my $self = shift;
    my $id = $self-&gt;id;
    return $id unless $id =~ m|^./../|;
    substr($id,5);
}

#-&gt; sub CPAN::Distribution::base_id
sub base_id {
    my $self = shift;
    my $id = $self-&gt;pretty_id();
    my $base_id = File::Basename::basename($id);
    $base_id =~ s{\.(?:tar\.(bz2|gz|Z)|t(?:gz|bz)|zip)$}{}i;
    return $base_id;
}

#-&gt; sub CPAN::Distribution::tested_ok_but_not_installed
sub tested_ok_but_not_installed {
    my $self = shift;
    return (
           $self-&gt;{make_test}
        &amp;&amp; $self-&gt;{build_dir}
        &amp;&amp; (UNIVERSAL::can($self-&gt;{make_test},"failed") ?
             ! $self-&gt;{make_test}-&gt;failed :
             $self-&gt;{make_test} =~ /^YES/
            )
        &amp;&amp; (
            !$self-&gt;{install}
            ||
            $self-&gt;{install}-&gt;failed
           )
    );
}


# mark as dirty/clean for the sake of recursion detection. $color=1
# means "in use", $color=0 means "not in use anymore". $color=2 means
# we have determined prereqs now and thus insist on passing this
# through (at least) once again.

#-&gt; sub CPAN::Distribution::color_cmd_tmps ;
sub color_cmd_tmps {
    my($self) = shift;
    my($depth) = shift || 0;
    my($color) = shift || 0;
    my($ancestors) = shift || [];
    # a distribution needs to recurse into its prereq_pms
    $self-&gt;debug("color_cmd_tmps[$depth,$color,@$ancestors]") if $CPAN::DEBUG;

    return if exists $self-&gt;{incommandcolor}
        &amp;&amp; $color==1
        &amp;&amp; $self-&gt;{incommandcolor}==$color;
    $CPAN::MAX_RECURSION||=0; # silence 'once' warnings
    if ($depth&gt;=$CPAN::MAX_RECURSION) {
        my $e = CPAN::Exception::RecursiveDependency-&gt;new($ancestors);
        if ($e-&gt;is_resolvable) {
            return $self-&gt;{incommandcolor}=2;
        } else {
            die $e;
        }
    }
    # warn "color_cmd_tmps $depth $color " . $self-&gt;id; # sleep 1;
    my $prereq_pm = $self-&gt;prereq_pm;
    if (defined $prereq_pm) {
        # XXX also optional_req &amp; optional_breq? -- xdg, 2012-04-01
        # A: no, optional deps may recurse -- ak, 2014-05-07
      PREREQ: for my $pre (sort(
                keys %{$prereq_pm-&gt;{requires}||{}},
                keys %{$prereq_pm-&gt;{build_requires}||{}},
            )) {
            next PREREQ if $pre eq "perl";
            my $premo;
            unless ($premo = CPAN::Shell-&gt;expand("Module",$pre)) {
                $CPAN::Frontend-&gt;mywarn("prerequisite module[$pre] not known\n");
                $CPAN::Frontend-&gt;mysleep(0.2);
                next PREREQ;
            }
            $premo-&gt;color_cmd_tmps($depth+1,$color,[@$ancestors, $self-&gt;id]);
        }
    }
    if ($color==0) {
        delete $self-&gt;{sponsored_mods};

        # as we are at the end of a command, we'll give up this
        # reminder of a broken test. Other commands may test this guy
        # again. Maybe 'badtestcnt' should be renamed to
        # 'make_test_failed_within_command'?
        delete $self-&gt;{badtestcnt};
    }
    $self-&gt;{incommandcolor} = $color;
}

#-&gt; sub CPAN::Distribution::as_string ;
sub as_string {
    my $self = shift;
    $self-&gt;containsmods;
    $self-&gt;upload_date;
    $self-&gt;SUPER::as_string(@_);
}

#-&gt; sub CPAN::Distribution::containsmods ;
sub containsmods {
    my $self = shift;
    return sort keys %{$self-&gt;{CONTAINSMODS}} if exists $self-&gt;{CONTAINSMODS};
    my $dist_id = $self-&gt;{ID};
    for my $mod ($CPAN::META-&gt;all_objects("CPAN::Module")) {
        my $mod_file = $mod-&gt;cpan_file or next;
        my $mod_id = $mod-&gt;{ID} or next;
        # warn "mod_file[$mod_file] dist_id[$dist_id] mod_id[$mod_id]";
        # sleep 1;
        if ($CPAN::Signal) {
            delete $self-&gt;{CONTAINSMODS};
            return;
        }
        $self-&gt;{CONTAINSMODS}{$mod_id} = undef if $mod_file eq $dist_id;
    }
    sort keys %{$self-&gt;{CONTAINSMODS}||={}};
}

#-&gt; sub CPAN::Distribution::upload_date ;
sub upload_date {
    my $self = shift;
    return $self-&gt;{UPLOAD_DATE} if exists $self-&gt;{UPLOAD_DATE};
    my(@local_wanted) = split(/\//,$self-&gt;id);
    my $filename = pop @local_wanted;
    push @local_wanted, "CHECKSUMS";
    my $author = CPAN::Shell-&gt;expand("Author",$self-&gt;cpan_userid);
    return unless $author;
    my @dl = $author-&gt;dir_listing(\@local_wanted,0,$CPAN::Config-&gt;{show_upload_date});
    return unless @dl;
    my($dirent) = grep { $_-&gt;[2] eq $filename } @dl;
    # warn sprintf "dirent[%s]id[%s]", $dirent, $self-&gt;id;
    return unless $dirent-&gt;[1];
    return $self-&gt;{UPLOAD_DATE} = $dirent-&gt;[1];
}

#-&gt; sub CPAN::Distribution::uptodate ;
sub uptodate {
    my($self) = @_;
    my $c;
    foreach $c ($self-&gt;containsmods) {
        my $obj = CPAN::Shell-&gt;expandany($c);
        unless ($obj-&gt;uptodate) {
            my $id = $self-&gt;pretty_id;
            $self-&gt;debug("$id not uptodate due to $c") if $CPAN::DEBUG;
            return 0;
        }
    }
    return 1;
}

#-&gt; sub CPAN::Distribution::called_for ;
sub called_for {
    my($self,$id) = @_;
    $self-&gt;{CALLED_FOR} = $id if defined $id;
    return $self-&gt;{CALLED_FOR};
}

#-&gt; sub CPAN::Distribution::shortcut_get ;
# return values: undef means don't shortcut; 0 means shortcut as fail;
# and 1 means shortcut as success
sub shortcut_get {
    my ($self) = @_;

    if (my $why = $self-&gt;check_disabled) {
        $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO $why");
        # XXX why is this goodbye() instead of just print/warn?
        # Alternatively, should other print/warns here be goodbye()?
        # -- xdg, 2012-04-05
        return $self-&gt;goodbye("[disabled] -- NA $why");
    }

    $self-&gt;debug("checking already unwrapped[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (exists $self-&gt;{build_dir} &amp;&amp; -d $self-&gt;{build_dir}) {
        # this deserves print, not warn:
        return $self-&gt;success("Has already been unwrapped into directory ".
            "$self-&gt;{build_dir}"
        );
    }

    # XXX I'm not sure this should be here because it's not really
    # a test for whether get should continue or return; this is
    # a side effect -- xdg, 2012-04-05
    $self-&gt;debug("checking missing build_dir[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (exists $self-&gt;{build_dir} &amp;&amp; ! -d $self-&gt;{build_dir}){
        # we have lost it.
        $self-&gt;fforce(""); # no method to reset all phases but not set force (dodge)
        return undef; # no shortcut
    }

    # although we talk about 'force' we shall not test on
    # force directly. New model of force tries to refrain from
    # direct checking of force.
    $self-&gt;debug("checking unwrapping error[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if ( exists $self-&gt;{unwrapped} and (
            UNIVERSAL::can($self-&gt;{unwrapped},"failed") ?
            $self-&gt;{unwrapped}-&gt;failed :
            $self-&gt;{unwrapped} =~ /^NO/ )
    ) {
        return $self-&gt;goodbye("Unwrapping had some problem, won't try again without force");
    }

    return undef; # no shortcut
}

#-&gt; sub CPAN::Distribution::get ;
sub get {
    my($self) = @_;

    $self-&gt;pre_get();

    $self-&gt;debug("checking goto id[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (my $goto = $self-&gt;prefs-&gt;{goto}) {
        return $self-&gt;goto($goto);
    }

    if ( defined( my $sc = $self-&gt;shortcut_get) ) {
        return $sc;
    }

    local $ENV{PERL5LIB} = defined($ENV{PERL5LIB})
                           ? $ENV{PERL5LIB}
                           : ($ENV{PERLLIB} || "");
    local $ENV{PERL5OPT} = defined $ENV{PERL5OPT} ? $ENV{PERL5OPT} : "";
    # local $ENV{PERL_USE_UNSAFE_INC} = exists $ENV{PERL_USE_UNSAFE_INC} ? $ENV{PERL_USE_UNSAFE_INC} : 1; # get
    $CPAN::META-&gt;set_perl5lib;
    local $ENV{MAKEFLAGS}; # protect us from outer make calls

    my $sub_wd = CPAN::anycwd(); # for cleaning up as good as possible

    my($local_file);
    # XXX I don't think this check needs to be here, as it
    # is already checked in shortcut_get() -- xdg, 2012-04-05
    unless ($self-&gt;{build_dir} &amp;&amp; -d $self-&gt;{build_dir}) {
        $self-&gt;get_file_onto_local_disk;
        return if $CPAN::Signal;
        $self-&gt;check_integrity;
        return if $CPAN::Signal;
        (my $packagedir,$local_file) = $self-&gt;run_preps_on_packagedir;
        # XXX why is this check here? -- xdg, 2012-04-08
        if (exists $self-&gt;{writemakefile} &amp;&amp; ref $self-&gt;{writemakefile}
           &amp;&amp; $self-&gt;{writemakefile}-&gt;can("failed") &amp;&amp;
           $self-&gt;{writemakefile}-&gt;failed) {
           #
            return;
        }
        $packagedir ||= $self-&gt;{build_dir};
        $self-&gt;{build_dir} = $packagedir;
    }

    # XXX should this move up to after run_preps_on_packagedir?
    # Otherwise, failing writemakefile can return without
    # a $CPAN::Signal check -- xdg, 2012-04-05
    if ($CPAN::Signal) {
        $self-&gt;safe_chdir($sub_wd);
        return;
    }
    return unless $self-&gt;patch;
    $self-&gt;store_persistent_state;

    $self-&gt;post_get();

    return 1; # success
}

#-&gt; CPAN::Distribution::get_file_onto_local_disk
sub get_file_onto_local_disk {
    my($self) = @_;

    return if $self-&gt;is_dot_dist;
    my($local_file);
    my($local_wanted) =
        File::Spec-&gt;catfile(
                            $CPAN::Config-&gt;{keep_source_where},
                            "authors",
                            "id",
                            split(/\//,$self-&gt;id)
                           );

    $self-&gt;debug("Doing localize") if $CPAN::DEBUG;
    unless ($local_file =
            CPAN::FTP-&gt;localize("authors/id/$self-&gt;{ID}",
                                $local_wanted)) {
        my $note = "";
        if ($CPAN::Index::DATE_OF_02) {
            $note = "Note: Current database in memory was generated ".
                "on $CPAN::Index::DATE_OF_02\n";
        }
        $CPAN::Frontend-&gt;mydie("Giving up on '$local_wanted'\n$note");
    }

    $self-&gt;debug("local_wanted[$local_wanted]local_file[$local_file]") if $CPAN::DEBUG;
    $self-&gt;{localfile} = $local_file;
}


#-&gt; CPAN::Distribution::check_integrity
sub check_integrity {
    my($self) = @_;

    return if $self-&gt;is_dot_dist;
    if ($CPAN::META-&gt;has_inst("Digest::SHA")) {
        $self-&gt;debug("Digest::SHA is installed, verifying");
        $self-&gt;verifyCHECKSUM;
    } else {
        $self-&gt;debug("Digest::SHA is NOT installed");
    }
}

#-&gt; CPAN::Distribution::run_preps_on_packagedir
sub run_preps_on_packagedir {
    my($self) = @_;
    return if $self-&gt;is_dot_dist;

    $CPAN::META-&gt;{cachemgr} ||= CPAN::CacheMgr-&gt;new(); # unsafe meta access, ok
    my $builddir = $CPAN::META-&gt;{cachemgr}-&gt;dir; # unsafe meta access, ok
    $self-&gt;safe_chdir($builddir);
    $self-&gt;debug("Removing tmp-$$") if $CPAN::DEBUG;
    File::Path::rmtree("tmp-$$");
    unless (mkdir "tmp-$$", 0755) {
        $CPAN::Frontend-&gt;unrecoverable_error(&lt;&lt;EOF);
Couldn't mkdir '$builddir/tmp-$$': $!

Cannot continue: Please find the reason why I cannot make the
directory
$builddir/tmp-$$
and fix the problem, then retry.

EOF
    }
    if ($CPAN::Signal) {
        return;
    }
    $self-&gt;safe_chdir("tmp-$$");

    #
    # Unpack the goods
    #
    my $local_file = $self-&gt;{localfile};
    my $ct = eval{CPAN::Tarzip-&gt;new($local_file)};
    unless ($ct) {
        $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO");
        delete $self-&gt;{build_dir};
        return;
    }
    if ($local_file =~ /(\.tar\.(bz2|gz|Z)|\.tgz)(?!\n)\Z/i) {
        $self-&gt;{was_uncompressed}++ unless eval{$ct-&gt;gtest()};
        $self-&gt;untar_me($ct);
    } elsif ( $local_file =~ /\.zip(?!\n)\Z/i ) {
        $self-&gt;unzip_me($ct);
    } else {
        $self-&gt;{was_uncompressed}++ unless $ct-&gt;gtest();
        $local_file = $self-&gt;handle_singlefile($local_file);
    }

    # we are still in the tmp directory!
    # Let's check if the package has its own directory.
    my $dh = DirHandle-&gt;new(File::Spec-&gt;curdir)
        or Carp::croak("Couldn't opendir .: $!");
    my @readdir = grep $_ !~ /^\.\.?(?!\n)\Z/s, $dh-&gt;read; ### MAC??
    if (grep { $_ eq "pax_global_header" } @readdir) {
        $CPAN::Frontend-&gt;mywarn("Your (un)tar seems to have extracted a file named 'pax_global_header'
from the tarball '$local_file'.
This is almost certainly an error. Please upgrade your tar.
I'll ignore this file for now.
See also http://rt.cpan.org/Ticket/Display.html?id=38932\n");
        $CPAN::Frontend-&gt;mysleep(5);
        @readdir = grep { $_ ne "pax_global_header" } @readdir;
    }
    $dh-&gt;close;
    my $tdir_base;
    my $from_dir;
    my @dirents;
    if (@readdir == 1 &amp;&amp; -d $readdir[0]) {
        $tdir_base = $readdir[0];
        $from_dir = File::Spec-&gt;catdir(File::Spec-&gt;curdir,$readdir[0]);
        my $dh2;
        unless ($dh2 = DirHandle-&gt;new($from_dir)) {
            my($mode) = (stat $from_dir)[2];
            my $why = sprintf
                (
                 "Couldn't opendir '%s', mode '%o': %s",
                 $from_dir,
                 $mode,
                 $!,
                );
            $CPAN::Frontend-&gt;mywarn("$why\n");
            $self-&gt;{writemakefile} = CPAN::Distrostatus-&gt;new("NO -- $why");
            return;
        }
        @dirents = grep $_ !~ /^\.\.?(?!\n)\Z/s, $dh2-&gt;read; ### MAC??
    } else {
        my $userid = $self-&gt;cpan_userid;
        CPAN-&gt;debug("userid[$userid]");
        if (!$userid or $userid eq "N/A") {
            $userid = "anon";
        }
        $tdir_base = $userid;
        $from_dir = File::Spec-&gt;curdir;
        @dirents = @readdir;
    }
    eval { File::Path::mkpath $builddir; };
    if ($@) {
        $CPAN::Frontend-&gt;mydie("Cannot create directory $builddir: $@");
    }
    my $packagedir;
    my $eexist = ($CPAN::META-&gt;has_usable("Errno") &amp;&amp; defined &amp;Errno::EEXIST)
        ? &amp;Errno::EEXIST : undef;
    for(my $suffix = 0; ; $suffix++) {
        $packagedir = File::Spec-&gt;catdir($builddir, "$tdir_base-$suffix");
        my $parent = $builddir;
        mkdir($packagedir, 0777) and last;
        if((defined($eexist) &amp;&amp; $! != $eexist) || $suffix == 999) {
            $CPAN::Frontend-&gt;mydie("Cannot create directory $packagedir: $!\n");
        }
    }
    my $f;
    for $f (@dirents) { # is already without "." and ".."
        my $from = File::Spec-&gt;catfile($from_dir,$f);
        my $to = File::Spec-&gt;catfile($packagedir,$f);
        unless (File::Copy::move($from,$to)) {
            my $err = $!;
            $from = File::Spec-&gt;rel2abs($from);
            $CPAN::Frontend-&gt;mydie(
                "Couldn't move $from to $to: $err; #82295? ".
                "CPAN::VERSION=$CPAN::VERSION; ".
                "File::Copy::VERSION=$File::Copy::VERSION; ".
                "$from " . (-e $from ? "exists; " : "does not exist; ").
                "$to " . (-e $to ? "exists; " : "does not exist; ").
                "cwd=" . CPAN::anycwd() . ";"
            );
        }
    }
    $self-&gt;{build_dir} = $packagedir;
    $self-&gt;safe_chdir($builddir);
    File::Path::rmtree("tmp-$$");

    $self-&gt;safe_chdir($packagedir);
    $self-&gt;_signature_business();
    $self-&gt;safe_chdir($builddir);

    return($packagedir,$local_file);
}

#-&gt; sub CPAN::Distribution::pick_meta_file ;
sub pick_meta_file {
    my($self, $filter) = @_;
    $filter = '.' unless defined $filter;

    my $build_dir;
    unless ($build_dir = $self-&gt;{build_dir}) {
        # maybe permission on build_dir was missing
        $CPAN::Frontend-&gt;mywarn("Warning: cannot determine META.yml without a build_dir.\n");
        return;
    }

    my $has_cm = $CPAN::META-&gt;has_usable("CPAN::Meta");
    my $has_pcm = $CPAN::META-&gt;has_usable("Parse::CPAN::Meta");

    my @choices;
    push @choices, 'MYMETA.json' if $has_cm;
    push @choices, 'MYMETA.yml' if $has_cm || $has_pcm;
    push @choices, 'META.json' if $has_cm;
    push @choices, 'META.yml' if $has_cm || $has_pcm;

    for my $file ( grep { /$filter/ } @choices ) {
        my $path = File::Spec-&gt;catfile( $build_dir, $file );
        return $path if -f $path
    }

    return;
}

#-&gt; sub CPAN::Distribution::parse_meta_yml ;
sub parse_meta_yml {
    my($self, $yaml) = @_;
    $self-&gt;debug(sprintf("parse_meta_yml[%s]",$yaml||'undef')) if $CPAN::DEBUG;
    my $build_dir = $self-&gt;{build_dir} or die "PANIC: cannot parse yaml without a build_dir";
    $yaml ||= File::Spec-&gt;catfile($build_dir,"META.yml");
    $self-&gt;debug("meta[$yaml]") if $CPAN::DEBUG;
    return unless -f $yaml;
    my $early_yaml;
    eval {
        $CPAN::META-&gt;has_inst("Parse::CPAN::Meta") or die;
        die "Parse::CPAN::Meta yaml too old" unless $Parse::CPAN::Meta::VERSION &gt;= "1.40";
        # P::C::M returns last document in scalar context
        $early_yaml = Parse::CPAN::Meta::LoadFile($yaml);
    };
    unless ($early_yaml) {
        eval { $early_yaml = CPAN-&gt;_yaml_loadfile($yaml)-&gt;[0]; };
    }
    $self-&gt;debug(sprintf("yaml[%s]", $early_yaml || 'UNDEF')) if $CPAN::DEBUG;
    $self-&gt;debug($early_yaml) if $CPAN::DEBUG &amp;&amp; $early_yaml;
    if (!ref $early_yaml or ref $early_yaml ne "HASH"){
        # fix rt.cpan.org #95271
        $CPAN::Frontend-&gt;mywarn("The content of '$yaml' is not a HASH reference. Cannot use it.\n");
        return {};
    }
    return $early_yaml || undef;
}

#-&gt; sub CPAN::Distribution::satisfy_requires ;
# return values: 1 means requirements are satisfied;
# and 0 means not satisfied (and maybe queued)
sub satisfy_requires {
    my ($self) = @_;
    $self-&gt;debug("Entering satisfy_requires") if $CPAN::DEBUG;
    if (my @prereq = $self-&gt;unsat_prereq("later")) {
        if ($CPAN::DEBUG){
            require Data::Dumper;
            my $prereq = Data::Dumper-&gt;new(\@prereq)-&gt;Terse(1)-&gt;Indent(0)-&gt;Dump;
            $self-&gt;debug("unsatisfied[$prereq]");
        }
        if ($prereq[0][0] eq "perl") {
            my $need = "requires perl '$prereq[0][1]'";
            my $id = $self-&gt;pretty_id;
            $CPAN::Frontend-&gt;mywarn("$id $need; you have only $]; giving up\n");
            $self-&gt;{make} = CPAN::Distrostatus-&gt;new("NO $need");
            $self-&gt;store_persistent_state;
            die "[prereq] -- NOT OK\n";
        } else {
            my $follow = eval { $self-&gt;follow_prereqs("later",@prereq); };
            if (0) {
            } elsif ($follow) {
                return; # we need deps
            } elsif ($@ &amp;&amp; ref $@ &amp;&amp; $@-&gt;isa("CPAN::Exception::RecursiveDependency")) {
                $CPAN::Frontend-&gt;mywarn($@);
                die "[depend] -- NOT OK\n";
            }
        }
    }
    return 1;
}

#-&gt; sub CPAN::Distribution::satisfy_configure_requires ;
# return values: 1 means configure_require is satisfied;
# and 0 means not satisfied (and maybe queued)
sub satisfy_configure_requires {
    my($self) = @_;
    $self-&gt;debug("Entering satisfy_configure_requires") if $CPAN::DEBUG;
    my $enable_configure_requires = 1;
    if (!$enable_configure_requires) {
        return 1;
        # if we return 1 here, everything is as before we introduced
        # configure_requires that means, things with
        # configure_requires simply fail, all others succeed
    }
    my @prereq = $self-&gt;unsat_prereq("configure_requires_later");
    $self-&gt;debug(sprintf "configure_requires[%s]", join(",",map {join "/",@$_} @prereq)) if $CPAN::DEBUG;
    return 1 unless @prereq;
    $self-&gt;debug(\@prereq) if $CPAN::DEBUG;
    if ($self-&gt;{configure_requires_later}) {
        for my $k (sort keys %{$self-&gt;{configure_requires_later_for}||{}}) {
            if ($self-&gt;{configure_requires_later_for}{$k}&gt;1) {
                my $type = "";
                for my $p (@prereq) {
                    if ($p-&gt;[0] eq $k) {
                        $type = $p-&gt;[1];
                    }
                }
                $type = " $type" if $type;
                $CPAN::Frontend-&gt;mywarn("Warning: unmanageable(?) prerequisite $k$type");
                sleep 1;
            }
        }
    }
    if ($prereq[0][0] eq "perl") {
        my $need = "requires perl '$prereq[0][1]'";
        my $id = $self-&gt;pretty_id;
        $CPAN::Frontend-&gt;mywarn("$id $need; you have only $]; giving up\n");
        $self-&gt;{make} = CPAN::Distrostatus-&gt;new("NO $need");
        $self-&gt;store_persistent_state;
        return $self-&gt;goodbye("[prereq] -- NOT OK");
    } else {
        my $follow = eval {
            $self-&gt;follow_prereqs("configure_requires_later", @prereq);
        };
        if (0) {
        } elsif ($follow) {
            return; # we need deps
        } elsif ($@ &amp;&amp; ref $@ &amp;&amp; $@-&gt;isa("CPAN::Exception::RecursiveDependency")) {
            $CPAN::Frontend-&gt;mywarn($@);
            return $self-&gt;goodbye("[depend] -- NOT OK");
        }
        else {
          return $self-&gt;goodbye("[configure_requires] -- NOT OK");
        }
    }
    die "never reached";
}

#-&gt; sub CPAN::Distribution::choose_MM_or_MB ;
sub choose_MM_or_MB {
    my($self) = @_;
    $self-&gt;satisfy_configure_requires() or return;
    my $local_file = $self-&gt;{localfile};
    my($mpl) = File::Spec-&gt;catfile($self-&gt;{build_dir},"Makefile.PL");
    my($mpl_exists) = -f $mpl;
    unless ($mpl_exists) {
        # NFS has been reported to have racing problems after the
        # renaming of a directory in some environments.
        # This trick helps.
        $CPAN::Frontend-&gt;mysleep(1);
        my $mpldh = DirHandle-&gt;new($self-&gt;{build_dir})
            or Carp::croak("Couldn't opendir $self-&gt;{build_dir}: $!");
        $mpl_exists = grep /^Makefile\.PL$/, $mpldh-&gt;read;
        $mpldh-&gt;close;
    }
    my $prefer_installer = "eumm"; # eumm|mb
    if (-f File::Spec-&gt;catfile($self-&gt;{build_dir},"Build.PL")) {
        if ($mpl_exists) { # they *can* choose
            if ($CPAN::META-&gt;has_inst("Module::Build")) {
                $prefer_installer = CPAN::HandleConfig-&gt;prefs_lookup(
                  $self, q{prefer_installer}
                );
                # M::B &lt;= 0.35 left a DATA handle open that
                # causes problems upgrading M::B on Windows
                close *Module::Build::Version::DATA
                  if fileno *Module::Build::Version::DATA;
            }
        } else {
            $prefer_installer = "mb";
        }
    }
    if (lc($prefer_installer) eq "rand") {
        $prefer_installer = rand()&lt;.5 ? "eumm" : "mb";
    }
    if (lc($prefer_installer) eq "mb") {
        $self-&gt;{modulebuild} = 1;
    } elsif ($self-&gt;{archived} eq "patch") {
        # not an edge case, nothing to install for sure
        my $why = "A patch file cannot be installed";
        $CPAN::Frontend-&gt;mywarn("Refusing to handle this file: $why\n");
        $self-&gt;{writemakefile} = CPAN::Distrostatus-&gt;new("NO $why");
    } elsif (! $mpl_exists) {
        $self-&gt;_edge_cases($mpl,$local_file);
    }
    if ($self-&gt;{build_dir}
        &amp;&amp;
        $CPAN::Config-&gt;{build_dir_reuse}
       ) {
        $self-&gt;store_persistent_state;
    }
    return $self;
}

# see also reanimate_build_dir
#-&gt; CPAN::Distribution::store_persistent_state
sub store_persistent_state {
    my($self) = @_;
    my $dir = $self-&gt;{build_dir};
    unless (defined $dir &amp;&amp; length $dir) {
        my $id = $self-&gt;id;
        $CPAN::Frontend-&gt;mywarnonce("build_dir of $id is not known, ".
                                    "will not store persistent state\n");
        return;
    }
    # self-build-dir
    my $sbd = Cwd::realpath(
        File::Spec-&gt;catdir($dir,                       File::Spec-&gt;updir ())
                           );
    # config-build-dir
    my $cbd = Cwd::realpath(
        # the catdir is a workaround for bug https://rt.cpan.org/Ticket/Display.html?id=101283
        File::Spec-&gt;catdir($CPAN::Config-&gt;{build_dir}, File::Spec-&gt;curdir())
    );
    unless ($sbd eq $cbd) {
        $CPAN::Frontend-&gt;mywarnonce("Directory '$dir' not below $CPAN::Config-&gt;{build_dir}, ".
                                    "will not store persistent state\n");
        return;
    }
    my $file = sprintf "%s.yml", $dir;
    my $yaml_module = CPAN::_yaml_module();
    if ($CPAN::META-&gt;has_inst($yaml_module)) {
        CPAN-&gt;_yaml_dumpfile(
                             $file,
                             {
                              time =&gt; time,
                              perl =&gt; CPAN::_perl_fingerprint(),
                              distribution =&gt; $self,
                             }
                            );
    } else {
        $CPAN::Frontend-&gt;myprintonce("'$yaml_module' not installed, ".
                                    "will not store persistent state\n");
    }
}

#-&gt; CPAN::Distribution::try_download
sub try_download {
    my($self,$patch) = @_;
    my $norm = $self-&gt;normalize($patch);
    my($local_wanted) =
        File::Spec-&gt;catfile(
                            $CPAN::Config-&gt;{keep_source_where},
                            "authors",
                            "id",
                            split(/\//,$norm),
                           );
    $self-&gt;debug("Doing localize") if $CPAN::DEBUG;
    return CPAN::FTP-&gt;localize("authors/id/$norm",
                               $local_wanted);
}

{
    my $stdpatchargs = "";
    #-&gt; CPAN::Distribution::patch
    sub patch {
        my($self) = @_;
        $self-&gt;debug("checking patches id[$self-&gt;{ID}]") if $CPAN::DEBUG;
        my $patches = $self-&gt;prefs-&gt;{patches};
        $patches ||= "";
        $self-&gt;debug("patches[$patches]") if $CPAN::DEBUG;
        if ($patches) {
            return unless @$patches;
            $self-&gt;safe_chdir($self-&gt;{build_dir});
            CPAN-&gt;debug("patches[$patches]") if $CPAN::DEBUG;
            my $patchbin = $CPAN::Config-&gt;{patch};
            unless ($patchbin &amp;&amp; length $patchbin) {
                $CPAN::Frontend-&gt;mydie("No external patch command configured\n\n".
                                       "Please run 'o conf init /patch/'\n\n");
            }
            unless (MM-&gt;maybe_command($patchbin)) {
                $CPAN::Frontend-&gt;mydie("No external patch command available\n\n".
                                       "Please run 'o conf init /patch/'\n\n");
            }
            $patchbin = CPAN::HandleConfig-&gt;safe_quote($patchbin);
            local $ENV{PATCH_GET} = 0; # formerly known as -g0
            unless ($stdpatchargs) {
                my $system = "$patchbin --version |";
                local *FH;
                open FH, $system or die "Could not fork '$system': $!";
                local $/ = "\n";
                my $pversion;
              PARSEVERSION: while (&lt;FH&gt;) {
                    if (/^patch\s+([\d\.]+)/) {
                        $pversion = $1;
                        last PARSEVERSION;
                    }
                }
                if ($pversion) {
                    $stdpatchargs = "-N --fuzz=3";
                } else {
                    $stdpatchargs = "-N";
                }
            }
            my $countedpatches = @$patches == 1 ? "1 patch" : (scalar @$patches . " patches");
            $CPAN::Frontend-&gt;myprint("Applying $countedpatches:\n");
            my $patches_dir = $CPAN::Config-&gt;{patches_dir};
            for my $patch (@$patches) {
                if ($patches_dir &amp;&amp; !File::Spec-&gt;file_name_is_absolute($patch)) {
                    my $f = File::Spec-&gt;catfile($patches_dir, $patch);
                    $patch = $f if -f $f;
                }
                unless (-f $patch) {
                    CPAN-&gt;debug("not on disk: patch[$patch]") if $CPAN::DEBUG;
                    if (my $trydl = $self-&gt;try_download($patch)) {
                        $patch = $trydl;
                    } else {
                        my $fail = "Could not find patch '$patch'";
                        $CPAN::Frontend-&gt;mywarn("$fail; cannot continue\n");
                        $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO -- $fail");
                        delete $self-&gt;{build_dir};
                        return;
                    }
                }
                $CPAN::Frontend-&gt;myprint("  $patch\n");
                my $readfh = CPAN::Tarzip-&gt;TIEHANDLE($patch);

                my $pcommand;
                my($ppp,$pfiles) = $self-&gt;_patch_p_parameter($readfh);
                if ($ppp eq "applypatch") {
                    $pcommand = "$CPAN::Config-&gt;{applypatch} -verbose";
                } else {
                    my $thispatchargs = join " ", $stdpatchargs, $ppp;
                    $pcommand = "$patchbin $thispatchargs";
                    require Config; # usually loaded from CPAN.pm
                    if ($Config::Config{osname} eq "solaris") {
                        # native solaris patch cannot patch readonly files
                        for my $file (@{$pfiles||[]}) {
                            my @stat = stat $file or next;
                            chmod $stat[2] | 0600, $file; # may fail
                        }
                    }
                }

                $readfh = CPAN::Tarzip-&gt;TIEHANDLE($patch); # open again
                my $writefh = FileHandle-&gt;new;
                $CPAN::Frontend-&gt;myprint("  $pcommand\n");
                unless (open $writefh, "|$pcommand") {
                    my $fail = "Could not fork '$pcommand'";
                    $CPAN::Frontend-&gt;mywarn("$fail; cannot continue\n");
                    $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO -- $fail");
                    delete $self-&gt;{build_dir};
                    return;
                }
                binmode($writefh);
                while (my $x = $readfh-&gt;READLINE) {
                    print $writefh $x;
                }
                unless (close $writefh) {
                    my $fail = "Could not apply patch '$patch'";
                    $CPAN::Frontend-&gt;mywarn("$fail; cannot continue\n");
                    $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO -- $fail");
                    delete $self-&gt;{build_dir};
                    return;
                }
            }
            $self-&gt;{patched}++;
        }
        return 1;
    }
}

# may return
# - "applypatch"
# - ("-p0"|"-p1", $files)
sub _patch_p_parameter {
    my($self,$fh) = @_;
    my $cnt_files   = 0;
    my $cnt_p0files = 0;
    my @files;
    local($_);
    while ($_ = $fh-&gt;READLINE) {
        if (
            $CPAN::Config-&gt;{applypatch}
            &amp;&amp;
            /\#\#\#\# ApplyPatch data follows \#\#\#\#/
           ) {
            return "applypatch"
        }
        next unless /^[\*\+]{3}\s(\S+)/;
        my $file = $1;
        push @files, $file;
        $cnt_files++;
        $cnt_p0files++ if -f $file;
        CPAN-&gt;debug("file[$file]cnt_files[$cnt_files]cnt_p0files[$cnt_p0files]")
            if $CPAN::DEBUG;
    }
    return "-p1" unless $cnt_files;
    my $opt_p = $cnt_files==$cnt_p0files ? "-p0" : "-p1";
    return ($opt_p, \@files);
}

#-&gt; sub CPAN::Distribution::_edge_cases
# with "configure" or "Makefile" or single file scripts
sub _edge_cases {
    my($self,$mpl,$local_file) = @_;
    $self-&gt;debug(sprintf("makefilepl[%s]anycwd[%s]",
                         $mpl,
                         CPAN::anycwd(),
                        )) if $CPAN::DEBUG;
    my $build_dir = $self-&gt;{build_dir};
    my($configure) = File::Spec-&gt;catfile($build_dir,"Configure");
    if (-f $configure) {
        # do we have anything to do?
        $self-&gt;{configure} = $configure;
    } elsif (-f File::Spec-&gt;catfile($build_dir,"Makefile")) {
        $CPAN::Frontend-&gt;mywarn(qq{
Package comes with a Makefile and without a Makefile.PL.
We\'ll try to build it with that Makefile then.
});
        $self-&gt;{writemakefile} = CPAN::Distrostatus-&gt;new("YES");
        $CPAN::Frontend-&gt;mysleep(2);
    } else {
        my $cf = $self-&gt;called_for || "unknown";
        if ($cf =~ m|/|) {
            $cf =~ s|.*/||;
            $cf =~ s|\W.*||;
        }
        $cf =~ s|[/\\:]||g;     # risk of filesystem damage
        $cf = "unknown" unless length($cf);
        if (my $crud = $self-&gt;_contains_crud($build_dir)) {
            my $why = qq{Package contains $crud; not recognized as a perl package, giving up};
            $CPAN::Frontend-&gt;mywarn("$why\n");
            $self-&gt;{writemakefile} = CPAN::Distrostatus-&gt;new(qq{NO -- $why});
            return;
        }
        $CPAN::Frontend-&gt;mywarn(qq{Package seems to come without Makefile.PL.
  (The test -f "$mpl" returned false.)
  Writing one on our own (setting NAME to $cf)\a\n});
        $self-&gt;{had_no_makefile_pl}++;
        $CPAN::Frontend-&gt;mysleep(3);

        # Writing our own Makefile.PL

        my $exefile_stanza = "";
        if ($self-&gt;{archived} eq "maybe_pl") {
            $exefile_stanza = $self-&gt;_exefile_stanza($build_dir,$local_file);
        }

        my $fh = FileHandle-&gt;new;
        $fh-&gt;open("&gt;$mpl")
            or Carp::croak("Could not open &gt;$mpl: $!");
        $fh-&gt;print(
                   qq{# This Makefile.PL has been autogenerated by the module CPAN.pm
# because there was no Makefile.PL supplied.
# Autogenerated on: }.scalar localtime().qq{

use ExtUtils::MakeMaker;
WriteMakefile(
              NAME =&gt; q[$cf],$exefile_stanza
             );
});
        $fh-&gt;close;
    }
}

#-&gt; CPAN;:Distribution::_contains_crud
sub _contains_crud {
    my($self,$dir) = @_;
    my(@dirs, $dh, @files);
    opendir $dh, $dir or return;
    my $dirent;
    for $dirent (readdir $dh) {
        next if $dirent =~ /^\.\.?$/;
        my $path = File::Spec-&gt;catdir($dir,$dirent);
        if (-d $path) {
            push @dirs, $dirent;
        } elsif (-f $path) {
            push @files, $dirent;
        }
    }
    if (@dirs &amp;&amp; @files) {
        return "both files[@files] and directories[@dirs]";
    } elsif (@files &gt; 2) {
        return "several files[@files] but no Makefile.PL or Build.PL";
    }
    return;
}

#-&gt; CPAN;:Distribution::_exefile_stanza
sub _exefile_stanza {
    my($self,$build_dir,$local_file) = @_;

            my $fh = FileHandle-&gt;new;
            my $script_file = File::Spec-&gt;catfile($build_dir,$local_file);
            $fh-&gt;open($script_file)
                or Carp::croak("Could not open script '$script_file': $!");
            local $/ = "\n";
            # parse name and prereq
            my($state) = "poddir";
            my($name, $prereq) = ("", "");
            while (&lt;$fh&gt;) {
                if ($state eq "poddir" &amp;&amp; /^=head\d\s+(\S+)/) {
                    if ($1 eq 'NAME') {
                        $state = "name";
                    } elsif ($1 eq 'PREREQUISITES') {
                        $state = "prereq";
                    }
                } elsif ($state =~ m{^(name|prereq)$}) {
                    if (/^=/) {
                        $state = "poddir";
                    } elsif (/^\s*$/) {
                        # nop
                    } elsif ($state eq "name") {
                        if ($name eq "") {
                            ($name) = /^(\S+)/;
                            $state = "poddir";
                        }
                    } elsif ($state eq "prereq") {
                        $prereq .= $_;
                    }
                } elsif (/^=cut\b/) {
                    last;
                }
            }
            $fh-&gt;close;

            for ($name) {
                s{.*&lt;}{};       # strip X&lt;...&gt;
                s{&gt;.*}{};
            }
            chomp $prereq;
            $prereq = join " ", split /\s+/, $prereq;
            my($PREREQ_PM) = join("\n", map {
                s{.*&lt;}{};       # strip X&lt;...&gt;
                s{&gt;.*}{};
                if (/[\s\'\"]/) { # prose?
                } else {
                    s/[^\w:]$//; # period?
                    " "x28 . "'$_' =&gt; 0,";
                }
            } split /\s*,\s*/, $prereq);

            if ($name) {
                my $to_file = File::Spec-&gt;catfile($build_dir, $name);
                rename $script_file, $to_file
                    or die "Can't rename $script_file to $to_file: $!";
            }

    return "
              EXE_FILES =&gt; ['$name'],
              PREREQ_PM =&gt; {
$PREREQ_PM
                           },
";
}

#-&gt; CPAN::Distribution::_signature_business
sub _signature_business {
    my($self) = @_;
    my $check_sigs = CPAN::HandleConfig-&gt;prefs_lookup($self,
                                                      q{check_sigs});
    if ($check_sigs) {
        if ($CPAN::META-&gt;has_inst("Module::Signature")) {
            if (-f "SIGNATURE") {
                $self-&gt;debug("Module::Signature is installed, verifying") if $CPAN::DEBUG;
                my $rv = Module::Signature::verify();
                if ($rv != Module::Signature::SIGNATURE_OK() and
                    $rv != Module::Signature::SIGNATURE_MISSING()) {
                    $CPAN::Frontend-&gt;mywarn(
                                            qq{\nSignature invalid for }.
                                            qq{distribution file. }.
                                            qq{Please investigate.\n\n}
                                           );

                    my $wrap =
                        sprintf(qq{I'd recommend removing %s. Some error occurred   }.
                                qq{while checking its signature, so it could        }.
                                qq{be invalid. Maybe you have configured            }.
                                qq{your 'urllist' with a bad URL. Please check this }.
                                qq{array with 'o conf urllist' and retry. Or        }.
                                qq{examine the distribution in a subshell. Try
  look %s
and run
  cpansign -v
},
                                $self-&gt;{localfile},
                                $self-&gt;pretty_id,
                               );
                    $self-&gt;{signature_verify} = CPAN::Distrostatus-&gt;new("NO");
                    $CPAN::Frontend-&gt;mywarn(Text::Wrap::wrap("","",$wrap));
                    $CPAN::Frontend-&gt;mysleep(5) if $CPAN::Frontend-&gt;can("mysleep");
                } else {
                    $self-&gt;{signature_verify} = CPAN::Distrostatus-&gt;new("YES");
                    $self-&gt;debug("Module::Signature has verified") if $CPAN::DEBUG;
                }
            } else {
                $CPAN::Frontend-&gt;mywarn(qq{Package came without SIGNATURE\n\n});
            }
        } else {
            $self-&gt;debug("Module::Signature is NOT installed") if $CPAN::DEBUG;
        }
    }
}

#-&gt; CPAN::Distribution::untar_me ;
sub untar_me {
    my($self,$ct) = @_;
    $self-&gt;{archived} = "tar";
    my $result = eval { $ct-&gt;untar() };
    if ($result) {
        $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("YES");
    } else {
        # unfortunately we have no $@ here, Tarzip is using mydie which dies with "\n"
        $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO -- untar failed");
    }
}

# CPAN::Distribution::unzip_me ;
sub unzip_me {
    my($self,$ct) = @_;
    $self-&gt;{archived} = "zip";
    if ($ct-&gt;unzip()) {
        $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("YES");
    } else {
        $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO -- unzip failed");
    }
    return;
}

sub handle_singlefile {
    my($self,$local_file) = @_;

    if ( $local_file =~ /\.pm(\.(gz|Z))?(?!\n)\Z/ ) {
        $self-&gt;{archived} = "pm";
    } elsif ( $local_file =~ /\.patch(\.(gz|bz2))?(?!\n)\Z/ ) {
        $self-&gt;{archived} = "patch";
    } else {
        $self-&gt;{archived} = "maybe_pl";
    }

    my $to = File::Basename::basename($local_file);
    if ($to =~ s/\.(gz|Z)(?!\n)\Z//) {
        if (eval{CPAN::Tarzip-&gt;new($local_file)-&gt;gunzip($to)}) {
            $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("YES");
        } else {
            $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO -- uncompressing failed");
        }
    } else {
        if (File::Copy::cp($local_file,".")) {
            $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("YES");
        } else {
            $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO -- copying failed");
        }
    }
    return $to;
}

#-&gt; sub CPAN::Distribution::new ;
sub new {
    my($class,%att) = @_;

    # $CPAN::META-&gt;{cachemgr} ||= CPAN::CacheMgr-&gt;new();

    my $this = { %att };
    return bless $this, $class;
}

#-&gt; sub CPAN::Distribution::look ;
sub look {
    my($self) = @_;

    if ($^O eq 'MacOS') {
      $self-&gt;Mac::BuildTools::look;
      return;
    }

    if (  $CPAN::Config-&gt;{'shell'} ) {
        $CPAN::Frontend-&gt;myprint(qq{
Trying to open a subshell in the build directory...
});
    } else {
        $CPAN::Frontend-&gt;myprint(qq{
Your configuration does not define a value for subshells.
Please define it with "o conf shell &lt;your shell&gt;"
});
        return;
    }
    my $dist = $self-&gt;id;
    my $dir;
    unless ($dir = $self-&gt;dir) {
        $self-&gt;get;
    }
    unless ($dir ||= $self-&gt;dir) {
        $CPAN::Frontend-&gt;mywarn(qq{
Could not determine which directory to use for looking at $dist.
});
        return;
    }
    my $pwd  = CPAN::anycwd();
    $self-&gt;safe_chdir($dir);
    $CPAN::Frontend-&gt;myprint(qq{Working directory is $dir\n});
    {
        local $ENV{CPAN_SHELL_LEVEL} = $ENV{CPAN_SHELL_LEVEL}||0;
        $ENV{CPAN_SHELL_LEVEL} += 1;
        my $shell = CPAN::HandleConfig-&gt;safe_quote($CPAN::Config-&gt;{'shell'});

        local $ENV{PERL5LIB} = defined($ENV{PERL5LIB})
            ? $ENV{PERL5LIB}
                : ($ENV{PERLLIB} || "");

        local $ENV{PERL5OPT} = defined $ENV{PERL5OPT} ? $ENV{PERL5OPT} : "";
        # local $ENV{PERL_USE_UNSAFE_INC} = exists $ENV{PERL_USE_UNSAFE_INC} ? $ENV{PERL_USE_UNSAFE_INC} : 1; # look
        $CPAN::META-&gt;set_perl5lib;
        local $ENV{MAKEFLAGS}; # protect us from outer make calls

        unless (system($shell) == 0) {
            my $code = $? &gt;&gt; 8;
            $CPAN::Frontend-&gt;mywarn("Subprocess shell exit code $code\n");
        }
    }
    $self-&gt;safe_chdir($pwd);
}

# CPAN::Distribution::cvs_import ;
sub cvs_import {
    my($self) = @_;
    $self-&gt;get;
    my $dir = $self-&gt;dir;

    my $package = $self-&gt;called_for;
    my $module = $CPAN::META-&gt;instance('CPAN::Module', $package);
    my $version = $module-&gt;cpan_version;

    my $userid = $self-&gt;cpan_userid;

    my $cvs_dir = (split /\//, $dir)[-1];
    $cvs_dir =~ s/-\d+[^-]+(?!\n)\Z//;
    my $cvs_root =
      $CPAN::Config-&gt;{cvsroot} || $ENV{CVSROOT};
    my $cvs_site_perl =
      $CPAN::Config-&gt;{cvs_site_perl} || $ENV{CVS_SITE_PERL};
    if ($cvs_site_perl) {
        $cvs_dir = "$cvs_site_perl/$cvs_dir";
    }
    my $cvs_log = qq{"imported $package $version sources"};
    $version =~ s/\./_/g;
    # XXX cvs: undocumented and unclear how it was meant to work
    my @cmd = ('cvs', '-d', $cvs_root, 'import', '-m', $cvs_log,
               "$cvs_dir", $userid, "v$version");

    my $pwd  = CPAN::anycwd();
    chdir($dir) or $CPAN::Frontend-&gt;mydie(qq{Could not chdir to "$dir": $!});

    $CPAN::Frontend-&gt;myprint(qq{Working directory is $dir\n});

    $CPAN::Frontend-&gt;myprint(qq{@cmd\n});
    system(@cmd) == 0 or
    # XXX cvs
        $CPAN::Frontend-&gt;mydie("cvs import failed");
    chdir($pwd) or $CPAN::Frontend-&gt;mydie(qq{Could not chdir to "$pwd": $!});
}

#-&gt; sub CPAN::Distribution::readme ;
sub readme {
    my($self) = @_;
    my($dist) = $self-&gt;id;
    my($sans,$suffix) = $dist =~ /(.+)\.(tgz|tar[\._-]gz|tar\.Z|zip)$/;
    $self-&gt;debug("sans[$sans] suffix[$suffix]\n") if $CPAN::DEBUG;
    my($local_file);
    my($local_wanted) =
        File::Spec-&gt;catfile(
                            $CPAN::Config-&gt;{keep_source_where},
                            "authors",
                            "id",
                            split(/\//,"$sans.readme"),
                           );
    my $readme = "authors/id/$sans.readme";
    $self-&gt;debug("Doing localize for '$readme'") if $CPAN::DEBUG;
    $local_file = CPAN::FTP-&gt;localize($readme,
                                      $local_wanted)
        or $CPAN::Frontend-&gt;mydie(qq{No $sans.readme found});

    if ($^O eq 'MacOS') {
        Mac::BuildTools::launch_file($local_file);
        return;
    }

    my $fh_pager = FileHandle-&gt;new;
    local($SIG{PIPE}) = "IGNORE";
    my $pager = $CPAN::Config-&gt;{'pager'} || "cat";
    $fh_pager-&gt;open("|$pager")
        or die "Could not open pager $pager\: $!";
    my $fh_readme = FileHandle-&gt;new;
    $fh_readme-&gt;open($local_file)
        or $CPAN::Frontend-&gt;mydie(qq{Could not open "$local_file": $!});
    $CPAN::Frontend-&gt;myprint(qq{
Displaying file
  $local_file
with pager "$pager"
});
    $fh_pager-&gt;print(&lt;$fh_readme&gt;);
    $fh_pager-&gt;close;
}

#-&gt; sub CPAN::Distribution::verifyCHECKSUM ;
sub verifyCHECKSUM {
    my($self) = @_;
  EXCUSE: {
        my @e;
        $self-&gt;{CHECKSUM_STATUS} ||= "";
        $self-&gt;{CHECKSUM_STATUS} eq "OK" and push @e, "Checksum was ok";
        $CPAN::Frontend-&gt;myprint(join "", map {"  $_\n"} @e) and return if @e;
    }
    my($lc_want,$lc_file,@local,$basename);
    @local = split(/\//,$self-&gt;id);
    pop @local;
    push @local, "CHECKSUMS";
    $lc_want =
        File::Spec-&gt;catfile($CPAN::Config-&gt;{keep_source_where},
                            "authors", "id", @local);
    local($") = "/";
    if (my $size = -s $lc_want) {
        $self-&gt;debug("lc_want[$lc_want]size[$size]") if $CPAN::DEBUG;
        if ($self-&gt;CHECKSUM_check_file($lc_want,1)) {
            return $self-&gt;{CHECKSUM_STATUS} = "OK";
        }
    }
    $lc_file = CPAN::FTP-&gt;localize("authors/id/@local",
                                   $lc_want,1);
    unless ($lc_file) {
        $CPAN::Frontend-&gt;myprint("Trying $lc_want.gz\n");
        $local[-1] .= ".gz";
        $lc_file = CPAN::FTP-&gt;localize("authors/id/@local",
                                       "$lc_want.gz",1);
        if ($lc_file) {
            $lc_file =~ s/\.gz(?!\n)\Z//;
            eval{CPAN::Tarzip-&gt;new("$lc_file.gz")-&gt;gunzip($lc_file)};
        } else {
            return;
        }
    }
    if ($self-&gt;CHECKSUM_check_file($lc_file)) {
        return $self-&gt;{CHECKSUM_STATUS} = "OK";
    }
}

#-&gt; sub CPAN::Distribution::SIG_check_file ;
sub SIG_check_file {
    my($self,$chk_file) = @_;
    my $rv = eval { Module::Signature::_verify($chk_file) };

    if ($rv eq Module::Signature::CANNOT_VERIFY()) {
        $CPAN::Frontend-&gt;myprint(qq{\nSignature for }.
                                 qq{file $chk_file could not be verified for an unknown reason. }.
                                 $self-&gt;as_string.
                                 qq{Module::Signature verification returned value $rv\n\n}
                                );

        my $wrap = qq{The manual says for this case: Cannot verify the
OpenPGP signature, maybe due to the lack of a network connection to
the key server, or if neither gnupg nor Crypt::OpenPGP exists on the
system. You probably want to analyse the situation and if you cannot
fix it you will have to decide whether you want to stop this session
or you want to turn off signature verification. The latter would be
done with the command 'o conf init check_sigs'};

        $CPAN::Frontend-&gt;mydie(Text::Wrap::wrap("","",$wrap));
    } if ($rv == Module::Signature::SIGNATURE_OK()) {
        $CPAN::Frontend-&gt;myprint("Signature for $chk_file ok\n");
        return $self-&gt;{SIG_STATUS} = "OK";
    } else {
        $CPAN::Frontend-&gt;mywarn(qq{\nSignature invalid for }.
                                 qq{file $chk_file. }.
                                 qq{Please investigate.\n\n}.
                                 $self-&gt;as_string.
                                 qq{Module::Signature verification returned value $rv\n\n}
                                );

        my $wrap = qq{I\'d recommend removing $chk_file. Its signature
is invalid. Maybe you have configured your 'urllist' with
a bad URL. Please check this array with 'o conf urllist', and
retry.};

        $CPAN::Frontend-&gt;mydie(Text::Wrap::wrap("","",$wrap));
    }
}

#-&gt; sub CPAN::Distribution::CHECKSUM_check_file ;

# sloppy is 1 when we have an old checksums file that maybe is good
# enough

sub CHECKSUM_check_file {
    my($self,$chk_file,$sloppy) = @_;
    my($cksum,$file,$basename);

    $sloppy ||= 0;
    $self-&gt;debug("chk_file[$chk_file]sloppy[$sloppy]") if $CPAN::DEBUG;
    my $check_sigs = CPAN::HandleConfig-&gt;prefs_lookup($self,
                                                      q{check_sigs});
    if ($check_sigs) {
        if ($CPAN::META-&gt;has_inst("Module::Signature")) {
            $self-&gt;debug("Module::Signature is installed, verifying") if $CPAN::DEBUG;
            $self-&gt;SIG_check_file($chk_file);
        } else {
            $self-&gt;debug("Module::Signature is NOT installed") if $CPAN::DEBUG;
        }
    }

    $file = $self-&gt;{localfile};
    $basename = File::Basename::basename($file);
    my($signed_data);
    my $fh = FileHandle-&gt;new;
    if ($check_sigs) {
        my $tempdir;
        if ($CPAN::META-&gt;has_usable("File::Temp")) {
            $tempdir = File::Temp::tempdir("CHECKSUMS-XXXX", CLEANUP =&gt; 1, DIR =&gt; "/tmp" );
        } else {
            $tempdir = File::Spec-&gt;catdir(File::Spec-&gt;tmpdir, "CHECKSUMS-$$");
            File::Path::mkpath($tempdir);
        }
        my $tempfile = File::Spec-&gt;catfile($tempdir, "CHECKSUMS.$$");
        unlink $tempfile; # ignore missing file
        my $devnull = File::Spec-&gt;devnull;
        my $gpg = $CPAN::Config-&gt;{gpg} or
            $CPAN::Frontend-&gt;mydie("Your configuration suggests that you do not have 'gpg' installed. This is needed to verify checksums with the config variable 'check_sigs' on. Please configure it with 'o conf init gpg'");
        my $system = qq{"$gpg" --verify --batch --no-tty --output "$tempfile" "$chk_file" 2&gt; "$devnull"};
        0 == system $system or $CPAN::Frontend-&gt;mydie("gpg run was failing, cannot continue: $system");
        open $fh, $tempfile or $CPAN::Frontend-&gt;mydie("Could not open $tempfile: $!");
        local $/;
        $signed_data = &lt;$fh&gt;;
        close $fh;
        File::Path::rmtree($tempdir);
    } else {
        my $fh = FileHandle-&gt;new;
        if (open $fh, $chk_file) {
            local($/);
            $signed_data = &lt;$fh&gt;;
        } else {
            $CPAN::Frontend-&gt;mydie("Could not open $chk_file for reading");
        }
        close $fh;
    }
    $signed_data =~ s/\015?\012/\n/g;
    my($compmt) = Safe-&gt;new();
    $cksum = $compmt-&gt;reval($signed_data);
    if ($@) {
        rename $chk_file, "$chk_file.bad";
        Carp::confess($@) if $@;
    }

    if (! ref $cksum or ref $cksum ne "HASH") {
        $CPAN::Frontend-&gt;mywarn(qq{
Warning: checksum file '$chk_file' broken.

When trying to read that file I expected to get a hash reference
for further processing, but got garbage instead.
});
        my $answer = CPAN::Shell::colorable_makemaker_prompt("Proceed nonetheless?", "no");
        $answer =~ /^\s*y/i or $CPAN::Frontend-&gt;mydie("Aborted.\n");
        $self-&gt;{CHECKSUM_STATUS} = "NIL -- CHECKSUMS file broken";
        return;
    } elsif (exists $cksum-&gt;{$basename} &amp;&amp; ! exists $cksum-&gt;{$basename}{cpan_path}) {
        $CPAN::Frontend-&gt;mywarn(qq{
Warning: checksum file '$chk_file' not conforming.

The cksum does not contain the key 'cpan_path' for '$basename'.
});
        my $answer = CPAN::Shell::colorable_makemaker_prompt("Proceed nonetheless?", "no");
        $answer =~ /^\s*y/i or $CPAN::Frontend-&gt;mydie("Aborted.\n");
        $self-&gt;{CHECKSUM_STATUS} = "NIL -- CHECKSUMS file without cpan_path";
        return;
    } elsif (exists $cksum-&gt;{$basename} &amp;&amp; substr($self-&gt;{ID},0,length($cksum-&gt;{$basename}{cpan_path}))
             ne $cksum-&gt;{$basename}{cpan_path}) {
        $CPAN::Frontend-&gt;mywarn(qq{
Warning: checksum file not matching path '$self-&gt;{ID}'.

The cksum contain the key 'cpan_path=$cksum-&gt;{$basename}{cpan_path}'
which does not match the ID of the distribution '$self-&gt;{ID}'.
Something's suspicious might be going on here. Please investigate.

});
        my $answer = CPAN::Shell::colorable_makemaker_prompt("Proceed nonetheless?", "no");
        $answer =~ /^\s*y/i or $CPAN::Frontend-&gt;mydie("Aborted.\n");
        $self-&gt;{CHECKSUM_STATUS} = "NIL -- CHECKSUMS non-matching cpan_path vs. ID";
        return;
    } elsif (exists $cksum-&gt;{$basename}{sha256}) {
        $self-&gt;debug("Found checksum for $basename:" .
                     "$cksum-&gt;{$basename}{sha256}\n") if $CPAN::DEBUG;

        open($fh, $file);
        binmode $fh;
        my $eq = $self-&gt;eq_CHECKSUM($fh,$cksum-&gt;{$basename}{sha256});
        $fh-&gt;close;
        $fh = CPAN::Tarzip-&gt;TIEHANDLE($file);

        unless ($eq) {
            my $dg = Digest::SHA-&gt;new(256);
            my($data,$ref);
            $ref = \$data;
            while ($fh-&gt;READ($ref, 4096) &gt; 0) {
                $dg-&gt;add($data);
            }
            my $hexdigest = $dg-&gt;hexdigest;
            $eq += $hexdigest eq $cksum-&gt;{$basename}{'sha256-ungz'};
        }

        if ($eq) {
            $CPAN::Frontend-&gt;myprint("Checksum for $file ok\n");
            return $self-&gt;{CHECKSUM_STATUS} = "OK";
        } else {
            $CPAN::Frontend-&gt;myprint(qq{\nChecksum mismatch for }.
                                     qq{distribution file. }.
                                     qq{Please investigate.\n\n}.
                                     $self-&gt;as_string,
                                     $CPAN::META-&gt;instance(
                                                           'CPAN::Author',
                                                           $self-&gt;cpan_userid
                                                          )-&gt;as_string);

            my $wrap = qq{I\'d recommend removing $file. Its
checksum is incorrect. Maybe you have configured your 'urllist' with
a bad URL. Please check this array with 'o conf urllist', and
retry.};

            $CPAN::Frontend-&gt;mydie(Text::Wrap::wrap("","",$wrap));

            # former versions just returned here but this seems a
            # serious threat that deserves a die

            # $CPAN::Frontend-&gt;myprint("\n\n");
            # sleep 3;
            # return;
        }
        # close $fh if fileno($fh);
    } else {
        return if $sloppy;
        unless ($self-&gt;{CHECKSUM_STATUS}) {
            $CPAN::Frontend-&gt;mywarn(qq{
Warning: No checksum for $basename in $chk_file.

The cause for this may be that the file is very new and the checksum
has not yet been calculated, but it may also be that something is
going awry right now.
});
            my $answer = CPAN::Shell::colorable_makemaker_prompt("Proceed?", "yes");
            $answer =~ /^\s*y/i or $CPAN::Frontend-&gt;mydie("Aborted.\n");
        }
        $self-&gt;{CHECKSUM_STATUS} = "NIL -- distro not in CHECKSUMS file";
        return;
    }
}

#-&gt; sub CPAN::Distribution::eq_CHECKSUM ;
sub eq_CHECKSUM {
    my($self,$fh,$expect) = @_;
    if ($CPAN::META-&gt;has_inst("Digest::SHA")) {
        my $dg = Digest::SHA-&gt;new(256);
        my($data);
        while (read($fh, $data, 4096)) {
            $dg-&gt;add($data);
        }
        my $hexdigest = $dg-&gt;hexdigest;
        # warn "fh[$fh] hex[$hexdigest] aexp[$expectMD5]";
        return $hexdigest eq $expect;
    }
    return 1;
}

#-&gt; sub CPAN::Distribution::force ;

# Both CPAN::Modules and CPAN::Distributions know if "force" is in
# effect by autoinspection, not by inspecting a global variable. One
# of the reason why this was chosen to work that way was the treatment
# of dependencies. They should not automatically inherit the force
# status. But this has the downside that ^C and die() will return to
# the prompt but will not be able to reset the force_update
# attributes. We try to correct for it currently in the read_metadata
# routine, and immediately before we check for a Signal. I hope this
# works out in one of v1.57_53ff

# "Force get forgets previous error conditions"

#-&gt; sub CPAN::Distribution::fforce ;
sub fforce {
  my($self, $method) = @_;
  $self-&gt;force($method,1);
}

#-&gt; sub CPAN::Distribution::force ;
sub force {
  my($self, $method,$fforce) = @_;
  my %phase_map = (
                   get =&gt; [
                           "unwrapped",
                           "build_dir",
                           "archived",
                           "localfile",
                           "CHECKSUM_STATUS",
                           "signature_verify",
                           "prefs",
                           "prefs_file",
                           "prefs_file_doc",
                          ],
                   make =&gt; [
                            "writemakefile",
                            "make",
                            "modulebuild",
                            "prereq_pm",
                           ],
                   test =&gt; [
                            "badtestcnt",
                            "make_test",
                           ],
                   install =&gt; [
                               "install",
                              ],
                   unknown =&gt; [
                               "reqtype",
                               "yaml_content",
                              ],
                  );
  my $methodmatch = 0;
  my $ldebug = 0;
 PHASE: for my $phase (qw(unknown get make test install)) { # order matters
      $methodmatch = 1 if $fforce || ($method &amp;&amp; $phase eq $method);
      next unless $methodmatch;
    ATTRIBUTE: for my $att (@{$phase_map{$phase}}) {
          if ($phase eq "get") {
              if (substr($self-&gt;id,-1,1) eq "."
                  &amp;&amp; $att =~ /(unwrapped|build_dir|archived)/ ) {
                  # cannot be undone for local distros
                  next ATTRIBUTE;
              }
              if ($att eq "build_dir"
                  &amp;&amp; $self-&gt;{build_dir}
                  &amp;&amp; $CPAN::META-&gt;{is_tested}
                 ) {
                  delete $CPAN::META-&gt;{is_tested}{$self-&gt;{build_dir}};
              }
          } elsif ($phase eq "test") {
              if ($att eq "make_test"
                  &amp;&amp; $self-&gt;{make_test}
                  &amp;&amp; $self-&gt;{make_test}{COMMANDID}
                  &amp;&amp; $self-&gt;{make_test}{COMMANDID} == $CPAN::CurrentCommandId
                 ) {
                  # endless loop too likely
                  next ATTRIBUTE;
              }
          }
          delete $self-&gt;{$att};
          if ($ldebug || $CPAN::DEBUG) {
              # local $CPAN::DEBUG = 16; # Distribution
              CPAN-&gt;debug(sprintf "id[%s]phase[%s]att[%s]", $self-&gt;id, $phase, $att);
          }
      }
  }
  if ($method &amp;&amp; $method =~ /make|test|install/) {
    $self-&gt;{force_update} = 1; # name should probably have been force_install
  }
}

#-&gt; sub CPAN::Distribution::notest ;
sub notest {
  my($self, $method) = @_;
  # $CPAN::Frontend-&gt;mywarn("XDEBUG: set notest for $self $method");
  $self-&gt;{"notest"}++; # name should probably have been force_install
}

#-&gt; sub CPAN::Distribution::unnotest ;
sub unnotest {
  my($self) = @_;
  # warn "XDEBUG: deleting notest";
  delete $self-&gt;{notest};
}

#-&gt; sub CPAN::Distribution::unforce ;
sub unforce {
  my($self) = @_;
  delete $self-&gt;{force_update};
}

#-&gt; sub CPAN::Distribution::isa_perl ;
sub isa_perl {
  my($self) = @_;
  my $file = File::Basename::basename($self-&gt;id);
  if ($file =~ m{ ^ perl
                  (
                   -(5\.\d+\.\d+)
                   |
                   (5)[._-](00[0-5](?:_[0-4][0-9])?)
                  )
                  \.tar[._-](?:gz|bz2)
                  (?!\n)\Z
                }xs) {
    my $perl_version;
    if ($2) {
        $perl_version = $2;
    } else {
        $perl_version = "$3.$4";
    }
    return $perl_version;
  } elsif ($self-&gt;cpan_comment
           &amp;&amp;
           $self-&gt;cpan_comment =~ /isa_perl\(.+?\)/) {
    return $1;
  }
}


#-&gt; sub CPAN::Distribution::perl ;
sub perl {
    my ($self) = @_;
    if (! $self) {
        use Carp qw(carp);
        carp __PACKAGE__ . "::perl was called without parameters.";
    }
    return CPAN::HandleConfig-&gt;safe_quote($CPAN::Perl);
}

#-&gt; sub CPAN::Distribution::shortcut_prepare ;
# return values: undef means don't shortcut; 0 means shortcut as fail;
# and 1 means shortcut as success

sub shortcut_prepare {
    my ($self) = @_;

    $self-&gt;debug("checking archive type[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (!$self-&gt;{archived} || $self-&gt;{archived} eq "NO") {
        return $self-&gt;goodbye("Is neither a tar nor a zip archive.");
    }

    $self-&gt;debug("checking unwrapping[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (!$self-&gt;{unwrapped}
        || (
            UNIVERSAL::can($self-&gt;{unwrapped},"failed") ?
            $self-&gt;{unwrapped}-&gt;failed :
            $self-&gt;{unwrapped} =~ /^NO/
            )) {
        return $self-&gt;goodbye("Had problems unarchiving. Please build manually");
    }

    $self-&gt;debug("checking signature[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if ( ! $self-&gt;{force_update}
        &amp;&amp; exists $self-&gt;{signature_verify}
        &amp;&amp; (
                UNIVERSAL::can($self-&gt;{signature_verify},"failed") ?
                $self-&gt;{signature_verify}-&gt;failed :
                $self-&gt;{signature_verify} =~ /^NO/
            )
    ) {
        return $self-&gt;goodbye("Did not pass the signature test.");
    }

    $self-&gt;debug("checking writemakefile[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if ($self-&gt;{writemakefile}) {
        if (
                UNIVERSAL::can($self-&gt;{writemakefile},"failed") ?
                $self-&gt;{writemakefile}-&gt;failed :
                $self-&gt;{writemakefile} =~ /^NO/
            ) {
            # XXX maybe a retry would be in order?
            my $err = UNIVERSAL::can($self-&gt;{writemakefile},"text") ?
                $self-&gt;{writemakefile}-&gt;text :
                    $self-&gt;{writemakefile};
            $err =~ s/^NO\s*(--\s+)?//;
            $err ||= "Had some problem writing Makefile";
            $err .= ", not re-running";
            return $self-&gt;goodbye($err);
        } else {
            return $self-&gt;success("Has already been prepared");
        }
    }

    $self-&gt;debug("checking configure_requires_later[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if( my $later = $self-&gt;{configure_requires_later} ) { # see also undelay
        return $self-&gt;goodbye($later);
    }

    return undef; # no shortcut
}

sub prepare {
    my ($self) = @_;

    $self-&gt;get
        or return;

    if ( defined( my $sc = $self-&gt;shortcut_prepare) ) {
        return $sc;
    }

    local $ENV{PERL5LIB} = defined($ENV{PERL5LIB})
                           ? $ENV{PERL5LIB}
                           : ($ENV{PERLLIB} || "");
    local $ENV{PERL5OPT} = defined $ENV{PERL5OPT} ? $ENV{PERL5OPT} : "";
    local $ENV{PERL_USE_UNSAFE_INC} = exists $ENV{PERL_USE_UNSAFE_INC} ? $ENV{PERL_USE_UNSAFE_INC} : 1; # prepare
    $CPAN::META-&gt;set_perl5lib;
    local $ENV{MAKEFLAGS}; # protect us from outer make calls

    if ($CPAN::Signal) {
        delete $self-&gt;{force_update};
        return;
    }

    my $builddir = $self-&gt;dir or
        $CPAN::Frontend-&gt;mydie("PANIC: Cannot determine build directory\n");

    unless (chdir $builddir) {
        $CPAN::Frontend-&gt;mywarn("Couldn't chdir to '$builddir': $!");
        return;
    }

    if ($CPAN::Signal) {
        delete $self-&gt;{force_update};
        return;
    }

    $self-&gt;debug("Changed directory to $builddir") if $CPAN::DEBUG;

    local $ENV{PERL_AUTOINSTALL} = $ENV{PERL_AUTOINSTALL} || '';
    local $ENV{PERL_EXTUTILS_AUTOINSTALL} = $ENV{PERL_EXTUTILS_AUTOINSTALL} || '';
    $self-&gt;choose_MM_or_MB
        or return;

    my $configurator = $self-&gt;{configure} ? "Configure"
                     : $self-&gt;{modulebuild} ? "Build.PL"
                     : "Makefile.PL";

    $CPAN::Frontend-&gt;myprint("Configuring ".$self-&gt;id." with $configurator\n");

    if ($CPAN::Config-&gt;{prerequisites_policy} eq "follow") {
        $ENV{PERL_AUTOINSTALL}          ||= "--defaultdeps";
        $ENV{PERL_EXTUTILS_AUTOINSTALL} ||= "--defaultdeps";
    }

    my $system;
    my $pl_commandline;
    if ($self-&gt;prefs-&gt;{pl}) {
        $pl_commandline = $self-&gt;prefs-&gt;{pl}{commandline};
    }
    local $ENV{PERL} = defined $ENV{PERL}? $ENV{PERL} : $^X;
    local $ENV{PERL5_CPAN_IS_EXECUTING} = $ENV{PERL5_CPAN_IS_EXECUTING} || '';
    local $ENV{PERL_MM_USE_DEFAULT} = 1 if $CPAN::Config-&gt;{use_prompt_default};
    local $ENV{NONINTERACTIVE_TESTING} = 1 if $CPAN::Config-&gt;{use_prompt_default};
    if ($pl_commandline) {
        $system = $pl_commandline;
        $ENV{PERL} = $^X;
    } elsif ($self-&gt;{'configure'}) {
        $system = $self-&gt;{'configure'};
    } elsif ($self-&gt;{modulebuild}) {
        my($perl) = $self-&gt;perl or die "Couldn\'t find executable perl\n";
        my $mbuildpl_arg = $self-&gt;_make_phase_arg("pl");
        $system = sprintf("%s Build.PL%s",
                          $perl,
                          $mbuildpl_arg ? " $mbuildpl_arg" : "",
                         );
    } else {
        my($perl) = $self-&gt;perl or die "Couldn\'t find executable perl\n";
        my $switch = "";
# This needs a handler that can be turned on or off:
#        $switch = "-MExtUtils::MakeMaker ".
#            "-Mops=:default,:filesys_read,:filesys_open,require,chdir"
#            if $] &gt; 5.00310;
        my $makepl_arg = $self-&gt;_make_phase_arg("pl");
        $ENV{PERL5_CPAN_IS_EXECUTING} = File::Spec-&gt;catfile($self-&gt;{build_dir},
                                                            "Makefile.PL");
        $system = sprintf("%s%s Makefile.PL%s",
                          $perl,
                          $switch ? " $switch" : "",
                          $makepl_arg ? " $makepl_arg" : "",
                         );
    }
    my $pl_env;
    if ($self-&gt;prefs-&gt;{pl}) {
        $pl_env = $self-&gt;prefs-&gt;{pl}{env};
    }
    local @ENV{keys %$pl_env} = values %$pl_env if $pl_env;
    if (exists $self-&gt;{writemakefile}) {
    } else {
        local($SIG{ALRM}) = sub { die "inactivity_timeout reached\n" };
        my($ret,$pid,$output);
        $@ = "";
        my $go_via_alarm;
        if ($CPAN::Config-&gt;{inactivity_timeout}) {
            require Config;
            if ($Config::Config{d_alarm}
                &amp;&amp;
                $Config::Config{d_alarm} eq "define"
               ) {
                $go_via_alarm++
            } else {
                $CPAN::Frontend-&gt;mywarn("Warning: you have configured the config ".
                                        "variable 'inactivity_timeout' to ".
                                        "'$CPAN::Config-&gt;{inactivity_timeout}'. But ".
                                        "on this machine the system call 'alarm' ".
                                        "isn't available. This means that we cannot ".
                                        "provide the feature of intercepting long ".
                                        "waiting code and will turn this feature off.\n"
                                       );
                $CPAN::Config-&gt;{inactivity_timeout} = 0;
            }
        }
        if ($go_via_alarm) {
            if ( $self-&gt;_should_report('pl') ) {
                ($output, $ret) = CPAN::Reporter::record_command(
                    $system,
                    $CPAN::Config-&gt;{inactivity_timeout},
                );
                CPAN::Reporter::grade_PL( $self, $system, $output, $ret );
            }
            else {
                eval {
                    alarm $CPAN::Config-&gt;{inactivity_timeout};
                    local $SIG{CHLD}; # = sub { wait };
                    if (defined($pid = fork)) {
                        if ($pid) { #parent
                            # wait;
                            waitpid $pid, 0;
                        } else {    #child
                            # note, this exec isn't necessary if
                            # inactivity_timeout is 0. On the Mac I'd
                            # suggest, we set it always to 0.
                            exec $system;
                        }
                    } else {
                        $CPAN::Frontend-&gt;myprint("Cannot fork: $!");
                        return;
                    }
                };
                alarm 0;
                if ($@) {
                    kill 9, $pid;
                    waitpid $pid, 0;
                    my $err = "$@";
                    $CPAN::Frontend-&gt;myprint($err);
                    $self-&gt;{writemakefile} = CPAN::Distrostatus-&gt;new("NO $err");
                    $@ = "";
                    $self-&gt;store_persistent_state;
                    return $self-&gt;goodbye("$system -- TIMED OUT");
                }
            }
        } else {
            if (my $expect_model = $self-&gt;_prefs_with_expect("pl")) {
                # XXX probably want to check _should_report here and warn
                # about not being able to use CPAN::Reporter with expect
                $ret = $self-&gt;_run_via_expect($system,'writemakefile',$expect_model);
                if (! defined $ret
                    &amp;&amp; $self-&gt;{writemakefile}
                    &amp;&amp; $self-&gt;{writemakefile}-&gt;failed) {
                    # timeout
                    return;
                }
            }
            elsif ( $self-&gt;_should_report('pl') ) {
                ($output, $ret) = eval { CPAN::Reporter::record_command($system) };
                if (! defined $output or $@) {
                    my $err = $@ || "Unknown error";
                    $CPAN::Frontend-&gt;mywarn("Error while running PL phase: $err");
                    return $self-&gt;goodbye("$system -- NOT OK");
                }
                CPAN::Reporter::grade_PL( $self, $system, $output, $ret );
            }
            else {
                $ret = system($system);
            }
            if ($ret != 0) {
                $self-&gt;{writemakefile} = CPAN::Distrostatus
                    -&gt;new("NO '$system' returned status $ret");
                $CPAN::Frontend-&gt;mywarn("Warning: No success on command[$system]\n");
                $self-&gt;store_persistent_state;
                return $self-&gt;goodbye("$system -- NOT OK");
            }
        }
        if (-f "Makefile" || -f "Build" || ($^O eq 'VMS' &amp;&amp; (-f 'descrip.mms' || -f 'Build.com'))) {
            $self-&gt;{writemakefile} = CPAN::Distrostatus-&gt;new("YES");
            delete $self-&gt;{make_clean}; # if cleaned before, enable next
            $self-&gt;store_persistent_state;
            return $self-&gt;success("$system -- OK");
        } else {
            my $makefile = $self-&gt;{modulebuild} ? "Build" : "Makefile";
            my $why = "No '$makefile' created";
            $CPAN::Frontend-&gt;mywarn($why);
            $self-&gt;{writemakefile} = CPAN::Distrostatus
                -&gt;new(qq{NO -- $why\n});
            $self-&gt;store_persistent_state;
            return $self-&gt;goodbye("$system -- NOT OK");
        }
    }
    $self-&gt;store_persistent_state;
    return 1; # success
}

#-&gt; sub CPAN::Distribution::shortcut_make ;
# return values: undef means don't shortcut; 0 means shortcut as fail;
# and 1 means shortcut as success
sub shortcut_make {
    my ($self) = @_;

    $self-&gt;debug("checking make/build results[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (defined $self-&gt;{make}) {
        if (UNIVERSAL::can($self-&gt;{make},"failed") ?
            $self-&gt;{make}-&gt;failed :
            $self-&gt;{make} =~ /^NO/
        ) {
            if ($self-&gt;{force_update}) {
                # Trying an already failed 'make' (unless somebody else blocks)
                return undef; # no shortcut
            } else {
                # introduced for turning recursion detection into a distrostatus
                my $error = length $self-&gt;{make}&gt;3
                    ? substr($self-&gt;{make},3) : "Unknown error";
                $self-&gt;store_persistent_state;
                return $self-&gt;goodbye("Could not make: $error\n");
            }
        } else {
            return $self-&gt;success("Has already been made")
        }
    }
    return undef; # no shortcut
}

#-&gt; sub CPAN::Distribution::make ;
sub make {
    my($self) = @_;

    $self-&gt;pre_make();

    $self-&gt;debug("checking goto id[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (my $goto = $self-&gt;prefs-&gt;{goto}) {
        return $self-&gt;goto($goto);
    }
    # Emergency brake if they said install Pippi and get newest perl

    # XXX Would this make more sense in shortcut_prepare, since
    # that doesn't make sense on a perl dist either?  Broader
    # question: what is the purpose of suggesting force install
    # on a perl distribution?  That seems unlikely to result in
    # such a dependency being satisfied, even if the perl is
    # successfully installed.  This situation is tantamount to
    # a prereq on a version of perl greater than the current one
    # so I think we should just abort. -- xdg, 2012-04-06
    if ($self-&gt;isa_perl) {
        if (
            $self-&gt;called_for ne $self-&gt;id &amp;&amp;
            ! $self-&gt;{force_update}
        ) {
            # if we die here, we break bundles
            $CPAN::Frontend
                -&gt;mywarn(sprintf(
                            qq{The most recent version "%s" of the module "%s"
is part of the perl-%s distribution. To install that, you need to run
  force install %s   --or--
  install %s
},
                             $CPAN::META-&gt;instance(
                                                   'CPAN::Module',
                                                   $self-&gt;called_for
                                                  )-&gt;cpan_version,
                             $self-&gt;called_for,
                             $self-&gt;isa_perl,
                             $self-&gt;called_for,
                             $self-&gt;pretty_id,
                            ));
            $self-&gt;{make} = CPAN::Distrostatus-&gt;new("NO isa perl");
            $CPAN::Frontend-&gt;mysleep(1);
            return;
        }
    }

    $self-&gt;prepare
        or return;

    if ( defined( my $sc = $self-&gt;shortcut_make) ) {
        return $sc;
    }

    if ($CPAN::Signal) {
        delete $self-&gt;{force_update};
        return;
    }

    my $builddir = $self-&gt;dir or
        $CPAN::Frontend-&gt;mydie("PANIC: Cannot determine build directory\n");

    unless (chdir $builddir) {
        $CPAN::Frontend-&gt;mywarn("Couldn't chdir to '$builddir': $!");
        return;
    }

    my $make = $self-&gt;{modulebuild} ? "Build" : "make";
    $CPAN::Frontend-&gt;myprint(sprintf "Running %s for %s\n", $make, $self-&gt;id);
    local $ENV{PERL5LIB} = defined($ENV{PERL5LIB})
                           ? $ENV{PERL5LIB}
                           : ($ENV{PERLLIB} || "");
    local $ENV{PERL5OPT} = defined $ENV{PERL5OPT} ? $ENV{PERL5OPT} : "";
    local $ENV{PERL_USE_UNSAFE_INC} = exists $ENV{PERL_USE_UNSAFE_INC} ? $ENV{PERL_USE_UNSAFE_INC} : 1; # make
    $CPAN::META-&gt;set_perl5lib;
    local $ENV{MAKEFLAGS}; # protect us from outer make calls

    if ($CPAN::Signal) {
        delete $self-&gt;{force_update};
        return;
    }

    if ($^O eq 'MacOS') {
        Mac::BuildTools::make($self);
        return;
    }

    my %env;
    while (my($k,$v) = each %ENV) {
        next if defined $v;
        $env{$k} = '';
    }
    local @ENV{keys %env} = values %env;
    my $satisfied = eval { $self-&gt;satisfy_requires };
    return $self-&gt;goodbye($@) if $@;
    return unless $satisfied ;
    if ($CPAN::Signal) {
        delete $self-&gt;{force_update};
        return;
    }

    # need to chdir again, because $self-&gt;satisfy_requires might change the directory
    unless (chdir $builddir) {
        $CPAN::Frontend-&gt;mywarn("Couldn't chdir to '$builddir': $!");
        return;
    }

    my $system;
    my $make_commandline;
    if ($self-&gt;prefs-&gt;{make}) {
        $make_commandline = $self-&gt;prefs-&gt;{make}{commandline};
    }
    local $ENV{PERL} = defined $ENV{PERL}? $ENV{PERL} : $^X;
    local $ENV{PERL_MM_USE_DEFAULT} = 1 if $CPAN::Config-&gt;{use_prompt_default};
    local $ENV{NONINTERACTIVE_TESTING} = 1 if $CPAN::Config-&gt;{use_prompt_default};
    if ($make_commandline) {
        $system = $make_commandline;
        $ENV{PERL} = CPAN::find_perl();
    } else {
        if ($self-&gt;{modulebuild}) {
            unless (-f "Build" || ($^O eq 'VMS' &amp;&amp; -f 'Build.com')) {
                my $cwd = CPAN::anycwd();
                $CPAN::Frontend-&gt;mywarn("Alert: no Build file available for 'make $self-&gt;{id}'".
                                        " in cwd[$cwd]. Danger, Will Robinson!\n");
                $CPAN::Frontend-&gt;mysleep(5);
            }
            $system = join " ", $self-&gt;_build_command(), $CPAN::Config-&gt;{mbuild_arg};
        } else {
            $system = join " ", $self-&gt;_make_command(),  $CPAN::Config-&gt;{make_arg};
        }
        $system =~ s/\s+$//;
        my $make_arg = $self-&gt;_make_phase_arg("make");
        $system = sprintf("%s%s",
                          $system,
                          $make_arg ? " $make_arg" : "",
                         );
    }
    my $make_env;
    if ($self-&gt;prefs-&gt;{make}) {
        $make_env = $self-&gt;prefs-&gt;{make}{env};
    }
    local @ENV{keys %$make_env} = values %$make_env if $make_env;
    my $expect_model = $self-&gt;_prefs_with_expect("make");
    my $want_expect = 0;
    if ( $expect_model &amp;&amp; @{$expect_model-&gt;{talk}} ) {
        my $can_expect = $CPAN::META-&gt;has_inst("Expect");
        if ($can_expect) {
            $want_expect = 1;
        } else {
            $CPAN::Frontend-&gt;mywarn("Expect not installed, falling back to ".
                                    "system()\n");
        }
    }
    my ($system_ok, $system_err);
    if ($want_expect) {
        # XXX probably want to check _should_report here and
        # warn about not being able to use CPAN::Reporter with expect
        $system_ok = $self-&gt;_run_via_expect($system,'make',$expect_model) == 0;
    }
    elsif ( $self-&gt;_should_report('make') ) {
        my ($output, $ret) = CPAN::Reporter::record_command($system);
        CPAN::Reporter::grade_make( $self, $system, $output, $ret );
        $system_ok = ! $ret;
    }
    else {
        my $rc = system($system);
        $system_ok = $rc == 0;
        $system_err = $! if $rc == -1;
    }
    $self-&gt;introduce_myself;
    if ( $system_ok ) {
        $CPAN::Frontend-&gt;myprint("  $system -- OK\n");
        $self-&gt;{make} = CPAN::Distrostatus-&gt;new("YES");
    } else {
        $self-&gt;{writemakefile} ||= CPAN::Distrostatus-&gt;new("YES");
        $self-&gt;{make} = CPAN::Distrostatus-&gt;new("NO");
        $CPAN::Frontend-&gt;mywarn("  $system -- NOT OK\n");
        $CPAN::Frontend-&gt;mywarn("  $system_err\n") if defined $system_err;
    }
    $self-&gt;store_persistent_state;

    $self-&gt;post_make();

    return !! $system_ok;
}

# CPAN::Distribution::goodbye ;
sub goodbye {
    my($self,$goodbye) = @_;
    my $id = $self-&gt;pretty_id;
    $CPAN::Frontend-&gt;mywarn("  $id\n  $goodbye\n");
    return 0; # must be explicit false, not undef
}

sub success {
    my($self,$why) = @_;
    my $id = $self-&gt;pretty_id;
    $CPAN::Frontend-&gt;myprint("  $id\n  $why\n");
    return 1;
}

# CPAN::Distribution::_run_via_expect ;
sub _run_via_expect {
    my($self,$system,$phase,$expect_model) = @_;
    CPAN-&gt;debug("system[$system]expect_model[$expect_model]") if $CPAN::DEBUG;
    if ($CPAN::META-&gt;has_inst("Expect")) {
        my $expo = Expect-&gt;new;  # expo Expect object;
        $expo-&gt;spawn($system);
        $expect_model-&gt;{mode} ||= "deterministic";
        if ($expect_model-&gt;{mode} eq "deterministic") {
            return $self-&gt;_run_via_expect_deterministic($expo,$phase,$expect_model);
        } elsif ($expect_model-&gt;{mode} eq "anyorder") {
            return $self-&gt;_run_via_expect_anyorder($expo,$phase,$expect_model);
        } else {
            die "Panic: Illegal expect mode: $expect_model-&gt;{mode}";
        }
    } else {
        $CPAN::Frontend-&gt;mywarn("Expect not installed, falling back to system()\n");
        return system($system);
    }
}

sub _run_via_expect_anyorder {
    my($self,$expo,$phase,$expect_model) = @_;
    my $timeout = $expect_model-&gt;{timeout} || 5;
    my $reuse = $expect_model-&gt;{reuse};
    my @expectacopy = @{$expect_model-&gt;{talk}}; # we trash it!
    my $but = "";
    my $timeout_start = time;
  EXPECT: while () {
        my($eof,$ran_into_timeout);
        # XXX not up to the full power of expect. one could certainly
        # wrap all of the talk pairs into a single expect call and on
        # success tweak it and step ahead to the next question. The
        # current implementation unnecessarily limits itself to a
        # single match.
        my @match = $expo-&gt;expect(1,
                                  [ eof =&gt; sub {
                                        $eof++;
                                    } ],
                                  [ timeout =&gt; sub {
                                        $ran_into_timeout++;
                                    } ],
                                  -re =&gt; eval"qr{.}",
                                 );
        if ($match[2]) {
            $but .= $match[2];
        }
        $but .= $expo-&gt;clear_accum;
        if ($eof) {
            $expo-&gt;soft_close;
            return $expo-&gt;exitstatus();
        } elsif ($ran_into_timeout) {
            # warn "DEBUG: they are asking a question, but[$but]";
            for (my $i = 0; $i &lt;= $#expectacopy; $i+=2) {
                my($next,$send) = @expectacopy[$i,$i+1];
                my $regex = eval "qr{$next}";
                # warn "DEBUG: will compare with regex[$regex].";
                if ($but =~ /$regex/) {
                    # warn "DEBUG: will send send[$send]";
                    $expo-&gt;send($send);
                    # never allow reusing an QA pair unless they told us
                    splice @expectacopy, $i, 2 unless $reuse;
                    $but =~ s/(?s:^.*?)$regex//;
                    $timeout_start = time;
                    next EXPECT;
                }
            }
            my $have_waited = time - $timeout_start;
            if ($have_waited &lt; $timeout) {
                # warn "DEBUG: have_waited[$have_waited]timeout[$timeout]";
                next EXPECT;
            }
            my $why = "could not answer a question during the dialog";
            $CPAN::Frontend-&gt;mywarn("Failing: $why\n");
            $self-&gt;{$phase} =
                CPAN::Distrostatus-&gt;new("NO $why");
            return 0;
        }
    }
}

sub _run_via_expect_deterministic {
    my($self,$expo,$phase,$expect_model) = @_;
    my $ran_into_timeout;
    my $ran_into_eof;
    my $timeout = $expect_model-&gt;{timeout} || 15; # currently unsettable
    my $expecta = $expect_model-&gt;{talk};
  EXPECT: for (my $i = 0; $i &lt;= $#$expecta; $i+=2) {
        my($re,$send) = @$expecta[$i,$i+1];
        CPAN-&gt;debug("timeout[$timeout]re[$re]") if $CPAN::DEBUG;
        my $regex = eval "qr{$re}";
        $expo-&gt;expect($timeout,
                      [ eof =&gt; sub {
                            my $but = $expo-&gt;clear_accum;
                            $CPAN::Frontend-&gt;mywarn("EOF (maybe harmless)
expected[$regex]\nbut[$but]\n\n");
                            $ran_into_eof++;
                        } ],
                      [ timeout =&gt; sub {
                            my $but = $expo-&gt;clear_accum;
                            $CPAN::Frontend-&gt;mywarn("TIMEOUT
expected[$regex]\nbut[$but]\n\n");
                            $ran_into_timeout++;
                        } ],
                      -re =&gt; $regex);
        if ($ran_into_timeout) {
            # note that the caller expects 0 for success
            $self-&gt;{$phase} =
                CPAN::Distrostatus-&gt;new("NO timeout during expect dialog");
            return 0;
        } elsif ($ran_into_eof) {
            last EXPECT;
        }
        $expo-&gt;send($send);
    }
    $expo-&gt;soft_close;
    return $expo-&gt;exitstatus();
}

#-&gt; CPAN::Distribution::_validate_distropref
sub _validate_distropref {
    my($self,@args) = @_;
    if (
        $CPAN::META-&gt;has_inst("CPAN::Kwalify")
        &amp;&amp;
        $CPAN::META-&gt;has_inst("Kwalify")
       ) {
        eval {CPAN::Kwalify::_validate("distroprefs",@args);};
        if ($@) {
            $CPAN::Frontend-&gt;mywarn($@);
        }
    } else {
        CPAN-&gt;debug("not validating '@args'") if $CPAN::DEBUG;
    }
}

#-&gt; CPAN::Distribution::_find_prefs
sub _find_prefs {
    my($self) = @_;
    my $distroid = $self-&gt;pretty_id;
    #CPAN-&gt;debug("distroid[$distroid]") if $CPAN::DEBUG;
    my $prefs_dir = $CPAN::Config-&gt;{prefs_dir};
    return if $prefs_dir =~ /^\s*$/;
    eval { File::Path::mkpath($prefs_dir); };
    if ($@) {
        $CPAN::Frontend-&gt;mydie("Cannot create directory $prefs_dir");
    }
    # shortcut if there are no distroprefs files
    {
      my $dh = DirHandle-&gt;new($prefs_dir) or $CPAN::Frontend-&gt;mydie("Couldn't open '$prefs_dir': $!");
      my @files = map { /\.(yml|dd|st)\z/i } $dh-&gt;read;
      return unless @files;
    }
    my $yaml_module = CPAN::_yaml_module();
    my $ext_map = {};
    my @extensions;
    if ($CPAN::META-&gt;has_inst($yaml_module)) {
        $ext_map-&gt;{yml} = 'CPAN';
    } else {
        my @fallbacks;
        if ($CPAN::META-&gt;has_inst("Data::Dumper")) {
            push @fallbacks, $ext_map-&gt;{dd} = 'Data::Dumper';
        }
        if ($CPAN::META-&gt;has_inst("Storable")) {
            push @fallbacks, $ext_map-&gt;{st} = 'Storable';
        }
        if (@fallbacks) {
            local $" = " and ";
            unless ($self-&gt;{have_complained_about_missing_yaml}++) {
                $CPAN::Frontend-&gt;mywarnonce("'$yaml_module' not installed, falling back ".
                                            "to @fallbacks to read prefs '$prefs_dir'\n");
            }
        } else {
            unless ($self-&gt;{have_complained_about_missing_yaml}++) {
                $CPAN::Frontend-&gt;mywarnonce("'$yaml_module' not installed, cannot ".
                                            "read prefs '$prefs_dir'\n");
            }
        }
    }
    my $finder = CPAN::Distroprefs-&gt;find($prefs_dir, $ext_map);
    DIRENT: while (my $result = $finder-&gt;next) {
        if ($result-&gt;is_warning) {
            $CPAN::Frontend-&gt;mywarn($result-&gt;as_string);
            $CPAN::Frontend-&gt;mysleep(1);
            next DIRENT;
        } elsif ($result-&gt;is_fatal) {
            $CPAN::Frontend-&gt;mydie($result-&gt;as_string);
        }

        my @prefs = @{ $result-&gt;prefs };

      ELEMENT: for my $y (0..$#prefs) {
            my $pref = $prefs[$y];
            $self-&gt;_validate_distropref($pref-&gt;data, $result-&gt;abs, $y);

            # I don't know why we silently skip when there's no match, but
            # complain if there's an empty match hashref, and there's no
            # comment explaining why -- hdp, 2008-03-18
            unless ($pref-&gt;has_any_match) {
                next ELEMENT;
            }

            unless ($pref-&gt;has_valid_subkeys) {
                $CPAN::Frontend-&gt;mydie(sprintf
                    "Nonconforming .%s file '%s': " .
                    "missing match/* subattribute. " .
                    "Please remove, cannot continue.",
                    $result-&gt;ext, $result-&gt;abs,
                );
            }

            my $arg = {
                env          =&gt; \%ENV,
                distribution =&gt; $distroid,
                perl         =&gt; \&amp;CPAN::find_perl,
                perlconfig   =&gt; \%Config::Config,
                module       =&gt; sub { [ $self-&gt;containsmods ] },
            };

            if ($pref-&gt;matches($arg)) {
                return {
                    prefs =&gt; $pref-&gt;data,
                    prefs_file =&gt; $result-&gt;abs,
                    prefs_file_doc =&gt; $y,
                };
            }

        }
    }
    return;
}

# CPAN::Distribution::prefs
sub prefs {
    my($self) = @_;
    if (exists $self-&gt;{negative_prefs_cache}
        &amp;&amp;
        $self-&gt;{negative_prefs_cache} != $CPAN::CurrentCommandId
       ) {
        delete $self-&gt;{negative_prefs_cache};
        delete $self-&gt;{prefs};
    }
    if (exists $self-&gt;{prefs}) {
        return $self-&gt;{prefs}; # XXX comment out during debugging
    }
    if ($CPAN::Config-&gt;{prefs_dir}) {
        CPAN-&gt;debug("prefs_dir[$CPAN::Config-&gt;{prefs_dir}]") if $CPAN::DEBUG;
        my $prefs = $self-&gt;_find_prefs();
        $prefs ||= ""; # avoid warning next line
        CPAN-&gt;debug("prefs[$prefs]") if $CPAN::DEBUG;
        if ($prefs) {
            for my $x (qw(prefs prefs_file prefs_file_doc)) {
                $self-&gt;{$x} = $prefs-&gt;{$x};
            }
            my $bs = sprintf(
                             "%s[%s]",
                             File::Basename::basename($self-&gt;{prefs_file}),
                             $self-&gt;{prefs_file_doc},
                            );
            my $filler1 = "_" x 22;
            my $filler2 = int(66 - length($bs))/2;
            $filler2 = 0 if $filler2 &lt; 0;
            $filler2 = " " x $filler2;
            $CPAN::Frontend-&gt;myprint("
$filler1 D i s t r o P r e f s $filler1
$filler2 $bs $filler2
");
            $CPAN::Frontend-&gt;mysleep(1);
            return $self-&gt;{prefs};
        }
    }
    $self-&gt;{negative_prefs_cache} = $CPAN::CurrentCommandId;
    return $self-&gt;{prefs} = +{};
}

# CPAN::Distribution::_make_phase_arg
sub _make_phase_arg {
    my($self, $phase) = @_;
    my $_make_phase_arg;
    my $prefs = $self-&gt;prefs;
    if (
        $prefs
        &amp;&amp; exists $prefs-&gt;{$phase}
        &amp;&amp; exists $prefs-&gt;{$phase}{args}
        &amp;&amp; $prefs-&gt;{$phase}{args}
       ) {
        $_make_phase_arg = join(" ",
                           map {CPAN::HandleConfig
                                 -&gt;safe_quote($_)} @{$prefs-&gt;{$phase}{args}},
                          );
    }

# cpan[2]&gt; o conf make[TAB]
# make                       make_install_make_command
# make_arg                   makepl_arg
# make_install_arg
# cpan[2]&gt; o conf mbuild[TAB]
# mbuild_arg                    mbuild_install_build_command
# mbuild_install_arg            mbuildpl_arg

    my $mantra; # must switch make/mbuild here
    if ($self-&gt;{modulebuild}) {
        $mantra = "mbuild";
    } else {
        $mantra = "make";
    }
    my %map = (
               pl =&gt; "pl_arg",
               make =&gt; "_arg",
               test =&gt; "_test_arg", # does not really exist but maybe
                                    # will some day and now protects
                                    # us from unini warnings
               install =&gt; "_install_arg",
              );
    my $phase_underscore_meshup = $map{$phase};
    my $what = sprintf "%s%s", $mantra, $phase_underscore_meshup;

    $_make_phase_arg ||= $CPAN::Config-&gt;{$what};
    return $_make_phase_arg;
}

# CPAN::Distribution::_make_command
sub _make_command {
    my ($self) = @_;
    if ($self) {
        return
            CPAN::HandleConfig
                -&gt;safe_quote(
                             CPAN::HandleConfig-&gt;prefs_lookup($self,
                                                              q{make})
                             || $Config::Config{make}
                             || 'make'
                            );
    } else {
        # Old style call, without object. Deprecated
        Carp::confess("CPAN::_make_command() used as function. Don't Do That.");
        return
          safe_quote(undef,
                     CPAN::HandleConfig-&gt;prefs_lookup($self,q{make})
                     || $CPAN::Config-&gt;{make}
                     || $Config::Config{make}
                     || 'make');
    }
}

sub _make_install_make_command {
    my ($self) = @_;
    my $mimc =
        CPAN::HandleConfig-&gt;prefs_lookup($self, q{make_install_make_command});
    return $self-&gt;_make_command() unless $mimc;

    # Quote the "make install" make command on Windows, where it is commonly
    # found in, e.g., C:\Program Files\... and therefore needs quoting. We can't
    # do this in general because the command maybe "sudo make..." (i.e. a
    # program with arguments), but that is unlikely to be the case on Windows.
    $mimc = CPAN::HandleConfig-&gt;safe_quote($mimc) if $^O eq 'MSWin32';

    return $mimc;
}

#-&gt; sub CPAN::Distribution::is_locally_optional
sub is_locally_optional {
    my($self, $prereq_pm, $prereq) = @_;
    $prereq_pm ||= $self-&gt;{prereq_pm};
    my($nmo,$opt);
    for my $rt (qw(requires build_requires)) {
        if (exists $prereq_pm-&gt;{$rt}{$prereq}) {
            # rt 121914
            $nmo ||= $CPAN::META-&gt;instance("CPAN::Module",$prereq);
            my $av = $nmo-&gt;available_version;
            return 0 if !$av || CPAN::Version-&gt;vlt($av,$prereq_pm-&gt;{$rt}{$prereq});
        }
        if (exists $prereq_pm-&gt;{"opt_$rt"}{$prereq}) {
            $opt = 1;
        }
    }
    return $opt||0;
}

#-&gt; sub CPAN::Distribution::follow_prereqs ;
sub follow_prereqs {
    my($self) = shift;
    my($slot) = shift;
    my(@prereq_tuples) = grep {$_-&gt;[0] ne "perl"} @_;
    return unless @prereq_tuples;
    my(@good_prereq_tuples);
    for my $p (@prereq_tuples) {
        # e.g. $p = ['Devel::PartialDump', 'r', 1]
        # promote if possible
        if ($p-&gt;[1] =~ /^(r|c)$/) {
            push @good_prereq_tuples, $p;
        } elsif ($p-&gt;[1] =~ /^(b)$/) {
            my $reqtype = CPAN::Queue-&gt;reqtype_of($p-&gt;[0]);
            if ($reqtype =~ /^(r|c)$/) {
                push @good_prereq_tuples, [$p-&gt;[0], $reqtype, $p-&gt;[2]];
            } else {
                push @good_prereq_tuples, $p;
            }
        } else {
            die "Panic: in follow_prereqs: reqtype[$p-&gt;[1]] seen, should never happen";
        }
    }
    my $pretty_id = $self-&gt;pretty_id;
    my %map = (
               b =&gt; "build_requires",
               r =&gt; "requires",
               c =&gt; "commandline",
              );
    my($filler1,$filler2,$filler3,$filler4);
    my $unsat = "Unsatisfied dependencies detected during";
    my $w = length($unsat) &gt; length($pretty_id) ? length($unsat) : length($pretty_id);
    {
        my $r = int(($w - length($unsat))/2);
        my $l = $w - length($unsat) - $r;
        $filler1 = "-"x4 . " "x$l;
        $filler2 = " "x$r . "-"x4 . "\n";
    }
    {
        my $r = int(($w - length($pretty_id))/2);
        my $l = $w - length($pretty_id) - $r;
        $filler3 = "-"x4 . " "x$l;
        $filler4 = " "x$r . "-"x4 . "\n";
    }
    $CPAN::Frontend-&gt;
        myprint("$filler1 $unsat $filler2".
                "$filler3 $pretty_id $filler4".
                join("", map {sprintf "    %s \[%s%s]\n", $_-&gt;[0], $map{$_-&gt;[1]}, $self-&gt;is_locally_optional(undef,$_-&gt;[0]) ? ",optional" : ""} @good_prereq_tuples),
               );
    my $follow = 0;
    if ($CPAN::Config-&gt;{prerequisites_policy} eq "follow") {
        $follow = 1;
    } elsif ($CPAN::Config-&gt;{prerequisites_policy} eq "ask") {
        my $answer = CPAN::Shell::colorable_makemaker_prompt(
"Shall I follow them and prepend them to the queue
of modules we are processing right now?", "yes");
        $follow = $answer =~ /^\s*y/i;
    } else {
        my @prereq = map { $_-&gt;[0] } @good_prereq_tuples;
        local($") = ", ";
        $CPAN::Frontend-&gt;
            myprint("  Ignoring dependencies on modules @prereq\n");
    }
    if ($follow) {
        my $id = $self-&gt;id;
        my(@to_queue_mand,@to_queue_opt);
        for my $gp (@good_prereq_tuples) {
            my($prereq,$reqtype,$optional) = @$gp;
            my $qthing = +{qmod=&gt;$prereq,reqtype=&gt;$reqtype,optional=&gt;$optional};
            if ($optional &amp;&amp;
                $self-&gt;is_locally_optional(undef,$prereq)
               ){
                # Since we do not depend on this one, we do not need
                # this in a mandatory arrangement:
                push @to_queue_opt, $qthing;
            } else {
                my $any = CPAN::Shell-&gt;expandany($prereq);
                $self-&gt;{$slot . "_for"}{$any-&gt;id}++;
                if ($any) {
                    unless ($optional) {
                        # No recursion check in an optional area of the tree
                        $any-&gt;color_cmd_tmps(0,2);
                    }
                } else {
                    $CPAN::Frontend-&gt;mywarn("Warning (maybe a bug): Cannot expand prereq '$prereq'\n");
                    $CPAN::Frontend-&gt;mysleep(2);
                }
                # order everything that is not locally_optional just
                # like mandatory items: this keeps leaves before
                # branches
                unshift @to_queue_mand, $qthing;
            }
        }
        if (@to_queue_mand) {
            unshift @to_queue_mand, {qmod =&gt; $id, reqtype =&gt; $self-&gt;{reqtype}, optional=&gt; !$self-&gt;{mandatory}};
            CPAN::Queue-&gt;jumpqueue(@to_queue_opt,@to_queue_mand);
            $self-&gt;{$slot} = "Delayed until after prerequisites";
            return 1; # signal we need dependencies
        } elsif (@to_queue_opt) {
            CPAN::Queue-&gt;jumpqueue(@to_queue_opt);
        }
    }
    return;
}

sub _feature_depends {
    my($self) = @_;
    my $meta_yml = $self-&gt;parse_meta_yml();
    my $optf = $meta_yml-&gt;{optional_features} or return;
    if (!ref $optf or ref $optf ne "HASH"){
        $CPAN::Frontend-&gt;mywarn("The content of optional_features is not a HASH reference. Cannot use it.\n");
        $optf = {};
    }
    my $wantf = $self-&gt;prefs-&gt;{features} or return;
    if (!ref $wantf or ref $wantf ne "ARRAY"){
        $CPAN::Frontend-&gt;mywarn("The content of 'features' is not an ARRAY reference. Cannot use it.\n");
        $wantf = [];
    }
    my $dep = +{};
    for my $wf (@$wantf) {
        if (my $f = $optf-&gt;{$wf}) {
            $CPAN::Frontend-&gt;myprint("Found the demanded feature '$wf' that ".
                                     "is accompanied by this description:\n".
                                     $f-&gt;{description}.
                                     "\n\n"
                                    );
            # configure_requires currently not in the spec, unlikely to be useful anyway
            for my $reqtype (qw(configure_requires build_requires requires)) {
                my $reqhash = $f-&gt;{$reqtype} or next;
                while (my($k,$v) = each %$reqhash) {
                    $dep-&gt;{$reqtype}{$k} = $v;
                }
            }
        } else {
            $CPAN::Frontend-&gt;mywarn("The demanded feature '$wf' was not ".
                                    "found in the META.yml file".
                                    "\n\n"
                                   );
        }
    }
    $dep;
}

sub prereqs_for_slot {
    my($self,$slot) = @_;
    my($prereq_pm);
    unless ($CPAN::META-&gt;has_usable("CPAN::Meta::Requirements")) {
        my $whynot = "not available";
        if (defined $CPAN::Meta::Requirements::VERSION) {
            $whynot = "version $CPAN::Meta::Requirements::VERSION not sufficient";
        }
        $CPAN::Frontend-&gt;mywarn("CPAN::Meta::Requirements $whynot\n");
        my $before = "";
        if ($self-&gt;{CALLED_FOR}){
            if ($self-&gt;{CALLED_FOR} =~
                /^(
                     CPAN::Meta::Requirements
                 |version
                 |parent
                 |ExtUtils::MakeMaker
                 |Test::Harness
                 )$/x) {
                $CPAN::Frontend-&gt;mywarn("Setting requirements to nil as a workaround\n");
                return;
            }
            $before = " before $self-&gt;{CALLED_FOR}";
        }
        $CPAN::Frontend-&gt;mydie("Please install CPAN::Meta::Requirements manually$before");
    }
    my $merged = CPAN::Meta::Requirements-&gt;new;
    my $prefs_depends = $self-&gt;prefs-&gt;{depends}||{};
    my $feature_depends = $self-&gt;_feature_depends();
    if ($slot eq "configure_requires_later") {
        for my $hash (  $self-&gt;configure_requires,
                        $prefs_depends-&gt;{configure_requires},
                        $feature_depends-&gt;{configure_requires},
        ) {
            $merged-&gt;add_requirements(
                CPAN::Meta::Requirements-&gt;from_string_hash($hash)
            );
        }
        if (-f "Build.PL"
            &amp;&amp; ! -f File::Spec-&gt;catfile($self-&gt;{build_dir},"Makefile.PL")
            &amp;&amp; ! $merged-&gt;requirements_for_module("Module::Build")
            &amp;&amp; ! $CPAN::META-&gt;has_inst("Module::Build")
           ) {
            $CPAN::Frontend-&gt;mywarn(
              "  Warning: CPAN.pm discovered Module::Build as undeclared prerequisite.\n".
              "  Adding it now as such.\n"
            );
            $CPAN::Frontend-&gt;mysleep(5);
            $merged-&gt;add_minimum( "Module::Build" =&gt; 0 );
            delete $self-&gt;{writemakefile};
        }
        $prereq_pm = {}; # configure_requires defined as "b"
    } elsif ($slot eq "later") {
        my $prereq_pm_0 = $self-&gt;prereq_pm || {};
        for my $reqtype (qw(requires build_requires opt_requires opt_build_requires)) {
            $prereq_pm-&gt;{$reqtype} = {%{$prereq_pm_0-&gt;{$reqtype}||{}}}; # copy to not pollute it
            for my $dep ($prefs_depends,$feature_depends) {
                for my $k (keys %{$dep-&gt;{$reqtype}||{}}) {
                    $prereq_pm-&gt;{$reqtype}{$k} = $dep-&gt;{$reqtype}{$k};
                }
            }
        }
        # XXX what about optional_req|breq? -- xdg, 2012-04-01
        for my $hash (
            $prereq_pm-&gt;{requires},
            $prereq_pm-&gt;{build_requires},
            $prereq_pm-&gt;{opt_requires},
            $prereq_pm-&gt;{opt_build_requires},

        ) {
            $merged-&gt;add_requirements(
                CPAN::Meta::Requirements-&gt;from_string_hash($hash)
            );
        }
    } else {
        die "Panic: illegal slot '$slot'";
    }
    return ($merged-&gt;as_string_hash, $prereq_pm);
}

#-&gt; sub CPAN::Distribution::unsat_prereq ;
# return ([Foo,"r"],[Bar,"b"]) for normal modules
# return ([perl=&gt;5.008]) if we need a newer perl than we are running under
# (sorry for the inconsistency, it was an accident)
sub unsat_prereq {
    my($self,$slot) = @_;
    my($merged_hash,$prereq_pm) = $self-&gt;prereqs_for_slot($slot);
    my(@need);
    unless ($CPAN::META-&gt;has_usable("CPAN::Meta::Requirements")) {
        $CPAN::Frontend-&gt;mywarn("CPAN::Meta::Requirements not available, please install as soon as possible, trying to continue with severly limited capabilities\n");
        return;
    }
    my $merged = CPAN::Meta::Requirements-&gt;from_string_hash($merged_hash);
    my @merged = sort $merged-&gt;required_modules;
    CPAN-&gt;debug("all merged_prereqs[@merged]") if $CPAN::DEBUG;
  NEED: for my $need_module ( @merged ) {
        my $need_version = $merged-&gt;requirements_for_module($need_module);
        my($available_version,$inst_file,$available_file,$nmo);
        if ($need_module eq "perl") {
            $available_version = $];
            $available_file = CPAN::find_perl();
        } else {
            if (CPAN::_sqlite_running()) {
                CPAN::Index-&gt;reload;
                $CPAN::SQLite-&gt;search("CPAN::Module",$need_module);
            }
            $nmo = $CPAN::META-&gt;instance("CPAN::Module",$need_module);
            $inst_file = $nmo-&gt;inst_file || '';
            $available_file = $nmo-&gt;available_file || '';
            $available_version = $nmo-&gt;available_version;
            if ($nmo-&gt;uptodate) {
                my $accepts = eval {
                    $merged-&gt;accepts_module($need_module, $available_version);
                };
                unless ($accepts) {
                    my $rq = $merged-&gt;requirements_for_module( $need_module );
                    $CPAN::Frontend-&gt;mywarn(
                        "Warning: Version '$available_version' of ".
                        "'$need_module' is up to date but does not ".
                        "fulfill requirements ($rq). I will continue, ".
                        "but chances to succeed are low.\n");
                }
                next NEED;
            }

            # if they have not specified a version, we accept any
            # installed one; in that case inst_file is always
            # sufficient and available_file is sufficient on
            # both build_requires and configure_requires
            my $sufficient = $inst_file ||
                ( exists $prereq_pm-&gt;{requires}{$need_module} ? 0 : $available_file );
            if ( $sufficient
                and ( # a few quick short circuits
                     not defined $need_version
                     or $need_version eq '0'    # "==" would trigger warning when not numeric
                     or $need_version eq "undef"
                    )) {
                unless ($nmo-&gt;inst_deprecated) {
                    next NEED;
                }
            }
        }

        # We only want to install prereqs if either they're not installed
        # or if the installed version is too old. We cannot omit this
        # check, because if 'force' is in effect, nobody else will check.
        # But we don't want to accept a deprecated module installed as part
        # of the Perl core, so we continue if the available file is the installed
        # one and is deprecated

        if ( $available_file ) {
            my $fulfills_all_version_rqs = $self-&gt;_fulfills_all_version_rqs
                (
                 $need_module,
                 $available_file,
                 $available_version,
                 $need_version,
                );
            if ( $inst_file
                       &amp;&amp; $available_file eq $inst_file
                       &amp;&amp; $nmo-&gt;inst_deprecated
                     ) {
                # continue installing as a prereq. we really want that
                # because the deprecated module may spit out warnings
                # and third party did not know until today. Only one
                # exception is OK, because CPANPLUS is special after
                # all:
                if ( $fulfills_all_version_rqs and
                     $nmo-&gt;id =~ /^CPANPLUS(?:::Dist::Build)$/
                   ) {
                    # here we have an available version that is good
                    # enough although deprecated (preventing circular
                    # loop CPANPLUS =&gt; CPANPLUS::Dist::Build RT#83042)
                    next NEED;
                }
            } elsif (
                $self-&gt;{reqtype} =~ /^(r|c)$/
                &amp;&amp; (   exists $prereq_pm-&gt;{requires}{$need_module}
                    || exists $prereq_pm-&gt;{opt_requires}{$need_module} )
                &amp;&amp; $nmo
                &amp;&amp; !$inst_file
            ) {
                # continue installing as a prereq; this may be a
                # distro we already used when it was a build_requires
                # so we did not install it. But suddenly somebody
                # wants it as a requires
                my $need_distro = $nmo-&gt;distribution;
                if ($need_distro-&gt;{install} &amp;&amp; $need_distro-&gt;{install}-&gt;failed &amp;&amp; $need_distro-&gt;{install}-&gt;text =~ /is only/) {
                    my $id = $need_distro-&gt;pretty_id;
                    $CPAN::Frontend-&gt;myprint("Promoting $id from build_requires to requires due $need_module\n");
                    delete $need_distro-&gt;{install}; # promote to another installation attempt
                    $need_distro-&gt;{reqtype} = "r";
                    $need_distro-&gt;install;
                    next NEED;
                }
            }
            else {
                next NEED if $fulfills_all_version_rqs;
            }
        }

        if ($need_module eq "perl") {
            return ["perl", $need_version];
        }
        $self-&gt;{sponsored_mods}{$need_module} ||= 0;
        CPAN-&gt;debug("need_module[$need_module]s/s/n[$self-&gt;{sponsored_mods}{$need_module}]") if $CPAN::DEBUG;
        if (my $sponsoring = $self-&gt;{sponsored_mods}{$need_module}++) {
            # We have already sponsored it and for some reason it's still
            # not available. So we do ... what??

            # if we push it again, we have a potential infinite loop

            # The following "next" was a very problematic construct.
            # It helped a lot but broke some day and had to be
            # replaced.

            # We must be able to deal with modules that come again and
            # again as a prereq and have themselves prereqs and the
            # queue becomes long but finally we would find the correct
            # order. The RecursiveDependency check should trigger a
            # die when it's becoming too weird. Unfortunately removing
            # this next breaks many other things.

            # The bug that brought this up is described in Todo under
            # "5.8.9 cannot install Compress::Zlib"

            # next; # this is the next that had to go away

            # The following "next NEED" are fine and the error message
            # explains well what is going on. For example when the DBI
            # fails and consequently DBD::SQLite fails and now we are
            # processing CPAN::SQLite. Then we must have a "next" for
            # DBD::SQLite. How can we get it and how can we identify
            # all other cases we must identify?

            my $do = $nmo-&gt;distribution;
            next NEED unless $do; # not on CPAN
            if (CPAN::Version-&gt;vcmp($need_version, $nmo-&gt;ro-&gt;{CPAN_VERSION}) &gt; 0){
                $CPAN::Frontend-&gt;mywarn("Warning: Prerequisite ".
                                        "'$need_module =&gt; $need_version' ".
                                        "for '$self-&gt;{ID}' seems ".
                                        "not available according to the indices\n"
                                       );
                next NEED;
            }
          NOSAYER: for my $nosayer (
                                    "unwrapped",
                                    "writemakefile",
                                    "signature_verify",
                                    "make",
                                    "make_test",
                                    "install",
                                    "make_clean",
                                   ) {
                if ($do-&gt;{$nosayer}) {
                    my $selfid = $self-&gt;pretty_id;
                    my $did = $do-&gt;pretty_id;
                    if (UNIVERSAL::can($do-&gt;{$nosayer},"failed") ?
                        $do-&gt;{$nosayer}-&gt;failed :
                        $do-&gt;{$nosayer} =~ /^NO/) {
                        if ($nosayer eq "make_test"
                            &amp;&amp;
                            $do-&gt;{make_test}{COMMANDID} != $CPAN::CurrentCommandId
                           ) {
                            next NOSAYER;
                        }
                        ### XXX  don't complain about missing optional deps -- xdg, 2012-04-01
                        if ($self-&gt;is_locally_optional($prereq_pm, $need_module)) {
                            # don't complain about failing optional prereqs
                        }
                        else {
                            $CPAN::Frontend-&gt;mywarn("Warning: Prerequisite ".
                                                    "'$need_module =&gt; $need_version' ".
                                                    "for '$selfid' failed when ".
                                                    "processing '$did' with ".
                                                    "'$nosayer =&gt; $do-&gt;{$nosayer}'. Continuing, ".
                                                    "but chances to succeed are limited.\n"
                                                );
                            $CPAN::Frontend-&gt;mysleep($sponsoring/10);
                        }
                        next NEED;
                    } else { # the other guy succeeded
                        if ($nosayer =~ /^(install|make_test)$/) {
                            # we had this with
                            # DMAKI/DateTime-Calendar-Chinese-0.05.tar.gz
                            # in 2007-03 for 'make install'
                            # and 2008-04: #30464 (for 'make test')
                            # $CPAN::Frontend-&gt;mywarn("Warning: Prerequisite ".
                            #                         "'$need_module =&gt; $need_version' ".
                            #                         "for '$selfid' already built ".
                            #                         "but the result looks suspicious. ".
                            #                         "Skipping another build attempt, ".
                            #                         "to prevent looping endlessly.\n"
                            #                        );
                            next NEED;
                        }
                    }
                }
            }
        }
        my $needed_as;
        if (0) {
        } elsif (exists $prereq_pm-&gt;{requires}{$need_module}
            || exists $prereq_pm-&gt;{opt_requires}{$need_module}
        ) {
            $needed_as = "r";
        } elsif ($slot eq "configure_requires_later") {
            # in ae872487d5 we said: C&lt; we have not yet run the
            # {Build,Makefile}.PL, we must presume "r" &gt;; but the
            # meta.yml standard says C&lt; These dependencies are not
            # required after the distribution is installed. &gt;; so now
            # we change it back to "b" and care for the proper
            # promotion later.
            $needed_as = "b";
        } else {
            $needed_as = "b";
        }
        # here need to flag as optional for recommends/suggests
        # -- xdg, 2012-04-01
        $self-&gt;debug(sprintf "%s manadory?[%s]",
                     $self-&gt;pretty_id,
                     $self-&gt;{mandatory})
            if $CPAN::DEBUG;
        my $optional = !$self-&gt;{mandatory}
            || $self-&gt;is_locally_optional($prereq_pm, $need_module);
        push @need, [$need_module,$needed_as,$optional];
    }
    my @unfolded = map { "[".join(",",@$_)."]" } @need;
    CPAN-&gt;debug("returning from unsat_prereq[@unfolded]") if $CPAN::DEBUG;
    @need;
}

sub _fulfills_all_version_rqs {
    my($self,$need_module,$available_file,$available_version,$need_version) = @_;
    my(@all_requirements) = split /\s*,\s*/, $need_version;
    local($^W) = 0;
    my $ok = 0;
  RQ: for my $rq (@all_requirements) {
        if ($rq =~ s|&gt;=\s*||) {
        } elsif ($rq =~ s|&gt;\s*||) {
            # 2005-12: one user
            if (CPAN::Version-&gt;vgt($available_version,$rq)) {
                $ok++;
            }
            next RQ;
        } elsif ($rq =~ s|!=\s*||) {
            # 2005-12: no user
            if (CPAN::Version-&gt;vcmp($available_version,$rq)) {
                $ok++;
                next RQ;
            } else {
                $ok=0;
                last RQ;
            }
        } elsif ($rq =~ m|&lt;=?\s*|) {
            # 2005-12: no user
            $CPAN::Frontend-&gt;mywarn("Downgrading not supported (rq[$rq])\n");
            $ok++;
            next RQ;
        } elsif ($rq =~ s|==\s*||) {
            # 2009-07: ELLIOTJS/Perl-Critic-1.099_002.tar.gz
            if (CPAN::Version-&gt;vcmp($available_version,$rq)) {
                $ok=0;
                last RQ;
            } else {
                $ok++;
                next RQ;
            }
        }
        if (! CPAN::Version-&gt;vgt($rq, $available_version)) {
            $ok++;
        }
        CPAN-&gt;debug(sprintf("need_module[%s]available_file[%s]".
                            "available_version[%s]rq[%s]ok[%d]",
                            $need_module,
                            $available_file,
                            $available_version,
                            CPAN::Version-&gt;readable($rq),
                            $ok,
                           )) if $CPAN::DEBUG;
    }
    my $ret = $ok == @all_requirements;
    CPAN-&gt;debug(sprintf("need_module[%s]ok[%s]all_requirements[%d]",$need_module, $ok, scalar @all_requirements)) if $CPAN::DEBUG;
    return $ret;
}

#-&gt; sub CPAN::Distribution::read_meta
# read any sort of meta files, return CPAN::Meta object if no errors
sub read_meta {
    my($self) = @_;
    my $meta_file = $self-&gt;pick_meta_file
        or return;

    return unless $CPAN::META-&gt;has_usable("CPAN::Meta");
    my $meta = eval { CPAN::Meta-&gt;load_file($meta_file)}
        or return;

    # Very old EU::MM could have wrong META
    if ($meta_file eq 'META.yml'
        &amp;&amp; $meta-&gt;generated_by =~ /ExtUtils::MakeMaker version ([\d\._]+)/
    ) {
        my $eummv = do { local $^W = 0; $1+0; };
        return if $eummv &lt; 6.2501;
    }

    return $meta;
}

#-&gt; sub CPAN::Distribution::read_yaml ;
# XXX This should be DEPRECATED -- dagolden, 2011-02-05
sub read_yaml {
    my($self) = @_;
    my $meta_file = $self-&gt;pick_meta_file('\.yml$');
    $self-&gt;debug("meta_file[$meta_file]") if $CPAN::DEBUG;
    return unless $meta_file;
    my $yaml;
    eval { $yaml = $self-&gt;parse_meta_yml($meta_file) };
    if ($@ or ! $yaml) {
        return undef; # if we die, then we cannot read YAML's own META.yml
    }
    # not "authoritative"
    if (defined $yaml &amp;&amp; (! ref $yaml || ref $yaml ne "HASH")) {
        $CPAN::Frontend-&gt;mywarn("META.yml does not seem to be conforming, cannot use it.\n");
        $yaml = undef;
    }
    $self-&gt;debug(sprintf "yaml[%s]", $yaml || "UNDEF")
        if $CPAN::DEBUG;
    $self-&gt;debug($yaml) if $CPAN::DEBUG &amp;&amp; $yaml;
    # MYMETA.yml is static and authoritative by definition
    if ( $meta_file =~ /MYMETA\.yml/ ) {
      return $yaml;
    }
    # META.yml is authoritative only if dynamic_config is defined and false
    if ( defined $yaml-&gt;{dynamic_config} &amp;&amp; ! $yaml-&gt;{dynamic_config} ) {
      return $yaml;
    }
    # otherwise, we can't use what we found
    return undef;
}

#-&gt; sub CPAN::Distribution::configure_requires ;
sub configure_requires {
    my($self) = @_;
    return unless my $meta_file = $self-&gt;pick_meta_file('^META');
    if (my $meta_obj = $self-&gt;read_meta) {
        my $prereqs = $meta_obj-&gt;effective_prereqs;
        my $cr = $prereqs-&gt;requirements_for(qw/configure requires/);
        return $cr ? $cr-&gt;as_string_hash : undef;
    }
    else {
        my $yaml = eval { $self-&gt;parse_meta_yml($meta_file) };
        return $yaml-&gt;{configure_requires};
    }
}

#-&gt; sub CPAN::Distribution::prereq_pm ;
sub prereq_pm {
    my($self) = @_;
    return unless $self-&gt;{writemakefile}  # no need to have succeeded
                                          # but we must have run it
        || $self-&gt;{modulebuild};
    unless ($self-&gt;{build_dir}) {
        return;
    }
    # no Makefile/Build means configuration aborted, so don't look for prereqs
    my $makefile  = File::Spec-&gt;catfile($self-&gt;{build_dir}, $^O eq 'VMS' ? 'descrip.mms' : 'Makefile');
    my $buildfile = File::Spec-&gt;catfile($self-&gt;{build_dir}, $^O eq 'VMS' ? 'Build.com' : 'Build');
    return unless   -f $makefile || -f $buildfile;
    CPAN-&gt;debug(sprintf "writemakefile[%s]modulebuild[%s]",
                $self-&gt;{writemakefile}||"",
                $self-&gt;{modulebuild}||"",
               ) if $CPAN::DEBUG;
    my($req,$breq, $opt_req, $opt_breq);
    my $meta_obj = $self-&gt;read_meta;
    # META/MYMETA is only authoritative if dynamic_config is false
    if ($meta_obj &amp;&amp; ! $meta_obj-&gt;dynamic_config) {
        my $prereqs = $meta_obj-&gt;effective_prereqs;
        my $requires = $prereqs-&gt;requirements_for(qw/runtime requires/);
        my $build_requires = $prereqs-&gt;requirements_for(qw/build requires/);
        my $test_requires = $prereqs-&gt;requirements_for(qw/test requires/);
        # XXX we don't yet distinguish build vs test, so merge them for now
        $build_requires-&gt;add_requirements($test_requires);
        $req = $requires-&gt;as_string_hash;
        $breq = $build_requires-&gt;as_string_hash;

        # XXX assemble optional_req &amp;&amp; optional_breq from recommends/suggests
        # depending on corresponding policies -- xdg, 2012-04-01
        CPAN-&gt;use_inst("CPAN::Meta::Requirements");
        my $opt_runtime = CPAN::Meta::Requirements-&gt;new;
        my $opt_build   = CPAN::Meta::Requirements-&gt;new;
        if ( $CPAN::Config-&gt;{recommends_policy} ) {
            $opt_runtime-&gt;add_requirements( $prereqs-&gt;requirements_for(qw/runtime recommends/));
            $opt_build-&gt;add_requirements(   $prereqs-&gt;requirements_for(qw/build recommends/));
            $opt_build-&gt;add_requirements(   $prereqs-&gt;requirements_for(qw/test  recommends/));

        }
        if ( $CPAN::Config-&gt;{suggests_policy} ) {
            $opt_runtime-&gt;add_requirements( $prereqs-&gt;requirements_for(qw/runtime suggests/));
            $opt_build-&gt;add_requirements(   $prereqs-&gt;requirements_for(qw/build suggests/));
            $opt_build-&gt;add_requirements(   $prereqs-&gt;requirements_for(qw/test  suggests/));
        }
        $opt_req = $opt_runtime-&gt;as_string_hash;
        $opt_breq = $opt_build-&gt;as_string_hash;
    }
    elsif (my $yaml = $self-&gt;read_yaml) { # often dynamic_config prevents a result here
        $req =  $yaml-&gt;{requires} || {};
        $breq =  $yaml-&gt;{build_requires} || {};
        if ( $CPAN::Config-&gt;{recommends_policy} ) {
            $opt_req = $yaml-&gt;{recommends} || {};
        }
        undef $req unless ref $req eq "HASH" &amp;&amp; %$req;
        if ($req) {
            if ($yaml-&gt;{generated_by} &amp;&amp;
                $yaml-&gt;{generated_by} =~ /ExtUtils::MakeMaker version ([\d\._]+)/) {
                my $eummv = do { local $^W = 0; $1+0; };
                if ($eummv &lt; 6.2501) {
                    # thanks to Slaven for digging that out: MM before
                    # that could be wrong because it could reflect a
                    # previous release
                    undef $req;
                }
            }
            my $areq;
            my $do_replace;
            foreach my $k (sort keys %{$req||{}}) {
                my $v = $req-&gt;{$k};
                next unless defined $v;
                if ($v =~ /\d/) {
                    $areq-&gt;{$k} = $v;
                } elsif ($k =~ /[A-Za-z]/ &amp;&amp;
                         $v =~ /[A-Za-z]/ &amp;&amp;
                         $CPAN::META-&gt;exists("CPAN::Module",$v)
                        ) {
                    $CPAN::Frontend-&gt;mywarn("Suspicious key-value pair in META.yml's ".
                                            "requires hash: $k =&gt; $v; I'll take both ".
                                            "key and value as a module name\n");
                    $CPAN::Frontend-&gt;mysleep(1);
                    $areq-&gt;{$k} = 0;
                    $areq-&gt;{$v} = 0;
                    $do_replace++;
                }
            }
            $req = $areq if $do_replace;
        }
    }
    else {
        $CPAN::Frontend-&gt;mywarnonce("Could not read metadata file. Falling back to other ".
                                    "methods to determine prerequisites\n");
    }

    unless ($req || $breq) {
        my $build_dir;
        unless ( $build_dir = $self-&gt;{build_dir} ) {
            return;
        }
        my $makefile = File::Spec-&gt;catfile($build_dir,"Makefile");
        my $fh;
        if (-f $makefile
            and
            $fh = FileHandle-&gt;new("&lt;$makefile\0")) {
            CPAN-&gt;debug("Getting prereq from Makefile") if $CPAN::DEBUG;
            local($/) = "\n";
            while (&lt;$fh&gt;) {
                last if /MakeMaker post_initialize section/;
                my($p) = m{^[\#]
                           \s+PREREQ_PM\s+=&gt;\s+(.+)
                       }x;
                next unless $p;
                # warn "Found prereq expr[$p]";

                #  Regexp modified by A.Speer to remember actual version of file
                #  PREREQ_PM hash key wants, then add to
                while ( $p =~ m/(?:\s)([\w\:]+)=&gt;(q\[.*?\]|undef),?/g ) {
                    my($m,$n) = ($1,$2);
                    # When a prereq is mentioned twice: let the bigger
                    # win; usual culprit is that they declared
                    # build_requires separately from requires; see
                    # rt.cpan.org #47774
                    my($prevn);
                    if ( defined $req-&gt;{$m} ) {
                        $prevn = $req-&gt;{$m};
                    }
                    if ($n =~ /^q\[(.*?)\]$/) {
                        $n = $1;
                    }
                    if (!$prevn || CPAN::Version-&gt;vlt($prevn, $n)){
                        $req-&gt;{$m} = $n;
                    }
                }
                last;
            }
        }
    }
    unless ($req || $breq) {
        my $build_dir = $self-&gt;{build_dir} or die "Panic: no build_dir?";
        my $buildfile = File::Spec-&gt;catfile($build_dir,"Build");
        if (-f $buildfile) {
            CPAN-&gt;debug("Found '$buildfile'") if $CPAN::DEBUG;
            my $build_prereqs = File::Spec-&gt;catfile($build_dir,"_build","prereqs");
            if (-f $build_prereqs) {
                CPAN-&gt;debug("Getting prerequisites from '$build_prereqs'") if $CPAN::DEBUG;
                my $content = do { local *FH;
                                   open FH, $build_prereqs
                                       or $CPAN::Frontend-&gt;mydie("Could not open ".
                                                                 "'$build_prereqs': $!");
                                   local $/;
                                   &lt;FH&gt;;
                               };
                my $bphash = eval $content;
                if ($@) {
                } else {
                    $req  = $bphash-&gt;{requires} || +{};
                    $breq = $bphash-&gt;{build_requires} || +{};
                }
            }
        }
    }
    # XXX needs to be adapted for optional_req &amp; optional_breq -- xdg, 2012-04-01
    if ($req || $breq || $opt_req || $opt_breq ) {
        return $self-&gt;{prereq_pm} = {
           requires =&gt; $req,
           build_requires =&gt; $breq,
           opt_requires =&gt; $opt_req,
           opt_build_requires =&gt; $opt_breq,
       };
    }
}

#-&gt; sub CPAN::Distribution::shortcut_test ;
# return values: undef means don't shortcut; 0 means shortcut as fail;
# and 1 means shortcut as success
sub shortcut_test {
    my ($self) = @_;

    $self-&gt;debug("checking badtestcnt[$self-&gt;{ID}]") if $CPAN::DEBUG;
    $self-&gt;{badtestcnt} ||= 0;
    if ($self-&gt;{badtestcnt} &gt; 0) {
        require Data::Dumper;
        CPAN-&gt;debug(sprintf "NOREPEAT[%s]", Data::Dumper::Dumper($self)) if $CPAN::DEBUG;
        return $self-&gt;goodbye("Won't repeat unsuccessful test during this command");
    }

    for my $slot ( qw/later configure_requires_later/ ) {
        $self-&gt;debug("checking $slot slot[$self-&gt;{ID}]") if $CPAN::DEBUG;
        return $self-&gt;success($self-&gt;{$slot})
        if $self-&gt;{$slot};
    }

    $self-&gt;debug("checking if tests passed[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if ( $self-&gt;{make_test} ) {
        if (
            UNIVERSAL::can($self-&gt;{make_test},"failed") ?
            $self-&gt;{make_test}-&gt;failed :
            $self-&gt;{make_test} =~ /^NO/
        ) {
            if (
                UNIVERSAL::can($self-&gt;{make_test},"commandid")
                &amp;&amp;
                $self-&gt;{make_test}-&gt;commandid == $CPAN::CurrentCommandId
            ) {
                return $self-&gt;goodbye("Has already been tested within this command");
            }
        } else {
            # if global "is_tested" has been cleared, we need to mark this to
            # be added to PERL5LIB if not already installed
            if ($self-&gt;tested_ok_but_not_installed) {
                $CPAN::META-&gt;is_tested($self-&gt;{build_dir},$self-&gt;{make_test}{TIME});
            }
            return $self-&gt;success("Has already been tested successfully");
        }
    }

    if ($self-&gt;{notest}) {
        $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new("YES");
        return $self-&gt;success("Skipping test because of notest pragma");
    }

    return undef; # no shortcut
}

#-&gt; sub CPAN::Distribution::_exe_files ;
sub _exe_files {
    my($self) = @_;
    return unless $self-&gt;{writemakefile}  # no need to have succeeded
                                          # but we must have run it
        || $self-&gt;{modulebuild};
    unless ($self-&gt;{build_dir}) {
        return;
    }
    CPAN-&gt;debug(sprintf "writemakefile[%s]modulebuild[%s]",
                $self-&gt;{writemakefile}||"",
                $self-&gt;{modulebuild}||"",
               ) if $CPAN::DEBUG;
    my $build_dir;
    unless ( $build_dir = $self-&gt;{build_dir} ) {
        return;
    }
    my $makefile = File::Spec-&gt;catfile($build_dir,"Makefile");
    my $fh;
    my @exe_files;
    if (-f $makefile
        and
        $fh = FileHandle-&gt;new("&lt;$makefile\0")) {
        CPAN-&gt;debug("Getting exefiles from Makefile") if $CPAN::DEBUG;
        local($/) = "\n";
        while (&lt;$fh&gt;) {
            last if /MakeMaker post_initialize section/;
            my($p) = m{^[\#]
                       \s+EXE_FILES\s+=&gt;\s+\[(.+)\]
                  }x;
            next unless $p;
            # warn "Found exefiles expr[$p]";
            my @p = split /,\s*/, $p;
            for my $p2 (@p) {
                if ($p2 =~ /^q\[(.+)\]/) {
                    push @exe_files, $1;
                }
            }
        }
    }
    return \@exe_files if @exe_files;
    my $buildparams = File::Spec-&gt;catfile($build_dir,"_build","build_params");
    if (-f $buildparams) {
        CPAN-&gt;debug("Found '$buildparams'") if $CPAN::DEBUG;
        my $x = do $buildparams;
        for my $sf ($x-&gt;[2]{script_files}) {
            if (my $reftype = ref $sf) {
                if ($reftype eq "ARRAY") {
                    push @exe_files, @$sf;
                }
                elsif ($reftype eq "HASH") {
                    push @exe_files, keys %$sf;
                }
                else {
                    $CPAN::Frontend-&gt;mywarn("Invalid reftype $reftype for Build.PL 'script_files'\n");
                }
            }
            elsif (defined $sf) {
                push @exe_files, $sf;
            }
        }
    }
    return \@exe_files;
}

#-&gt; sub CPAN::Distribution::test ;
sub test {
    my($self) = @_;

    $self-&gt;pre_test();

    $self-&gt;debug("checking goto id[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (my $goto = $self-&gt;prefs-&gt;{goto}) {
        return $self-&gt;goto($goto);
    }

    $self-&gt;make
        or return;

    if ( defined( my $sc = $self-&gt;shortcut_test ) ) {
        return $sc;
    }

    if ($CPAN::Signal) {
      delete $self-&gt;{force_update};
      return;
    }
    # warn "XDEBUG: checking for notest: $self-&gt;{notest} $self";
    my $make = $self-&gt;{modulebuild} ? "Build" : "make";

    local $ENV{PERL5LIB} = defined($ENV{PERL5LIB})
                           ? $ENV{PERL5LIB}
                           : ($ENV{PERLLIB} || "");

    local $ENV{PERL5OPT} = defined $ENV{PERL5OPT} ? $ENV{PERL5OPT} : "";
    local $ENV{PERL_USE_UNSAFE_INC} = exists $ENV{PERL_USE_UNSAFE_INC} ? $ENV{PERL_USE_UNSAFE_INC} : 1; # test
    $CPAN::META-&gt;set_perl5lib;
    local $ENV{MAKEFLAGS}; # protect us from outer make calls
    local $ENV{PERL_MM_USE_DEFAULT} = 1 if $CPAN::Config-&gt;{use_prompt_default};
    local $ENV{NONINTERACTIVE_TESTING} = 1 if $CPAN::Config-&gt;{use_prompt_default};

    $CPAN::Frontend-&gt;myprint(sprintf "Running %s test for %s\n", $make, $self-&gt;pretty_id);

    my $builddir = $self-&gt;dir or
        $CPAN::Frontend-&gt;mydie("PANIC: Cannot determine build directory\n");

    unless (chdir $builddir) {
        $CPAN::Frontend-&gt;mywarn("Couldn't chdir to '$builddir': $!");
        return;
    }

    $self-&gt;debug("Changed directory to $self-&gt;{build_dir}")
        if $CPAN::DEBUG;

    if ($^O eq 'MacOS') {
        Mac::BuildTools::make_test($self);
        return;
    }

    if ($self-&gt;{modulebuild}) {
        my $thm = CPAN::Shell-&gt;expand("Module","Test::Harness");
        my $v = $thm-&gt;inst_version;
        if (CPAN::Version-&gt;vlt($v,2.62)) {
            # XXX Eric Wilhelm reported this as a bug: klapperl:
            # Test::Harness 3.0 self-tests, so that should be 'unless
            # installing Test::Harness'
            unless ($self-&gt;id eq $thm-&gt;distribution-&gt;id) {
               $CPAN::Frontend-&gt;mywarn(qq{The version of your Test::Harness is only
  '$v', you need at least '2.62'. Please upgrade your Test::Harness.\n});
                $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new("NO Test::Harness too old");
                return;
            }
        }
    }

    if ( ! $self-&gt;{force_update}  ) {
        # bypass actual tests if "trust_test_report_history" and have a report
        my $have_tested_fcn;
        if (   $CPAN::Config-&gt;{trust_test_report_history}
            &amp;&amp; $CPAN::META-&gt;has_inst("CPAN::Reporter::History")
            &amp;&amp; ( $have_tested_fcn = CPAN::Reporter::History-&gt;can("have_tested" ))) {
            if ( my @reports = $have_tested_fcn-&gt;( dist =&gt; $self-&gt;base_id ) ) {
                # Do nothing if grade was DISCARD
                if ( $reports[-1]-&gt;{grade} =~ /^(?:PASS|UNKNOWN)$/ ) {
                    $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new("YES");
                    # if global "is_tested" has been cleared, we need to mark this to
                    # be added to PERL5LIB if not already installed
                    if ($self-&gt;tested_ok_but_not_installed) {
                        $CPAN::META-&gt;is_tested($self-&gt;{build_dir},$self-&gt;{make_test}{TIME});
                    }
                    $CPAN::Frontend-&gt;myprint("Found prior test report -- OK\n");
                    return;
                }
                elsif ( $reports[-1]-&gt;{grade} =~ /^(?:FAIL|NA)$/ ) {
                    $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new("NO");
                    $self-&gt;{badtestcnt}++;
                    $CPAN::Frontend-&gt;mywarn("Found prior test report -- NOT OK\n");
                    return;
                }
            }
        }
    }

    my $system;
    my $prefs_test = $self-&gt;prefs-&gt;{test};
    if (my $commandline
        = exists $prefs_test-&gt;{commandline} ? $prefs_test-&gt;{commandline} : "") {
        $system = $commandline;
        $ENV{PERL} = CPAN::find_perl();
    } elsif ($self-&gt;{modulebuild}) {
        $system = sprintf "%s test", $self-&gt;_build_command();
        unless (-e "Build" || ($^O eq 'VMS' &amp;&amp; -e "Build.com")) {
            my $id = $self-&gt;pretty_id;
            $CPAN::Frontend-&gt;mywarn("Alert: no 'Build' file found while trying to test '$id'");
        }
    } else {
        $system = join " ", $self-&gt;_make_command(), "test";
    }
    my $make_test_arg = $self-&gt;_make_phase_arg("test");
    $system = sprintf("%s%s",
                      $system,
                      $make_test_arg ? " $make_test_arg" : "",
                     );
    my($tests_ok);
    my $test_env;
    if ($self-&gt;prefs-&gt;{test}) {
        $test_env = $self-&gt;prefs-&gt;{test}{env};
    }
    local @ENV{keys %$test_env} = values %$test_env if $test_env;
    my $expect_model = $self-&gt;_prefs_with_expect("test");
    my $want_expect = 0;
    if ( $expect_model &amp;&amp; @{$expect_model-&gt;{talk}} ) {
        my $can_expect = $CPAN::META-&gt;has_inst("Expect");
        if ($can_expect) {
            $want_expect = 1;
        } else {
            $CPAN::Frontend-&gt;mywarn("Expect not installed, falling back to ".
                                    "testing without\n");
        }
    }
    if ($want_expect) {
        if ($self-&gt;_should_report('test')) {
            $CPAN::Frontend-&gt;mywarn("Reporting via CPAN::Reporter is currently ".
                                    "not supported when distroprefs specify ".
                                    "an interactive test\n");
        }
        $tests_ok = $self-&gt;_run_via_expect($system,'test',$expect_model) == 0;
    } elsif ( $self-&gt;_should_report('test') ) {
        $tests_ok = CPAN::Reporter::test($self, $system);
    } else {
        $tests_ok = system($system) == 0;
    }
    $self-&gt;introduce_myself;
    my $but = $self-&gt;_make_test_illuminate_prereqs();
    if ( $tests_ok ) {
        if ($but) {
            $CPAN::Frontend-&gt;mywarn("Tests succeeded but $but\n");
            $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new("NO $but");
            $self-&gt;store_persistent_state;
            return $self-&gt;goodbye("[dependencies] -- NA");
        }
        $CPAN::Frontend-&gt;myprint("  $system -- OK\n");
        $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new("YES");
        $CPAN::META-&gt;is_tested($self-&gt;{build_dir},$self-&gt;{make_test}{TIME});
        # probably impossible to need the next line because badtestcnt
        # has a lifespan of one command
        delete $self-&gt;{badtestcnt};
    } else {
        if ($but) {
            $but .= "; additionally test harness failed";
            $CPAN::Frontend-&gt;mywarn("$but\n");
            $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new("NO $but");
        } elsif ( $self-&gt;{force_update} ) {
            $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new(
                "NO but failure ignored because 'force' in effect"
            );
        } else {
            $self-&gt;{make_test} = CPAN::Distrostatus-&gt;new("NO");
        }
        $self-&gt;{badtestcnt}++;
        $CPAN::Frontend-&gt;mywarn("  $system -- NOT OK\n");
        CPAN::Shell-&gt;optprint
              ("hint",
               sprintf
               ("//hint// to see the cpan-testers results for installing this module, try:
  reports %s\n",
                $self-&gt;pretty_id));
    }
    $self-&gt;store_persistent_state;

    $self-&gt;post_test();

    return $self-&gt;{force_update} ? 1 : !! $tests_ok;
}

sub _make_test_illuminate_prereqs {
    my($self) = @_;
    my @prereq;

    # local $CPAN::DEBUG = 16; # Distribution
    for my $m (sort keys %{$self-&gt;{sponsored_mods}}) {
        next unless $self-&gt;{sponsored_mods}{$m} &gt; 0;
        my $m_obj = CPAN::Shell-&gt;expand("Module",$m) or next;
        # XXX we need available_version which reflects
        # $ENV{PERL5LIB} so that already tested but not yet
        # installed modules are counted.
        my $available_version = $m_obj-&gt;available_version;
        my $available_file = $m_obj-&gt;available_file;
        if ($available_version &amp;&amp;
            !CPAN::Version-&gt;vlt($available_version,$self-&gt;{prereq_pm}{$m})
           ) {
            CPAN-&gt;debug("m[$m] good enough available_version[$available_version]")
                if $CPAN::DEBUG;
        } elsif ($available_file
                 &amp;&amp; (
                     !$self-&gt;{prereq_pm}{$m}
                     ||
                     $self-&gt;{prereq_pm}{$m} == 0
                    )
                ) {
            # lex Class::Accessor::Chained::Fast which has no $VERSION
            CPAN-&gt;debug("m[$m] have available_file[$available_file]")
                if $CPAN::DEBUG;
        } else {
            push @prereq, $m
                if $m_obj-&gt;{mandatory};
        }
    }
    my $but;
    if (@prereq) {
        my $cnt = @prereq;
        my $which = join ",", @prereq;
        $but = $cnt == 1 ? "one dependency not OK ($which)" :
            "$cnt dependencies missing ($which)";
    }
    $but;
}

sub _prefs_with_expect {
    my($self,$where) = @_;
    return unless my $prefs = $self-&gt;prefs;
    return unless my $where_prefs = $prefs-&gt;{$where};
    if ($where_prefs-&gt;{expect}) {
        return {
                mode =&gt; "deterministic",
                timeout =&gt; 15,
                talk =&gt; $where_prefs-&gt;{expect},
               };
    } elsif ($where_prefs-&gt;{"eexpect"}) {
        return $where_prefs-&gt;{"eexpect"};
    }
    return;
}

#-&gt; sub CPAN::Distribution::clean ;
sub clean {
    my($self) = @_;
    my $make = $self-&gt;{modulebuild} ? "Build" : "make";
    $CPAN::Frontend-&gt;myprint(sprintf "Running %s clean for %s\n", $make, $self-&gt;pretty_id);
    unless (exists $self-&gt;{archived}) {
        $CPAN::Frontend-&gt;mywarn("Distribution seems to have never been unzipped".
                                "/untarred, nothing done\n");
        return 1;
    }
    unless (exists $self-&gt;{build_dir}) {
        $CPAN::Frontend-&gt;mywarn("Distribution has no own directory, nothing to do.\n");
        return 1;
    }
    if (exists $self-&gt;{writemakefile}
        and $self-&gt;{writemakefile}-&gt;failed
       ) {
        $CPAN::Frontend-&gt;mywarn("No Makefile, don't know how to 'make clean'\n");
        return 1;
    }
  EXCUSE: {
        my @e;
        exists $self-&gt;{make_clean} and $self-&gt;{make_clean} eq "YES" and
            push @e, "make clean already called once";
        $CPAN::Frontend-&gt;myprint(join "", map {"  $_\n"} @e) and return if @e;
    }
    chdir "$self-&gt;{build_dir}" or
        Carp::confess("Couldn't chdir to $self-&gt;{build_dir}: $!");
    $self-&gt;debug("Changed directory to $self-&gt;{build_dir}") if $CPAN::DEBUG;

    if ($^O eq 'MacOS') {
        Mac::BuildTools::make_clean($self);
        return;
    }

    my $system;
    if ($self-&gt;{modulebuild}) {
        unless (-f "Build") {
            my $cwd = CPAN::anycwd();
            $CPAN::Frontend-&gt;mywarn("Alert: no Build file available for 'clean $self-&gt;{id}".
                                    " in cwd[$cwd]. Danger, Will Robinson!");
            $CPAN::Frontend-&gt;mysleep(5);
        }
        $system = sprintf "%s clean", $self-&gt;_build_command();
    } else {
        $system  = join " ", $self-&gt;_make_command(), "clean";
    }
    my $system_ok = system($system) == 0;
    $self-&gt;introduce_myself;
    if ( $system_ok ) {
      $CPAN::Frontend-&gt;myprint("  $system -- OK\n");

      # $self-&gt;force;

      # Jost Krieger pointed out that this "force" was wrong because
      # it has the effect that the next "install" on this distribution
      # will untar everything again. Instead we should bring the
      # object's state back to where it is after untarring.

      for my $k (qw(
                    force_update
                    install
                    writemakefile
                    make
                    make_test
                   )) {
          delete $self-&gt;{$k};
      }
      $self-&gt;{make_clean} = CPAN::Distrostatus-&gt;new("YES");

    } else {
      # Hmmm, what to do if make clean failed?

      $self-&gt;{make_clean} = CPAN::Distrostatus-&gt;new("NO");
      $CPAN::Frontend-&gt;mywarn(qq{  $system -- NOT OK\n});

      # 2006-02-27: seems silly to me to force a make now
      # $self-&gt;force("make"); # so that this directory won't be used again

    }
    $self-&gt;store_persistent_state;
}

#-&gt; sub CPAN::Distribution::check_disabled ;
sub check_disabled {
    my ($self) = @_;
    $self-&gt;debug("checking disabled id[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if ($self-&gt;prefs-&gt;{disabled} &amp;&amp; ! $self-&gt;{force_update}) {
        return sprintf(
                            "Disabled via prefs file '%s' doc %d",
                            $self-&gt;{prefs_file},
                            $self-&gt;{prefs_file_doc},
                            );
    }
    return;
}

#-&gt; sub CPAN::Distribution::goto ;
sub goto {
    my($self,$goto) = @_;
    $goto = $self-&gt;normalize($goto);
    my $why = sprintf(
                      "Goto '$goto' via prefs file '%s' doc %d",
                      $self-&gt;{prefs_file},
                      $self-&gt;{prefs_file_doc},
                     );
    $self-&gt;{unwrapped} = CPAN::Distrostatus-&gt;new("NO $why");
    # 2007-07-16 akoenig : Better than NA would be if we could inherit
    # the status of the $goto distro but given the exceptional nature
    # of 'goto' I feel reluctant to implement it
    my $goodbye_message = "[goto] -- NA $why";
    $self-&gt;goodbye($goodbye_message);

    # inject into the queue

    CPAN::Queue-&gt;delete($self-&gt;id);
    CPAN::Queue-&gt;jumpqueue({qmod =&gt; $goto, reqtype =&gt; $self-&gt;{reqtype}});

    # and run where we left off

    my($method) = (caller(1))[3];
    CPAN-&gt;instance("CPAN::Distribution",$goto)-&gt;$method();
    CPAN::Queue-&gt;delete_first($goto);
    # XXX delete_first returns undef; is that what this should return
    # up the call stack, eg. return $sefl-&gt;goto($goto) -- xdg, 2012-04-04
}

#-&gt; sub CPAN::Distribution::shortcut_install ;
# return values: undef means don't shortcut; 0 means shortcut as fail;
# and 1 means shortcut as success
sub shortcut_install {
    my ($self) = @_;

    $self-&gt;debug("checking previous install results[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (exists $self-&gt;{install}) {
        my $text = UNIVERSAL::can($self-&gt;{install},"text") ?
            $self-&gt;{install}-&gt;text :
                $self-&gt;{install};
        if ($text =~ /^YES/) {
            $CPAN::META-&gt;is_installed($self-&gt;{build_dir});
            return $self-&gt;success("Already done");
        } elsif ($text =~ /is only/) {
            # e.g. 'is only build_requires': may be overruled later
            return $self-&gt;goodbye($text);
        } else {
            # comment in Todo on 2006-02-11; maybe retry?
            return $self-&gt;goodbye("Already tried without success");
        }
    }

    for my $slot ( qw/later configure_requires_later/ ) {
        return $self-&gt;success($self-&gt;{$slot})
        if $self-&gt;{$slot};
    }

    return undef;
}

#-&gt; sub CPAN::Distribution::install ;
sub install {
    my($self) = @_;

    $self-&gt;pre_install();

    $self-&gt;debug("checking goto id[$self-&gt;{ID}]") if $CPAN::DEBUG;
    if (my $goto = $self-&gt;prefs-&gt;{goto}) {
        $self-&gt;goto($goto);
        $self-&gt;post_install();
        return;
    }

    unless ($self-&gt;test) {
        $self-&gt;post_install();
        return;
    }

    if ( defined( my $sc = $self-&gt;shortcut_install ) ) {
        $self-&gt;post_install();
        return $sc;
    }

    if ($CPAN::Signal) {
        delete $self-&gt;{force_update};
        $self-&gt;post_install();
        return;
    }

    my $builddir = $self-&gt;dir or
        $CPAN::Frontend-&gt;mydie("PANIC: Cannot determine build directory\n");

    unless (chdir $builddir) {
        $CPAN::Frontend-&gt;mywarn("Couldn't chdir to '$builddir': $!");
        $self-&gt;post_install();
        return;
    }

    $self-&gt;debug("Changed directory to $self-&gt;{build_dir}")
        if $CPAN::DEBUG;

    my $make = $self-&gt;{modulebuild} ? "Build" : "make";
    $CPAN::Frontend-&gt;myprint(sprintf "Running %s install for %s\n", $make, $self-&gt;pretty_id);

    if ($^O eq 'MacOS') {
        Mac::BuildTools::make_install($self);
        $self-&gt;post_install();
        return;
    }

    my $system;
    if (my $commandline = $self-&gt;prefs-&gt;{install}{commandline}) {
        $system = $commandline;
        $ENV{PERL} = CPAN::find_perl();
    } elsif ($self-&gt;{modulebuild}) {
        my($mbuild_install_build_command) =
            exists $CPAN::HandleConfig::keys{mbuild_install_build_command} &amp;&amp;
                $CPAN::Config-&gt;{mbuild_install_build_command} ?
                    $CPAN::Config-&gt;{mbuild_install_build_command} :
                        $self-&gt;_build_command();
        my $install_directive = $^O eq 'VMS' ? '"install"' : 'install';
        $system = sprintf("%s %s %s",
                          $mbuild_install_build_command,
                          $install_directive,
                          $CPAN::Config-&gt;{mbuild_install_arg},
                         );
    } else {
        my($make_install_make_command) = $self-&gt;_make_install_make_command();
        $system = sprintf("%s install %s",
                          $make_install_make_command,
                          $CPAN::Config-&gt;{make_install_arg},
                         );
    }

    my($stderr) = $^O eq "MSWin32" || $^O eq 'VMS' ? "" : " 2&gt;&amp;1 ";
    my $brip = CPAN::HandleConfig-&gt;prefs_lookup($self,
                                                q{build_requires_install_policy});
    $brip ||="ask/yes";
    my $id = $self-&gt;id;
    my $reqtype = $self-&gt;{reqtype} ||= "c"; # in doubt it was a command
    my $want_install = "yes";
    if ($reqtype eq "b") {
        if ($brip eq "no") {
            $want_install = "no";
        } elsif ($brip =~ m|^ask/(.+)|) {
            my $default = $1;
            $default = "yes" unless $default =~ /^(y|n)/i;
            $want_install =
                CPAN::Shell::colorable_makemaker_prompt
                      ("$id is just needed temporarily during building or testing. ".
                       "Do you want to install it permanently?",
                       $default);
        }
    }
    unless ($want_install =~ /^y/i) {
        my $is_only = "is only 'build_requires'";
        $self-&gt;{install} = CPAN::Distrostatus-&gt;new("NO -- $is_only");
        delete $self-&gt;{force_update};
        $self-&gt;goodbye("Not installing because $is_only");
        $self-&gt;post_install();
        return;
    }
    local $ENV{PERL5LIB} = defined($ENV{PERL5LIB})
                           ? $ENV{PERL5LIB}
                           : ($ENV{PERLLIB} || "");

    local $ENV{PERL5OPT} = defined $ENV{PERL5OPT} ? $ENV{PERL5OPT} : "";
    local $ENV{PERL_USE_UNSAFE_INC} = exists $ENV{PERL_USE_UNSAFE_INC} ? $ENV{PERL_USE_UNSAFE_INC} : 1; # install
    $CPAN::META-&gt;set_perl5lib;
    local $ENV{PERL_MM_USE_DEFAULT} = 1 if $CPAN::Config-&gt;{use_prompt_default};
    local $ENV{NONINTERACTIVE_TESTING} = 1 if $CPAN::Config-&gt;{use_prompt_default};

    my($pipe) = FileHandle-&gt;new("$system $stderr |");
    unless ($pipe) {
        $CPAN::Frontend-&gt;mywarn("Can't execute $system: $!");
        $self-&gt;introduce_myself;
        $self-&gt;{install} = CPAN::Distrostatus-&gt;new("NO");
        $CPAN::Frontend-&gt;mywarn("  $system -- NOT OK\n");
        delete $self-&gt;{force_update};
        $self-&gt;post_install();
        return;
    }
    my($makeout) = "";
    while (&lt;$pipe&gt;) {
        print $_; # intentionally NOT use Frontend-&gt;myprint because it
                  # looks irritating when we markup in color what we
                  # just pass through from an external program
        $makeout .= $_;
    }
    $pipe-&gt;close;
    my $close_ok = $? == 0;
    $self-&gt;introduce_myself;
    if ( $close_ok ) {
        $CPAN::Frontend-&gt;myprint("  $system -- OK\n");
        $CPAN::META-&gt;is_installed($self-&gt;{build_dir});
        $self-&gt;{install} = CPAN::Distrostatus-&gt;new("YES");
        if ($CPAN::Config-&gt;{'cleanup_after_install'}
            &amp;&amp; ! $self-&gt;is_dot_dist) {
            my $parent = File::Spec-&gt;catdir( $self-&gt;{build_dir}, File::Spec-&gt;updir );
            chdir $parent or $CPAN::Frontend-&gt;mydie("Couldn't chdir to $parent: $!\n");
            File::Path::rmtree($self-&gt;{build_dir});
            my $yml = "$self-&gt;{build_dir}.yml";
            if (-e $yml) {
                unlink $yml or $CPAN::Frontend-&gt;mydie("Couldn't unlink $yml: $!\n");
            }
        }
    } else {
        $self-&gt;{install} = CPAN::Distrostatus-&gt;new("NO");
        $CPAN::Frontend-&gt;mywarn("  $system -- NOT OK\n");
        my $mimc =
            CPAN::HandleConfig-&gt;prefs_lookup($self,
                                             q{make_install_make_command});
        if (
            $makeout =~ /permission/s
            &amp;&amp; $&gt; &gt; 0
            &amp;&amp; (
                ! $mimc
                || $mimc eq (CPAN::HandleConfig-&gt;prefs_lookup($self,
                                                              q{make}))
               )
           ) {
            $CPAN::Frontend-&gt;myprint(
                                     qq{----\n}.
                                     qq{  You may have to su }.
                                     qq{to root to install the package\n}.
                                     qq{  (Or you may want to run something like\n}.
                                     qq{    o conf make_install_make_command 'sudo make'\n}.
                                     qq{  to raise your permissions.}
                                    );
        }
    }
    delete $self-&gt;{force_update};
    unless ($CPAN::Config-&gt;{'cleanup_after_install'}) {
        $self-&gt;store_persistent_state;
    }

    $self-&gt;post_install();

    return !! $close_ok;
}

sub introduce_myself {
    my($self) = @_;
    $CPAN::Frontend-&gt;myprint(sprintf("  %s\n",$self-&gt;pretty_id));
}

#-&gt; sub CPAN::Distribution::dir ;
sub dir {
    shift-&gt;{build_dir};
}

#-&gt; sub CPAN::Distribution::perldoc ;
sub perldoc {
    my($self) = @_;

    my($dist) = $self-&gt;id;
    my $package = $self-&gt;called_for;

    if ($CPAN::META-&gt;has_inst("Pod::Perldocs")) {
        my($perl) = $self-&gt;perl
            or $CPAN::Frontend-&gt;mydie("Couldn't find executable perl\n");
        my @args = ($perl, q{-MPod::Perldocs}, q{-e},
                    q{Pod::Perldocs-&gt;run()}, $package);
        my($wstatus);
        unless ( ($wstatus = system(@args)) == 0 ) {
            my $estatus = $wstatus &gt;&gt; 8;
            $CPAN::Frontend-&gt;myprint(qq{
    Function system("@args")
    returned status $estatus (wstat $wstatus)
    });
        }
    }
    else {
        $self-&gt;_display_url( $CPAN::Defaultdocs . $package );
    }
}

#-&gt; sub CPAN::Distribution::_check_binary ;
sub _check_binary {
    my ($dist,$shell,$binary) = @_;
    my ($pid,$out);

    $CPAN::Frontend-&gt;myprint(qq{ + _check_binary($binary)\n})
      if $CPAN::DEBUG;

    if ($CPAN::META-&gt;has_inst("File::Which")) {
        return File::Which::which($binary);
    } else {
        local *README;
        $pid = open README, "which $binary|"
            or $CPAN::Frontend-&gt;mywarn(qq{Could not fork 'which $binary': $!\n});
        return unless $pid;
        while (&lt;README&gt;) {
            $out .= $_;
        }
        close README
            or $CPAN::Frontend-&gt;mywarn("Could not run 'which $binary': $!\n")
                and return;
    }

    $CPAN::Frontend-&gt;myprint(qq{   + $out \n})
      if $CPAN::DEBUG &amp;&amp; $out;

    return $out;
}

#-&gt; sub CPAN::Distribution::_display_url ;
sub _display_url {
    my($self,$url) = @_;
    my($res,$saved_file,$pid,$out);

    $CPAN::Frontend-&gt;myprint(qq{ + _display_url($url)\n})
      if $CPAN::DEBUG;

    # should we define it in the config instead?
    my $html_converter = "html2text";

    my $web_browser = $CPAN::Config-&gt;{'lynx'} || undef;
    my $web_browser_out = $web_browser
        ? CPAN::Distribution-&gt;_check_binary($self,$web_browser)
        : undef;

    if ($web_browser_out) {
        # web browser found, run the action
        my $browser = CPAN::HandleConfig-&gt;safe_quote($CPAN::Config-&gt;{'lynx'});
        $CPAN::Frontend-&gt;myprint(qq{system[$browser $url]})
            if $CPAN::DEBUG;
        $CPAN::Frontend-&gt;myprint(qq{
Displaying URL
  $url
with browser $browser
});
        $CPAN::Frontend-&gt;mysleep(1);
        system("$browser $url");
        if ($saved_file) { 1 while unlink($saved_file) }
    } else {
        # web browser not found, let's try text only
        my $html_converter_out =
            CPAN::Distribution-&gt;_check_binary($self,$html_converter);
        $html_converter_out = CPAN::HandleConfig-&gt;safe_quote($html_converter_out);

        if ($html_converter_out ) {
            # html2text found, run it
            $saved_file = CPAN::Distribution-&gt;_getsave_url( $self, $url );
            $CPAN::Frontend-&gt;mydie(qq{ERROR: problems while getting $url\n})
                unless defined($saved_file);

            local *README;
            $pid = open README, "$html_converter $saved_file |"
                or $CPAN::Frontend-&gt;mydie(qq{
Could not fork '$html_converter $saved_file': $!});
            my($fh,$filename);
            if ($CPAN::META-&gt;has_usable("File::Temp")) {
                $fh = File::Temp-&gt;new(
                                      dir      =&gt; File::Spec-&gt;tmpdir,
                                      template =&gt; 'cpan_htmlconvert_XXXX',
                                      suffix =&gt; '.txt',
                                      unlink =&gt; 0,
                                     );
                $filename = $fh-&gt;filename;
            } else {
                $filename = "cpan_htmlconvert_$$.txt";
                $fh = FileHandle-&gt;new();
                open $fh, "&gt;$filename" or die;
            }
            while (&lt;README&gt;) {
                $fh-&gt;print($_);
            }
            close README or
                $CPAN::Frontend-&gt;mydie(qq{Could not run '$html_converter $saved_file': $!});
            my $tmpin = $fh-&gt;filename;
            $CPAN::Frontend-&gt;myprint(sprintf(qq{
Run '%s %s' and
saved output to %s\n},
                                             $html_converter,
                                             $saved_file,
                                             $tmpin,
                                            )) if $CPAN::DEBUG;
            close $fh;
            local *FH;
            open FH, $tmpin
                or $CPAN::Frontend-&gt;mydie(qq{Could not open "$tmpin": $!});
            my $fh_pager = FileHandle-&gt;new;
            local($SIG{PIPE}) = "IGNORE";
            my $pager = $CPAN::Config-&gt;{'pager'} || "cat";
            $fh_pager-&gt;open("|$pager")
                or $CPAN::Frontend-&gt;mydie(qq{
Could not open pager '$pager': $!});
            $CPAN::Frontend-&gt;myprint(qq{
Displaying URL
  $url
with pager "$pager"
});
            $CPAN::Frontend-&gt;mysleep(1);
            $fh_pager-&gt;print(&lt;FH&gt;);
            $fh_pager-&gt;close;
        } else {
            # coldn't find the web browser or html converter
            $CPAN::Frontend-&gt;myprint(qq{
You need to install lynx or $html_converter to use this feature.});
        }
    }
}

#-&gt; sub CPAN::Distribution::_getsave_url ;
sub _getsave_url {
    my($dist, $shell, $url) = @_;

    $CPAN::Frontend-&gt;myprint(qq{ + _getsave_url($url)\n})
      if $CPAN::DEBUG;

    my($fh,$filename);
    if ($CPAN::META-&gt;has_usable("File::Temp")) {
        $fh = File::Temp-&gt;new(
                              dir      =&gt; File::Spec-&gt;tmpdir,
                              template =&gt; "cpan_getsave_url_XXXX",
                              suffix =&gt; ".html",
                              unlink =&gt; 0,
                             );
        $filename = $fh-&gt;filename;
    } else {
        $fh = FileHandle-&gt;new;
        $filename = "cpan_getsave_url_$$.html";
    }
    my $tmpin = $filename;
    if ($CPAN::META-&gt;has_usable('LWP')) {
        $CPAN::Frontend-&gt;myprint("Fetching with LWP:
  $url
");
        my $Ua;
        CPAN::LWP::UserAgent-&gt;config;
        eval { $Ua = CPAN::LWP::UserAgent-&gt;new; };
        if ($@) {
            $CPAN::Frontend-&gt;mywarn("ERROR: CPAN::LWP::UserAgent-&gt;new dies with $@\n");
            return;
        } else {
            my($var);
            $Ua-&gt;proxy('http', $var)
                if $var = $CPAN::Config-&gt;{http_proxy} || $ENV{http_proxy};
            $Ua-&gt;no_proxy($var)
                if $var = $CPAN::Config-&gt;{no_proxy} || $ENV{no_proxy};
        }

        my $req = HTTP::Request-&gt;new(GET =&gt; $url);
        $req-&gt;header('Accept' =&gt; 'text/html');
        my $res = $Ua-&gt;request($req);
        if ($res-&gt;is_success) {
            $CPAN::Frontend-&gt;myprint(" + request successful.\n")
                if $CPAN::DEBUG;
            print $fh $res-&gt;content;
            close $fh;
            $CPAN::Frontend-&gt;myprint(qq{ + saved content to $tmpin \n})
                if $CPAN::DEBUG;
            return $tmpin;
        } else {
            $CPAN::Frontend-&gt;myprint(sprintf(
                                             "LWP failed with code[%s], message[%s]\n",
                                             $res-&gt;code,
                                             $res-&gt;message,
                                            ));
            return;
        }
    } else {
        $CPAN::Frontend-&gt;mywarn("  LWP not available\n");
        return;
    }
}

#-&gt; sub CPAN::Distribution::_build_command
sub _build_command {
    my($self) = @_;
    if ($^O eq "MSWin32") { # special code needed at least up to
                            # Module::Build 0.2611 and 0.2706; a fix
                            # in M:B has been promised 2006-01-30
        my($perl) = $self-&gt;perl or $CPAN::Frontend-&gt;mydie("Couldn't find executable perl\n");
        return "$perl ./Build";
    }
    elsif ($^O eq 'VMS') {
        return "$^X Build.com";
    }
    return "./Build";
}

#-&gt; sub CPAN::Distribution::_should_report
sub _should_report {
    my($self, $phase) = @_;
    die "_should_report() requires a 'phase' argument"
        if ! defined $phase;

    # configured
    my $test_report = CPAN::HandleConfig-&gt;prefs_lookup($self,
                                                       q{test_report});
    return unless $test_report;

    # don't repeat if we cached a result
    return $self-&gt;{should_report}
        if exists $self-&gt;{should_report};

    # don't report if we generated a Makefile.PL
    if ( $self-&gt;{had_no_makefile_pl} ) {
        $CPAN::Frontend-&gt;mywarn(
            "Will not send CPAN Testers report with generated Makefile.PL.\n"
        );
        return $self-&gt;{should_report} = 0;
    }

    # available
    if ( ! $CPAN::META-&gt;has_inst("CPAN::Reporter")) {
        $CPAN::Frontend-&gt;mywarnonce(
            "CPAN::Reporter not installed.  No reports will be sent.\n"
        );
        return $self-&gt;{should_report} = 0;
    }

    # capable
    my $crv = CPAN::Reporter-&gt;VERSION;
    if ( CPAN::Version-&gt;vlt( $crv, 0.99 ) ) {
        # don't cache $self-&gt;{should_report} -- need to check each phase
        if ( $phase eq 'test' ) {
            return 1;
        }
        else {
            $CPAN::Frontend-&gt;mywarn(
                "Reporting on the '$phase' phase requires CPAN::Reporter 0.99, but \n" .
                "you only have version $crv\.  Only 'test' phase reports will be sent.\n"
            );
            return;
        }
    }

    # appropriate
    if ($self-&gt;is_dot_dist) {
        $CPAN::Frontend-&gt;mywarn("Reporting via CPAN::Reporter is disabled ".
                                "for local directories\n");
        return $self-&gt;{should_report} = 0;
    }
    if ($self-&gt;prefs-&gt;{patches}
        &amp;&amp;
        @{$self-&gt;prefs-&gt;{patches}}
        &amp;&amp;
        $self-&gt;{patched}
       ) {
        $CPAN::Frontend-&gt;mywarn("Reporting via CPAN::Reporter is disabled ".
                                "when the source has been patched\n");
        return $self-&gt;{should_report} = 0;
    }

    # proceed and cache success
    return $self-&gt;{should_report} = 1;
}

#-&gt; sub CPAN::Distribution::reports
sub reports {
    my($self) = @_;
    my $pathname = $self-&gt;id;
    $CPAN::Frontend-&gt;myprint("Distribution: $pathname\n");

    unless ($CPAN::META-&gt;has_inst("CPAN::DistnameInfo")) {
        $CPAN::Frontend-&gt;mydie("CPAN::DistnameInfo not installed; cannot continue");
    }
    unless ($CPAN::META-&gt;has_usable("LWP")) {
        $CPAN::Frontend-&gt;mydie("LWP not installed; cannot continue");
    }
    unless ($CPAN::META-&gt;has_usable("File::Temp")) {
        $CPAN::Frontend-&gt;mydie("File::Temp not installed; cannot continue");
    }

    my $format;
    if ($CPAN::META-&gt;has_inst("YAML::XS") || $CPAN::META-&gt;has_inst("YAML::Syck")){
        $format = 'yaml';
    }
    elsif (!$format &amp;&amp; $CPAN::META-&gt;has_inst("JSON::PP") ) {
        $format = 'json';
    }
    else {
        $CPAN::Frontend-&gt;mydie("JSON::PP not installed, cannot continue");
    }

    my $d = CPAN::DistnameInfo-&gt;new($pathname);

    my $dist      = $d-&gt;dist;      # "CPAN-DistnameInfo"
    my $version   = $d-&gt;version;   # "0.02"
    my $maturity  = $d-&gt;maturity;  # "released"
    my $filename  = $d-&gt;filename;  # "CPAN-DistnameInfo-0.02.tar.gz"
    my $cpanid    = $d-&gt;cpanid;    # "GBARR"
    my $distvname = $d-&gt;distvname; # "CPAN-DistnameInfo-0.02"

    my $url = sprintf "http://www.cpantesters.org/show/%s.%s", $dist, $format;

    CPAN::LWP::UserAgent-&gt;config;
    my $Ua;
    eval { $Ua = CPAN::LWP::UserAgent-&gt;new; };
    if ($@) {
        $CPAN::Frontend-&gt;mydie("CPAN::LWP::UserAgent-&gt;new dies with $@\n");
    }
    $CPAN::Frontend-&gt;myprint("Fetching '$url'...");
    my $resp = $Ua-&gt;get($url);
    unless ($resp-&gt;is_success) {
        $CPAN::Frontend-&gt;mydie(sprintf "Could not download '%s': %s\n", $url, $resp-&gt;code);
    }
    $CPAN::Frontend-&gt;myprint("DONE\n\n");
    my $unserialized;
    if ( $format eq 'yaml' ) {
        my $yaml = $resp-&gt;content;
        # what a long way round!
        my $fh = File::Temp-&gt;new(
                                 dir      =&gt; File::Spec-&gt;tmpdir,
                                 template =&gt; 'cpan_reports_XXXX',
                                 suffix =&gt; '.yaml',
                                 unlink =&gt; 0,
                                );
        my $tfilename = $fh-&gt;filename;
        print $fh $yaml;
        close $fh or $CPAN::Frontend-&gt;mydie("Could not close '$tfilename': $!");
        $unserialized = CPAN-&gt;_yaml_loadfile($tfilename)-&gt;[0];
        unlink $tfilename or $CPAN::Frontend-&gt;mydie("Could not unlink '$tfilename': $!");
    } else {
        require JSON::PP;
        $unserialized = JSON::PP-&gt;new-&gt;utf8-&gt;decode($resp-&gt;content);
    }
    my %other_versions;
    my $this_version_seen;
    for my $rep (@$unserialized) {
        my $rversion = $rep-&gt;{version};
        if ($rversion eq $version) {
            unless ($this_version_seen++) {
                $CPAN::Frontend-&gt;myprint ("$rep-&gt;{version}:\n");
            }
            my $arch = $rep-&gt;{archname} || $rep-&gt;{platform}        || '????';
            my $grade = $rep-&gt;{action}  || $rep-&gt;{status}          || '????';
            my $ostext = $rep-&gt;{ostext} || ucfirst($rep-&gt;{osname}) || '????';
            $CPAN::Frontend-&gt;myprint
                (sprintf("%1s%1s%-4s %s on %s %s (%s)\n",
                         $arch eq $Config::Config{archname}?"*":"",
                         $grade eq "PASS"?"+":$grade eq"FAIL"?"-":"",
                         $grade,
                         $rep-&gt;{perl},
                         $ostext,
                         $rep-&gt;{osvers},
                         $arch,
                        ));
        } else {
            $other_versions{$rep-&gt;{version}}++;
        }
    }
    unless ($this_version_seen) {
        $CPAN::Frontend-&gt;myprint("No reports found for version '$version'
Reports for other versions:\n");
        for my $v (sort keys %other_versions) {
            $CPAN::Frontend-&gt;myprint(" $v\: $other_versions{$v}\n");
        }
    }
    $url = substr($url,0,-4) . 'html';
    $CPAN::Frontend-&gt;myprint("See $url for details\n");
}

1;
</pre></body></html>