<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package CPANPLUS::Module;
use deprecate;

use strict;
use vars qw[@ISA $VERSION];
$VERSION = "0.9135";

use CPANPLUS::Dist;
use CPANPLUS::Error;
use CPANPLUS::Module::Signature;
use CPANPLUS::Module::Checksums;
use CPANPLUS::Internals::Constants;

use FileHandle;

use Locale::Maketext::Simple    Class =&gt; 'CPANPLUS', Style =&gt; 'gettext';
use IPC::Cmd                    qw[can_run run];
use File::Find                  qw[find];
use Params::Check               qw[check];
use File::Basename              qw[dirname];
use Module::Load::Conditional   qw[can_load check_install];

$Params::Check::VERBOSE = 1;

@ISA = qw[ CPANPLUS::Module::Signature CPANPLUS::Module::Checksums];

=pod

=head1 NAME

CPANPLUS::Module - CPAN module objects for CPANPLUS

=head1 SYNOPSIS

    ### get a module object from the CPANPLUS::Backend object
    my $mod = $cb-&gt;module_tree('Some::Module');

    ### accessors
    $mod-&gt;version;
    $mod-&gt;package;

    ### methods
    $mod-&gt;fetch;
    $mod-&gt;extract;
    $mod-&gt;install;


=head1 DESCRIPTION

C&lt;CPANPLUS::Module&gt; creates objects from the information in the
source files. These can then be used to query and perform actions
on, like fetching or installing.

These objects should only be created internally. For C&lt;fake&gt; objects,
there's the C&lt;CPANPLUS::Module::Fake&gt; class. To obtain a module object
consult the C&lt;CPANPLUS::Backend&gt; documentation.

=cut

my $tmpl = {
    module      =&gt; { default =&gt; '', required =&gt; 1 },    # full module name
    version     =&gt; { default =&gt; '0.0' },                # version number
    path        =&gt; { default =&gt; '', required =&gt; 1 },    # extended path on the
                                                        # cpan mirror, like
                                                        # /author/id/K/KA/KANE
    comment     =&gt; { default =&gt; ''},                    # comment on module
    package     =&gt; { default =&gt; '', required =&gt; 1 },    # package name, like
                                                        # 'bar-baz-1.03.tgz'
    description =&gt; { default =&gt; '' },                   # description of the
                                                        # module
    dslip       =&gt; { default =&gt; EMPTY_DSLIP },          # dslip information
    _id         =&gt; { required =&gt; 1 },                   # id of the Internals
                                                        # parent object
    _status     =&gt; { no_override =&gt; 1 },                # stores status object
    author      =&gt; { default =&gt; '', required =&gt; 1,
                     allow =&gt; IS_AUTHOBJ },             # module author
    mtime       =&gt; { default =&gt; '' },
};

### some of these will be resolved by wrapper functions that
### do Clever Things to find the actual value, so don't create
### an autogenerated sub for that just here, take an alternate
### name to allow for a wrapper
{   my %rename = (
        dslip   =&gt; '_dslip'
    );

    ### autogenerate accessors ###
    for my $key ( keys %$tmpl ) {
        no strict 'refs';

        my $sub = $rename{$key} || $key;

        *{__PACKAGE__."::$sub"} = sub {
            $_[0]-&gt;{$key} = $_[1] if @_ &gt; 1;
            return $_[0]-&gt;{$key};
        }
    }
}


=pod

=head1 CLASS METHODS

=head2 accessors ()

Returns a list of all accessor methods to the object

=cut

### *name is an alias, include it explicitly
sub accessors { return ('name', keys %$tmpl) };

=head1 ACCESSORS

An objects of this class has the following accessors:

=over 4

=item name

Name of the module.

=item module

Name of the module.

=item version

Version of the module. Defaults to '0.0' if none was provided.

=item path

Extended path on the mirror.

=item comment

Any comment about the module -- largely unused.

=item package

The name of the package.

=item description

Description of the module -- only registered modules have this.

=item dslip

The five character dslip string, that represents meta-data of the
module -- again, only registered modules have this.

=cut

sub dslip {
    my $self    = shift;

    ### if this module has relevant dslip info, return it
    return $self-&gt;_dslip if $self-&gt;_dslip ne EMPTY_DSLIP;

    ### if not, look at other modules in the same package,
    ### see if *they* have any dslip info
    for my $mod ( $self-&gt;contains ) {
        return $mod-&gt;_dslip if $mod-&gt;_dslip ne EMPTY_DSLIP;
    }

    ### ok, really no dslip info found, return the default
    return EMPTY_DSLIP;
}


=pod

=item status

The C&lt;CPANPLUS::Module::Status&gt; object associated with this object.
(see below).

=item author

The C&lt;CPANPLUS::Module::Author&gt; object associated with this object.

=item parent

The C&lt;CPANPLUS::Internals&gt; object that spawned this module object.

=back

=cut

### Alias -&gt;name to -&gt;module, for human beings.
*name = *module;

sub parent {
    my $self = shift;
    my $obj  = CPANPLUS::Internals-&gt;_retrieve_id( $self-&gt;_id );

    return $obj;
}

=head1 STATUS ACCESSORS

C&lt;CPANPLUS&gt; caches a lot of results from method calls and saves data
it collected along the road for later reuse.

C&lt;CPANPLUS&gt; uses this internally, but it is also available for the end
user. You can get a status object by calling:

    $modobj-&gt;status

You can then query the object as follows:

=over 4

=item installer_type

The installer type used for this distribution. Will be one of
'makemaker' or 'build'. This determines whether C&lt;CPANPLUS::Dist::MM&gt;
or C&lt;CPANPLUS::Dist::Build&gt; will be used to build this distribution.

=item dist_cpan

The dist object used to do the CPAN-side of the installation. Either
a C&lt;CPANPLUS::Dist::MM&gt; or C&lt;CPANPLUS::Dist::Build&gt; object.

=item dist

The custom dist object used to do the operating specific side of the
installation, if you've chosen to use this. For example, if you've
chosen to install using the C&lt;ports&gt; format, this may be a
C&lt;CPANPLUS::Dist::Ports&gt; object.

Undefined if you didn't specify a separate format to install through.

=item prereqs | requires

A hashref of prereqs this distribution was found to have. Will look
something like this:

    { Carp  =&gt; 0.01, strict =&gt; 0 }

Might be undefined if the distribution didn't have any prerequisites.

=item configure_requires

Like prereqs, but these are necessary to be installed before the
build process can even begin.

=item signature

Flag indicating, if a signature check was done, whether it was OK or
not.

=item extract

The directory this distribution was extracted to.

=item fetch

The location this distribution was fetched to.

=item readme

The text of this distributions README file.

=item uninstall

Flag indicating if an uninstall call was done successfully.

=item created

Flag indicating if the C&lt;create&gt; call to your dist object was done
successfully.

=item installed

Flag indicating if the C&lt;install&gt; call to your dist object was done
successfully.

=item checksums

The location of this distributions CHECKSUMS file.

=item checksum_ok

Flag indicating if the checksums check was done successfully.

=item checksum_value

The checksum value this distribution is expected to have

=back

=head1 METHODS

=head2 $self = CPANPLUS::Module-&gt;new( OPTIONS )

This method returns a C&lt;CPANPLUS::Module&gt; object. Normal users
should never call this method directly, but instead use the
C&lt;CPANPLUS::Backend&gt; to obtain module objects.

This example illustrates a C&lt;new()&gt; call with all required arguments:

        CPANPLUS::Module-&gt;new(
            module  =&gt; 'Foo',
            path    =&gt; 'authors/id/A/AA/AAA',
            package =&gt; 'Foo-1.0.tgz',
            author  =&gt; $author_object,
            _id     =&gt; INTERNALS_OBJECT_ID,
        );

Every accessor is also a valid option to pass to C&lt;new&gt;.

Returns a module object on success and false on failure.

=cut


sub new {
    my($class, %hash) = @_;

    ### don't check the template for sanity
    ### -- we know it's good and saves a lot of performance
    local $Params::Check::SANITY_CHECK_TEMPLATE = 0;

    my $object  = check( $tmpl, \%hash ) or return;

    bless $object, $class;

    return $object;
}

### only create status objects when they're actually asked for
sub status {
    my $self = shift;
    return $self-&gt;_status if $self-&gt;_status;

    my $acc = Object::Accessor-&gt;new;
    $acc-&gt;mk_accessors( qw[ installer_type dist_cpan dist prereqs
                            signature extract fetch readme uninstall
                            created installed prepared checksums files
                            checksum_ok checksum_value _fetch_from
                            configure_requires
                        ] );

    ### create an alias from 'requires' to 'prereqs', so it's more in
    ### line with 'configure_requires';
    $acc-&gt;mk_aliases( requires =&gt; 'prereqs' );

    $self-&gt;_status( $acc );

    return $self-&gt;_status;
}


### flush the cache of this object ###
sub _flush {
    my $self = shift;
    $self-&gt;status-&gt;mk_flush;
    return 1;
}

=head2 $mod-&gt;package_name( [$package_string] )

Returns the name of the package a module is in. For C&lt;Acme::Bleach&gt;
that might be C&lt;Acme-Bleach&gt;.

=head2 $mod-&gt;package_version( [$package_string] )

Returns the version of the package a module is in. For a module
in the package C&lt;Acme-Bleach-1.1.tar.gz&gt; this would be C&lt;1.1&gt;.

=head2 $mod-&gt;package_extension( [$package_string] )

Returns the suffix added by the compression method of a package a
certain module is in. For a module in C&lt;Acme-Bleach-1.1.tar.gz&gt;, this
would be C&lt;tar.gz&gt;.

=head2 $mod-&gt;package_is_perl_core

Returns a boolean indicating of the package a particular module is in,
is actually a core perl distribution.

=head2 $mod-&gt;module_is_supplied_with_perl_core( [version =&gt; $]] )

Returns a boolean indicating whether C&lt;ANY VERSION&gt; of this module
was supplied with the current running perl's core package.

=head2 $mod-&gt;is_bundle

Returns a boolean indicating if the module you are looking at, is
actually a bundle. Bundles are identified as modules whose name starts
with C&lt;Bundle::&gt;.

=head2 $mod-&gt;is_autobundle;

Returns a boolean indicating if the module you are looking at, is
actually an autobundle as generated by C&lt;&lt; $cb-&gt;autobundle &gt;&gt;.

=head2 $mod-&gt;is_third_party

Returns a boolean indicating whether the package is a known third-party
module (i.e. it's not provided by the standard Perl distribution and
is not available on the CPAN, but on a third party software provider).
See L&lt;Module::ThirdParty&gt; for more details.

=head2 $mod-&gt;third_party_information

Returns a reference to a hash with more information about a third-party
module. See the documentation about C&lt;module_information()&gt; in
L&lt;Module::ThirdParty&gt; for more details.

=cut

{   ### fetches the test reports for a certain module ###
    my %map = (
        name        =&gt; 0,
        version     =&gt; 1,
        extension   =&gt; 2,
    );

    while ( my($type, $index) = each %map ) {
        my $name    = 'package_' . $type;

        no strict 'refs';
        *$name = sub {
            my $self = shift;
            my $val  = shift || $self-&gt;package;
            my @res  = $self-&gt;parent-&gt;_split_package_string( package =&gt; $val );

            ### return the corresponding index from the result
            return $res[$index] if @res;
            return;
        };
    }

    sub package_is_perl_core {
        my $self = shift;
        my $cb   = $self-&gt;parent;

        ### check if the package looks like a perl core package
        return 1 if $self-&gt;package_name eq PERL_CORE;

        ### address #44562: ::Module-&gt;package_is_perl_code : problem comparing
        ### version strings -- use $cb-&gt;_vcmp to avoid warnings when version
        ### have _ in them

        my $core = $self-&gt;module_is_supplied_with_perl_core;
        ### ok, so it's found in the core, BUT it could be dual-lifed
        if (defined $core) {
            ### if the package is newer than installed, then it's dual-lifed
            return if $cb-&gt;_vcmp($self-&gt;version, $self-&gt;installed_version) &gt; 0;

            ### if the package is newer or equal to the corelist,
            ### then it's dual-lifed
            return if $cb-&gt;_vcmp( $self-&gt;version, $core ) &gt;= 0;

            ### otherwise, it's older than corelist, thus unsuitable.
            return 1;
        }

        ### not in corelist, not a perl core package.
        return;
    }

    sub module_is_supplied_with_perl_core {
        my $self = shift;
        my $ver  = shift || $];

        ### allow it to be called as a package function as well like:
        ###   CPANPLUS::Module::module_is_supplied_with_perl_core('Config')
        ### so that we can check the status of modules that aren't released
        ### to CPAN, but are part of the core.
        my $name = ref $self ? $self-&gt;module : $self;

        ### check Module::CoreList to see if it's a core package
        require Module::CoreList;

        ### Address #41157: Module::module_is_supplied_with_perl_core()
        ### broken for perl 5.10: Module::CoreList's version key for the
        ### hash has a different number of trailing zero than $] aka
        ### $PERL_VERSION.

        my $core;

        if ( exists $Module::CoreList::version{ 0+$ver }-&gt;{ $name } ) {
          $core = $Module::CoreList::version{ 0+$ver }-&gt;{ $name };
          $core = 0 unless $core;
        }
        return $core;
    }

    ### make sure Bundle-Foo also gets flagged as bundle
    sub is_bundle {
        my $self = shift;

        ### cpan'd bundle
        return 1 if $self-&gt;module =~ /^bundle(?:-|::)/i;

        ### autobundle
        return 1 if $self-&gt;is_autobundle;

        ### neither
        return;
    }

    ### full path to a generated autobundle
    sub is_autobundle {
        my $self    = shift;
        my $conf    = $self-&gt;parent-&gt;configure_object;
        my $prefix  = $conf-&gt;_get_build('autobundle_prefix');

        return 1 if $self-&gt;module eq $prefix;
        return;
    }

    sub is_third_party {
        my $self = shift;

        return unless can_load( modules =&gt; { 'Module::ThirdParty' =&gt; 0 } );

        return Module::ThirdParty::is_3rd_party( $self-&gt;name );
    }

    sub third_party_information {
        my $self = shift;

        return unless $self-&gt;is_third_party;

        return Module::ThirdParty::module_information( $self-&gt;name );
    }
}

=pod

=head2 $clone = $self-&gt;clone

Clones the current module object for tinkering with.
It will have a clean C&lt;CPANPLUS::Module::Status&gt; object, as well as
a fake C&lt;CPANPLUS::Module::Author&gt; object.

=cut

{   ### accessors dont change during run time, so only compute once
    my @acc = grep !/status/, __PACKAGE__-&gt;accessors();

    sub clone {
        my $self = shift;

        ### clone the object ###
        my %data = map { $_ =&gt; $self-&gt;$_ } @acc;

        my $obj = CPANPLUS::Module::Fake-&gt;new( %data );

        return $obj;
    }
}

=pod

=head2 $where = $self-&gt;fetch

Fetches the module from a CPAN mirror.
Look at L&lt;CPANPLUS::Internals::Fetch::_fetch()&gt; for details on the
options you can pass.

=cut

sub fetch {
    my $self = shift;
    my $cb   = $self-&gt;parent;

    ### custom args
    my %args            = ( module =&gt; $self );

    ### if a custom fetch location got specified before, add that here
    $args{fetch_from}   = $self-&gt;status-&gt;_fetch_from
                            if $self-&gt;status-&gt;_fetch_from;

    my $where = $cb-&gt;_fetch( @_, %args ) or return;

    ### do an md5 check ###
    if( !$self-&gt;status-&gt;_fetch_from and
        $cb-&gt;configure_object-&gt;get_conf('md5') and
        $self-&gt;package ne CHECKSUMS
    ) {
        unless( $self-&gt;_validate_checksum ) {
            error( loc( "Checksum error for '%1' -- will not trust package",
                        $self-&gt;package) );
            return;
        }
    }

    return $where;
}

=pod

=head2 $path = $self-&gt;extract

Extracts the fetched module.
Look at L&lt;CPANPLUS::Internals::Extract::_extract()&gt; for details on
the options you can pass.

=cut

sub extract {
    my $self = shift;
    my $cb   = $self-&gt;parent;

    unless( $self-&gt;status-&gt;fetch ) {
        error( loc( "You have not fetched '%1' yet -- cannot extract",
                    $self-&gt;module) );
        return;
    }

    ### can't extract these, so just use the basedir for the file
    if( $self-&gt;is_autobundle ) {

        ### this is expected to be set after an extract call
        $self-&gt;get_installer_type;

        return $self-&gt;status-&gt;extract( dirname( $self-&gt;status-&gt;fetch ) );
    }

    return $cb-&gt;_extract( @_, module =&gt; $self );
}

=head2 $type = $self-&gt;get_installer_type([prefer_makefile =&gt; BOOL])

Gets the installer type for this module. This may either be C&lt;build&gt; or
C&lt;makemaker&gt;. If C&lt;Module::Build&gt; is unavailable or no installer type
is available, it will fall back to C&lt;makemaker&gt;. If both are available,
it will pick the one indicated by your config, or by the
C&lt;prefer_makefile&gt; option you can pass to this function.

Returns the installer type on success, and false on error.

=cut

sub get_installer_type {
    my $self = shift;
    my $cb   = $self-&gt;parent;
    my $conf = $cb-&gt;configure_object;
    my %hash = @_;

    my ($prefer_makefile,$verbose);
    my $tmpl = {
        prefer_makefile =&gt; { default =&gt; $conf-&gt;get_conf('prefer_makefile'),
                             store   =&gt; \$prefer_makefile, allow =&gt; BOOLEANS },
        verbose         =&gt; { default =&gt; $conf-&gt;get_conf('verbose'),
                             store   =&gt; \$verbose },
    };

    check( $tmpl, \%hash ) or return;

    my $type;

    ### autobundles use their own installer, so return that
    if( $self-&gt;is_autobundle ) {
        $type = INSTALLER_AUTOBUNDLE;

    } else {
        my $extract = $self-&gt;status-&gt;extract();
        unless( $extract ) {
            error(loc(
                "Cannot determine installer type of unextracted module '%1'",
                $self-&gt;module
            ));
            return;
        }

        ### check if it's a makemaker or a module::build type dist ###
        my $found_build     = -e BUILD_PL-&gt;( $extract );
        my $found_makefile  = -e MAKEFILE_PL-&gt;( $extract );

        $type = INSTALLER_BUILD if !$prefer_makefile &amp;&amp;  $found_build;
        $type = INSTALLER_BUILD if  $found_build     &amp;&amp; !$found_makefile;
        $type = INSTALLER_MM    if  $prefer_makefile &amp;&amp;  $found_makefile;
        $type = INSTALLER_MM    if  $found_makefile  &amp;&amp; !$found_build;
        # Special case Module::Build to always use INSTALLER_MM
        $type = INSTALLER_MM    if  $self-&gt;package =~ m{^Module-Build-\d};

    }

    ### ok, so it's a 'build' installer, but you don't /have/ module build
    ### XXX duplicated from CPANPLUS::Selfupdate. fix somehow?
    if( $type and $type eq INSTALLER_BUILD and (
        not CPANPLUS::Dist-&gt;has_dist_type( INSTALLER_BUILD )
        or not $cb-&gt;module_tree( INSTALLER_BUILD )
                    -&gt;is_uptodate( version =&gt; '0.60' )
    ) ) {

        ### XXX this is for recording purposes only. We *have* to install
        ### these before even creating a dist object, or we'll get an error
        ### saying 'no such dist type';
        ### XXX duplicated from CPANPLUS::Selfupdate. fix somehow?
        my $href = $self-&gt;status-&gt;configure_requires || {};
        my $deps = { INSTALLER_BUILD, '0.60', %$href };

        $self-&gt;status-&gt;configure_requires( $deps );

        msg(loc("This module requires '%1' and '%2' to be installed first. ".
                "Adding these modules to your prerequisites list",
                 'Module::Build', INSTALLER_BUILD
        ), $verbose );


    ### ok, actually we found neither ###
    } elsif ( !$type ) {
        error( loc( "Unable to find '%1' or '%2' for '%3'; ".
                    "Will default to '%4' but might be unable ".
                    "to install!", BUILD_PL-&gt;(), MAKEFILE_PL-&gt;(),
                    $self-&gt;module, INSTALLER_MM ) );
        $type = INSTALLER_MM;
    }

    return $self-&gt;status-&gt;installer_type( $type ) if $type;
    return;
}

=pod

=head2 $dist = $self-&gt;dist([target =&gt; 'prepare|create', format =&gt; DISTRIBUTION_TYPE, args =&gt; {key =&gt; val}]);

Create a distribution object, ready to be installed.
Distribution type defaults to your config settings

The optional C&lt;args&gt; hashref is passed on to the specific distribution
types' C&lt;create&gt; method after being dereferenced.

Returns a distribution object on success, false on failure.

See C&lt;CPANPLUS::Dist&gt; for details.

=cut

sub dist {
    my $self = shift;
    my $cb   = $self-&gt;parent;
    my $conf = $cb-&gt;configure_object;
    my %hash = @_;

    ### have you determined your installer type yet? if not, do it here,
    ### we need the info
    $self-&gt;get_installer_type unless $self-&gt;status-&gt;installer_type;

    my($type,$args,$target);
    my $tmpl = {
        format  =&gt; { default =&gt; $conf-&gt;get_conf('dist_type') ||
                                $self-&gt;status-&gt;installer_type,
                     store   =&gt; \$type },
        target  =&gt; { default =&gt; TARGET_CREATE, store =&gt; \$target },
        args    =&gt; { default =&gt; {}, store =&gt; \$args },
    };

    check( $tmpl, \%hash ) or return;

    ### ok, check for $type. Do we have it?
    unless( CPANPLUS::Dist-&gt;has_dist_type( $type ) ) {

        ### ok, we don't have it. Is it C::D::Build? if so we can install the
        ### whole thing now
        ### XXX we _could_ do this for any type we dont have actually...
        if( $type eq INSTALLER_BUILD ) {
            msg(loc("Bootstrapping installer '%1'", $type));

            ### don't propagate the format, it's the one we're trying to
            ### bootstrap, so it'll be an infinite loop if we do

            $cb-&gt;module_tree( $type )-&gt;install( target =&gt; $target, %$args ) or
                do {
                    error(loc("Could not bootstrap installer '%1' -- ".
                              "can not continue", $type));
                    return;
                };

            ### re-scan for available modules now
            CPANPLUS::Dist-&gt;rescan_dist_types;

            unless( CPANPLUS::Dist-&gt;has_dist_type( $type ) ) {
                error(loc("Newly installed installer type '%1' should be ".
                          "available, but is not! -- aborting", $type));
                return;
            } else {
                msg(loc("Installer '%1' successfully bootstrapped", $type));
            }

        ### some other plugin you dont have. Abort
        } else {
            error(loc("Installer type '%1' not found. Please verify your ".
                      "installation -- aborting", $type ));
            return;
        }
    }

    ### make sure we don't overwrite it, just in case we came
    ### back from a -&gt;save_state. This allows restoration to
    ### work correctly
    my( $dist, $dist_cpan );

    unless( $dist = $self-&gt;status-&gt;dist ) {
        $dist = $type-&gt;new( module =&gt; $self ) or return;
        $self-&gt;status-&gt;dist( $dist );
    }

    unless( $dist_cpan = $self-&gt;status-&gt;dist_cpan ) {

        $dist_cpan = $type eq $self-&gt;status-&gt;installer_type
                        ? $self-&gt;status-&gt;dist
                        : $self-&gt;status-&gt;installer_type-&gt;new( module =&gt; $self );


        $self-&gt;status-&gt;dist_cpan(   $dist_cpan );
    }


    DIST: {
        ### just wanted the $dist object?
        last DIST if $target eq TARGET_INIT;

        ### first prepare the dist
        $dist-&gt;prepare( %$args ) or return;
        $self-&gt;status-&gt;prepared(1);

        ### you just wanted us to prepare?
        last DIST if $target eq TARGET_PREPARE;

        $dist-&gt;create( %$args ) or return;
        $self-&gt;status-&gt;created(1);
    }

    return $dist;
}

=pod

=head2 $bool = $mod-&gt;prepare( )

Convenience method around C&lt;install()&gt; that prepares a module
without actually building it. This is equivalent to invoking C&lt;install&gt;
with C&lt;target&gt; set to C&lt;prepare&gt;

Returns true on success, false on failure.

=cut

sub prepare {
    my $self = shift;
    return $self-&gt;install( @_, target =&gt; TARGET_PREPARE );
}

=head2 $bool = $mod-&gt;create( )

Convenience method around C&lt;install()&gt; that creates a module.
This is equivalent to invoking C&lt;install&gt; with C&lt;target&gt; set to
C&lt;create&gt;

Returns true on success, false on failure.

=cut

sub create {
    my $self = shift;
    return $self-&gt;install( @_, target =&gt; TARGET_CREATE );
}

=head2 $bool = $mod-&gt;test( )

Convenience wrapper around C&lt;install()&gt; that tests a module, without
installing it.
It's the equivalent to invoking C&lt;install()&gt; with C&lt;target&gt; set to
C&lt;create&gt; and C&lt;skiptest&gt; set to C&lt;0&gt;.

Returns true on success, false on failure.

=cut

sub test {
    my $self = shift;
    return $self-&gt;install( @_, target =&gt; TARGET_CREATE, skiptest =&gt; 0 );
}

=pod

=head2 $bool = $self-&gt;install([ target =&gt; 'init|prepare|create|install', format =&gt; FORMAT_TYPE, extractdir =&gt; DIRECTORY, fetchdir =&gt; DIRECTORY, prefer_bin =&gt; BOOL, force =&gt; BOOL, verbose =&gt; BOOL, ..... ]);

Installs the current module. This includes fetching it and extracting
it, if this hasn't been done yet, as well as creating a distribution
object for it.

This means you can pass it more arguments than described above, which
will be passed on to the relevant methods as they are called.

See C&lt;CPANPLUS::Internals::Fetch&gt;, C&lt;CPANPLUS::Internals::Extract&gt; and
C&lt;CPANPLUS::Dist&gt; for details.

Returns true on success, false on failure.

=cut

sub install {
    my $self = shift;
    my $cb   = $self-&gt;parent;
    my $conf = $cb-&gt;configure_object;
    my %hash = @_;

    my $args; my $target; my $format;
    {   ### so we can use the rest of the args to the create calls etc ###
        local $Params::Check::NO_DUPLICATES = 1;
        local $Params::Check::ALLOW_UNKNOWN = 1;

        ### targets 'dist' and 'test' are now completely ignored ###
        my $tmpl = {
                        ### match this allow list with Dist-&gt;_resolve_prereqs
            target     =&gt; { default =&gt; TARGET_INSTALL, store =&gt; \$target,
                            allow   =&gt; [TARGET_PREPARE, TARGET_CREATE,
                                        TARGET_INSTALL, TARGET_INIT ] },
            force      =&gt; { default =&gt; $conf-&gt;get_conf('force'), },
            verbose    =&gt; { default =&gt; $conf-&gt;get_conf('verbose'), },
            format     =&gt; { default =&gt; $conf-&gt;get_conf('dist_type'),
                                store =&gt; \$format },
        };

        $args = check( $tmpl, \%hash ) or return;
    }


    ### if this target isn't 'install', we will need to at least 'create'
    ### every prereq, so it can build
    ### XXX prereq_target of 'prepare' will do weird things here, and is
    ### not supported.
    $args-&gt;{'prereq_target'} ||= TARGET_CREATE if $target ne TARGET_INSTALL;

    ### check if it's already upto date ###
    if( $target eq TARGET_INSTALL and !$args-&gt;{'force'} and
        !$self-&gt;package_is_perl_core() and         # separate rules apply
        ( $self-&gt;status-&gt;installed() or $self-&gt;is_uptodate ) and
        !INSTALL_VIA_PACKAGE_MANAGER-&gt;($format)
    ) {
        msg(loc("Module '%1' already up to date, won't install without force",
                $self-&gt;module), $args-&gt;{'verbose'} );
        return $self-&gt;status-&gt;installed(1);
    }

    # if it's a non-installable core package, abort the install.
    if( $self-&gt;package_is_perl_core() ) {
        # if the installed is newer, say so.
        if( $self-&gt;installed_version &gt; $self-&gt;version ) {
            error(loc("The core Perl %1 module '%2' (%3) is more ".
                      "recent than the latest release on CPAN (%4). ".
                      "Aborting install.",
                      $], $self-&gt;module, $self-&gt;installed_version,
                      $self-&gt;version ) );
        # if the installed matches, say so.
        } elsif( $self-&gt;installed_version == $self-&gt;version ) {
            error(loc("The core Perl %1 module '%2' (%3) can only ".
                      "be installed by Perl itself. ".
                      "Aborting install.",
                      $], $self-&gt;module, $self-&gt;installed_version ) );
        # otherwise, the installed is older; say so.
        } else {
            error(loc("The core Perl %1 module '%2' can only be ".
                      "upgraded from %3 to %4 by Perl itself (%5). ".
                      "Aborting install.",
                      $], $self-&gt;module, $self-&gt;installed_version,
                      $self-&gt;version, $self-&gt;package ) );
        }
        return;

    ### it might be a known 3rd party module
    } elsif ( $self-&gt;is_third_party ) {
        my $info = $self-&gt;third_party_information;
        error(loc(
            "%1 is a known third-party module.\n\n".
            "As it isn't available on the CPAN, CPANPLUS can't install " .
            "it automatically. Therefore you need to install it manually " .
            "before proceeding.\n\n".
            "%2 is part of %3, published by %4, and should be available ".
            "for download at the following address:\n\t%5",
            $self-&gt;name, $self-&gt;name, $info-&gt;{name}, $info-&gt;{author},
            $info-&gt;{url}
        ));

        return;
    }

    ### fetch it if need be ###
    unless( $self-&gt;status-&gt;fetch ) {
        my $params;
        for (qw[prefer_bin fetchdir]) {
            $params-&gt;{$_} = $args-&gt;{$_} if exists $args-&gt;{$_};
        }
        for (qw[force verbose]) {
            $params-&gt;{$_} = $args-&gt;{$_} if defined $args-&gt;{$_};
        }
        $self-&gt;fetch( %$params ) or return;
    }

    ### extract it if need be ###
    unless( $self-&gt;status-&gt;extract ) {
        my $params;
        for (qw[prefer_bin extractdir]) {
            $params-&gt;{$_} = $args-&gt;{$_} if exists $args-&gt;{$_};
        }
        for (qw[force verbose]) {
            $params-&gt;{$_} = $args-&gt;{$_} if defined $args-&gt;{$_};
        }
        $self-&gt;extract( %$params ) or return;
    }

    $args-&gt;{'prereq_format'} = $format if $format;
    $format ||= $self-&gt;status-&gt;installer_type;

    unless( $format ) {
        error( loc( "Don't know what installer to use; " .
                    "Couldn't find either '%1' or '%2' in the extraction " .
                    "directory '%3' -- will be unable to install",
                    BUILD_PL-&gt;(), MAKEFILE_PL-&gt;(), $self-&gt;status-&gt;extract ) );

        $self-&gt;status-&gt;installed(0);
        return;
    }


    ### do SIGNATURE checks? ###
    ### XXX check status and not recheck EVERY time?
    if( $conf-&gt;get_conf('signature') ) {
        unless( $self-&gt;check_signature( verbose =&gt; $args-&gt;{verbose} ) ) {
            error( loc( "Signature check failed for module '%1' ".
                        "-- Not trusting this module, aborting install",
                        $self-&gt;module ) );
            $self-&gt;status-&gt;signature(0);

            ### send out test report on broken sig
            if( $conf-&gt;get_conf('cpantest') ) {
                $cb-&gt;_send_report(
                    module  =&gt; $self,
                    failed  =&gt; 1,
                    buffer  =&gt; CPANPLUS::Error-&gt;stack_as_string,
                    verbose =&gt; $args-&gt;{verbose},
                    force   =&gt; $args-&gt;{force},
                ) or error(loc("Failed to send test report for '%1'",
                     $self-&gt;module ) );
            }

            return;

        } else {
            ### signature OK ###
            $self-&gt;status-&gt;signature(1);
        }
    }

    ### a target of 'create' basically means not to run make test ###
    ### eh, no it /doesn't/.. skiptest =&gt; 1 means skiptest =&gt; 1.
    #$args-&gt;{'skiptest'} = 1 if $target eq 'create';

    ### bundle rules apply ###
    if( $self-&gt;is_bundle ) {
        ### check what we need to install ###
        my @prereqs = $self-&gt;bundle_modules();
        unless( @prereqs ) {
            error( loc( "Bundle '%1' does not specify any modules to install",
                        $self-&gt;module ) );

            ### XXX mark an error here? ###
        }
    }

    my $dist = $self-&gt;dist( format  =&gt; $format,
                            target  =&gt; $target,
                            args    =&gt; $args );
    unless( $dist ) {
        error( loc( "Unable to create a new distribution object for '%1' " .
                    "-- cannot continue", $self-&gt;module ) );
        return;
    }

    return 1 if $target ne TARGET_INSTALL;

    my $ok = $dist-&gt;install( %$args ) ? 1 : 0;

    $self-&gt;status-&gt;installed($ok);

    return 1 if $ok;
    return;
}

=pod @list = $self-&gt;bundle_modules()

Returns a list of module objects the Bundle specifies.

This requires you to have extracted the bundle already, using the
C&lt;extract()&gt; method.

Returns false on error.

=cut

sub bundle_modules {
    my $self = shift;
    my $cb   = $self-&gt;parent;

    unless( $self-&gt;is_bundle ) {
        error( loc("'%1' is not a bundle", $self-&gt;module ) );
        return;
    }

    my @files;

    ### autobundles are special files generated by CPANPLUS. If we can
    ### read the file, we can determine the prereqs
    if( $self-&gt;is_autobundle ) {
        my $where;
        unless( $where = $self-&gt;status-&gt;fetch ) {
            error(loc("Don't know where '%1' was fetched to", $self-&gt;package));
            return;
        }

        push @files, $where

    ### regular bundle::* upload
    } else {
        my $dir;
        unless( $dir = $self-&gt;status-&gt;extract ) {
            error(loc("Don't know where '%1' was extracted to", $self-&gt;module));
            return;
        }

        find( {
            wanted   =&gt; sub { push @files, File::Spec-&gt;rel2abs($_) if /\.pm/i },
            no_chdir =&gt; 1,
        }, $dir );
    }

    my $prereqs = {}; my @list; my $seen = {};
    for my $file ( @files ) {
        my $fh = FileHandle-&gt;new($file)
                    or( error(loc("Could not open '%1' for reading: %2",
                        $file,$!)), next );

        my $flag;
        while( local $_ = &lt;$fh&gt; ) {
            ### quick hack to read past the header of the file ###
            last if $flag &amp;&amp; m|^=head|i;

            ### from perldoc cpan:
            ### =head1 CONTENTS
            ### In this pod section each line obeys the format
            ### Module_Name [Version_String] [- optional text]
            $flag = 1 if m|^=head1 CONTENTS|i;

            if ($flag &amp;&amp; /^(?!=)(\S+)\s*(\S+)?/) {
                my $module  = $1;
                my $version = $cb-&gt;_version_to_number( version =&gt; $2 );

                my $obj = $cb-&gt;module_tree($module);

                unless( $obj ) {
                    error(loc("Cannot find bundled module '%1'", $module),
                          loc("-- it does not seem to exist") );
                    next;
                }

                ### make sure we list no duplicates ###
                unless( $seen-&gt;{ $obj-&gt;module }++ ) {
                    push @list, $obj;
                    $prereqs-&gt;{ $module } =
                        $cb-&gt;_version_to_number( version =&gt; $version );
                }
            }
        }
    }

    ### store the prereqs we just found ###
    $self-&gt;status-&gt;prereqs( $prereqs );

    return @list;
}

=pod

=head2 $text = $self-&gt;readme

Fetches the readme belonging to this module and stores it under
C&lt;&lt; $obj-&gt;status-&gt;readme &gt;&gt;. Returns the readme as a string on
success and returns false on failure.

=cut

sub readme {
    my $self = shift;
    my $conf = $self-&gt;parent-&gt;configure_object;

    ### did we already dl the readme once? ###
    return $self-&gt;status-&gt;readme() if $self-&gt;status-&gt;readme();

    ### this should be core ###
    return unless can_load( modules     =&gt; { FileHandle =&gt; '0.0' },
                            verbose     =&gt; 1,
                        );

    ### get a clone of the current object, with a fresh status ###
    my $obj  = $self-&gt;clone or return;

    ### munge the package name
    my $pkg = README-&gt;( $obj );
    $obj-&gt;package($pkg);

    my $file;
    {   ### disable checksum fetches on readme downloads

        my $tmp = $conf-&gt;get_conf( 'md5' );
        $conf-&gt;set_conf( md5 =&gt; 0 );

        $file = $obj-&gt;fetch;

        $conf-&gt;set_conf( md5 =&gt; $tmp );

        return unless $file;
    }

    ### read the file into a scalar, to store in the original object ###
    my $fh = new FileHandle;
    unless( $fh-&gt;open($file) ) {
        error( loc( "Could not open file '%1': %2", $file, $! ) );
        return;
    }

    my $in = do{ local $/; &lt;$fh&gt; };
    $fh-&gt;close;

    return $self-&gt;status-&gt;readme( $in );
}

=pod

=head2 $version = $self-&gt;installed_version()

Returns the currently installed version of this module, if any.

=head2 $where = $self-&gt;installed_file()

Returns the location of the currently installed file of this module,
if any.

=head2 $dir = $self-&gt;installed_dir()

Returns the directory (or more accurately, the C&lt;@INC&gt; handle) from
which this module was loaded, if any.

=head2 $bool = $self-&gt;is_uptodate([version =&gt; VERSION_NUMBER])

Returns a boolean indicating if this module is uptodate or not.

=cut

### uptodate/installed functions
{   my $map = {             # hashkey,      alternate rv
        installed_version   =&gt; ['version',  0 ],
        installed_file      =&gt; ['file',     ''],
        installed_dir       =&gt; ['dir',      ''],
        is_uptodate         =&gt; ['uptodate', 0 ],
    };

    while( my($method, $aref) = each %$map ) {
        my($key,$alt_rv) = @$aref;

        no strict 'refs';
        *$method = sub {
            ### never use the @INC hooks to find installed versions of
            ### modules -- they're just there in case they're not on the
            ### perl install, but the user shouldn't trust them for *other*
            ### modules!
            ### XXX CPANPLUS::inc is now obsolete, so this should not
            ### be needed anymore
            #local @INC = CPANPLUS::inc-&gt;original_inc;

            my $self = shift;

            ### make sure check_install is not looking in %INC, as
            ### that may contain some of our sneakily loaded modules
            ### that aren't installed as such. -- kane
            local $Module::Load::Conditional::CHECK_INC_HASH = 0;
            ### this should all that is required for deprecated core modules
            local $Module::Load::Conditional::DEPRECATED = 1;
            my $href = check_install(
                            module  =&gt; $self-&gt;module,
                            version =&gt; $self-&gt;version,
                            @_,
                        );

            ### Don't trust modules which are the result of @INC hooks
            ### FatPacker uses this trickery and it causes WTF moments
            return $alt_rv if defined $href-&gt;{dir} &amp;&amp; ref $href-&gt;{dir};

            return $href-&gt;{$key} || $alt_rv;
        }
    }
}



=pod

=head2 $href = $self-&gt;details()

Returns a hashref with key/value pairs offering more information about
a particular module. For example, for C&lt;Time::HiRes&gt; it might look like
this:

    Author                  Jarkko Hietaniemi (jhi@iki.fi)
    Description             High resolution time, sleep, and alarm
    Development Stage       Released
    Installed File          /usr/local/perl/lib/Time/Hires.pm
    Interface Style         plain Functions, no references used
    Language Used           C and perl, a C compiler will be needed
    Package                 Time-HiRes-1.65.tar.gz
    Public License          Unknown
    Support Level           Developer
    Version Installed       1.52
    Version on CPAN         1.65

=cut

sub details {
    my $self = shift;
    my $conf = $self-&gt;parent-&gt;configure_object();
    my $cb   = $self-&gt;parent;
    my %hash = @_;

    my $res = {
        Author              =&gt; loc("%1 (%2)",   $self-&gt;author-&gt;author(),
                                                $self-&gt;author-&gt;email() ),
        Package             =&gt; $self-&gt;package,
        Description         =&gt; $self-&gt;description     || loc('None given'),
        'Version on CPAN'   =&gt; $self-&gt;version,
    };

    ### check if we have the module installed
    ### if so, add version have and version on cpan
    $res-&gt;{'Version Installed'} = $self-&gt;installed_version
                                    if $self-&gt;installed_version;
    $res-&gt;{'Installed File'} = $self-&gt;installed_file if $self-&gt;installed_file;

    my $i = 0;
    for my $item( split '', $self-&gt;dslip ) {
        $res-&gt;{ $cb-&gt;_dslip_defs-&gt;[$i]-&gt;[0] } =
                $cb-&gt;_dslip_defs-&gt;[$i]-&gt;[1]-&gt;{$item} || loc('Unknown');
        $i++;
    }

    return $res;
}

=head2 @list = $self-&gt;contains()

Returns a list of module objects that represent the modules also
present in the package of this module.

For example, for C&lt;Archive::Tar&gt; this might return:

    Archive::Tar
    Archive::Tar::Constant
    Archive::Tar::File

=cut

sub contains {
    my $self = shift;
    my $cb   = $self-&gt;parent;
    my $pkg  = $self-&gt;package;

    my @mods = $cb-&gt;search( type =&gt; 'package', allow =&gt; [qr/^$pkg$/] );

    return @mods;
}

=pod

=head2 @list_of_hrefs = $self-&gt;fetch_report()

This function queries the CPAN testers database at
I&lt;http://testers.cpan.org/&gt; for test results of specified module
objects, module names or distributions.

Look at L&lt;CPANPLUS::Internals::Report::_query_report()&gt; for details on
the options you can pass and the return value to expect.

=cut

sub fetch_report {
    my $self    = shift;
    my $cb      = $self-&gt;parent;

    return $cb-&gt;_query_report( @_, module =&gt; $self );
}

=pod

=head2 $bool = $self-&gt;uninstall([type =&gt; [all|man|prog])

This function uninstalls the specified module object.

You can install 2 types of files, either C&lt;man&gt; pages or C&lt;prog&gt;ram
files. Alternately you can specify C&lt;all&gt; to uninstall both (which
is the default).

Returns true on success and false on failure.

Do note that this does an uninstall via the so-called C&lt;.packlist&gt;,
so if you used a module installer like say, C&lt;ports&gt; or C&lt;apt&gt;, you
should not use this, but use your package manager instead.

=cut

sub uninstall {
    my $self = shift;
    my $conf = $self-&gt;parent-&gt;configure_object();
    my %hash = @_;

    my ($type,$verbose);
    my $tmpl = {
        type    =&gt; { default =&gt; 'all', allow =&gt; [qw|man prog all|],
                        store =&gt; \$type },
        verbose =&gt; { default =&gt; $conf-&gt;get_conf('verbose'),
                        store =&gt; \$verbose },
        force   =&gt; { default =&gt; $conf-&gt;get_conf('force') },
    };

    ### XXX add a warning here if your default install dist isn't
    ### makefile or build -- that means you are using a package manager
    ### and this will not do what you think!

    my $args = check( $tmpl, \%hash ) or return;

    if( $conf-&gt;get_conf('dist_type') and (
        ($conf-&gt;get_conf('dist_type') ne INSTALLER_BUILD) or
        ($conf-&gt;get_conf('dist_type') ne INSTALLER_MM))
    ) {
        msg(loc("You have a default installer type set (%1) ".
                "-- you should probably use that package manager to " .
                "uninstall modules", $conf-&gt;get_conf('dist_type')), $verbose);
    }

    ### check if we even have the module installed -- no point in continuing
    ### otherwise
    unless( $self-&gt;installed_version ) {
        error( loc( "Module '%1' is not installed, so cannot uninstall",
                    $self-&gt;module ) );
        return;
    }

                                                ### nothing to uninstall ###
    my $files   = $self-&gt;files( type =&gt; $type )             or return;
    my $dirs    = $self-&gt;directory_tree( type =&gt; $type )    or return;
    my $sudo    = $conf-&gt;get_program('sudo');

    ### just in case there's no file; M::B doesn't provide .packlists yet ###
    my $pack    = $self-&gt;packlist;
    $pack       = $pack-&gt;[0]-&gt;packlist_file() if $pack;

    ### first remove the files, then the dirs if they are empty ###
    my $flag = 0;
    for my $file( @$files, $pack ) {
        next unless defined $file &amp;&amp; -f $file;

        msg(loc("Unlinking '%1'", $file), $verbose);

        my @cmd = ($^X, "-eunlink+q[$file]");
        unshift @cmd, $sudo if $sudo;

        my $buffer;
        unless ( run(   command =&gt; \@cmd,
                        verbose =&gt; $verbose,
                        buffer  =&gt; \$buffer )
        ) {
            error(loc("Failed to unlink '%1': '%2'",$file, $buffer));
            $flag++;
        }
    }

    for my $dir ( sort @$dirs ) {
        local *DIR;
        opendir DIR, $dir or next;
        my @count = readdir(DIR);
        close DIR;

        next unless @count == 2;    # . and ..

        msg(loc("Removing '%1'", $dir), $verbose);

        ### this fails on my win2k machines.. it indeed leaves the
        ### dir, but it's not a critical error, since the files have
        ### been removed. --kane
        #unless( rmdir $dir ) {
        #    error( loc( "Could not remove '%1': %2", $dir, $! ) )
        #        unless $^O eq 'MSWin32';
        #}

        my @cmd = ($^X, "-e", "rmdir q[$dir]");
        unshift @cmd, $sudo if $sudo;

        my $buffer;
        unless ( run(   command =&gt; \@cmd,
                        verbose =&gt; $verbose,
                        buffer  =&gt; \$buffer )
        ) {
            error(loc("Failed to rmdir '%1': %2",$dir,$buffer));
            $flag++;
        }
    }

    $self-&gt;status-&gt;uninstall(!$flag);
    $self-&gt;status-&gt;installed( $flag ? 1 : undef);

    return !$flag;
}

=pod

=head2 @modobj = $self-&gt;distributions()

Returns a list of module objects representing all releases for this
module on success, false on failure.

=cut

sub distributions {
    my $self = shift;
    my %hash = @_;

    my @list = $self-&gt;author-&gt;distributions( %hash, module =&gt; $self ) or return;

    ### it's another release then by the same author ###
    return grep { $_-&gt;package_name eq $self-&gt;package_name } @list;
}

=pod

=head2 @list = $self-&gt;files ()

Returns a list of files used by this module, if it is installed.

=head2 @list = $self-&gt;directory_tree ()

Returns a list of directories used by this module.

=head2 @list = $self-&gt;packlist ()

Returns the C&lt;ExtUtils::Packlist&gt; object for this module.

=head2 @list = $self-&gt;validate ()

Returns a list of files that are missing for this modules, but
are present in the .packlist file.

=cut

for my $sub (qw[files directory_tree packlist validate]) {
    no strict 'refs';
    *$sub = sub {
        return shift-&gt;_extutils_installed( @_, method =&gt; $sub );
    }
}

### generic method to call an ExtUtils::Installed method ###
sub _extutils_installed {
    my $self = shift;
    my $cb   = $self-&gt;parent;
    my $conf = $cb-&gt;configure_object;
    my $home = $cb-&gt;_home_dir;          # may be needed to fix up prefixes
    my %hash = @_;

    my ($verbose,$type,$method);
    my $tmpl = {
        verbose =&gt; {    default     =&gt; $conf-&gt;get_conf('verbose'),
                        store       =&gt; \$verbose, },
        type    =&gt; {    default     =&gt; 'all',
                        allow       =&gt; [qw|prog man all|],
                        store       =&gt; \$type, },
        method  =&gt; {    required    =&gt; 1,
                        store       =&gt; \$method,
                        allow       =&gt; [qw|files directory_tree packlist
                                        validate|],
                    },
    };

    my $args = check( $tmpl, \%hash ) or return;

    ### old versions of cygwin + perl &lt; 5.8 are buggy here. bail out if we
    ### find we're being used by them
    {   my $err = ON_OLD_CYGWIN;
        if($err) { error($err); return };
    }

    return unless can_load(
                        modules     =&gt; { 'ExtUtils::Installed' =&gt; '0.0' },
                        verbose     =&gt; $verbose,
                    );

    my @config_names = (
        ### lib
        {   lib     =&gt; 'privlib',       # perl-only
            arch    =&gt; 'archlib',       # compiled code
            prefix  =&gt; 'prefix',        # prefix to both
        },
        ### site
        {   lib      =&gt; 'sitelib',
            arch     =&gt; 'sitearch',
            prefix   =&gt; 'siteprefix',
        },
        ### vendor
        {   lib     =&gt; 'vendorlib',
            arch    =&gt; 'vendorarch',
            prefix  =&gt; 'vendorprefix',
        },
    );

    ### search in your regular @INC, and anything you added to your config.
    ### this lets EU::Installed find .packlists that are *not* in the standard
    ### compiled in @INC path. Requires EU::I 1.42 or up. this addresses #33438
    ### make sure the archname path is also added, as that's where the .packlist
    ### files are written
    my @libs;
    for my $lib ( @{ $conf-&gt;get_conf('lib') } ) {
        require Config;

        ### and just the standard dir
        push @libs, $lib;

        ### figure out what an MM prefix expands to. Basically, it's the
        ### site install target from %Config, ie: /opt/lib/perl5/site_perl/5.8.8
        ### minus the site wide prefix, ie: /opt
        ### this lets users add the dir they have set as their EU::MM PREFIX
        ### to our 'lib' config and it Just Works
        ### the arch specific dir, ie:
        ### /opt/lib/perl5/site_perl/5.8.8/darwin-2level
        ### XXX is this the right thing to do?

        ### we add all 6 dir combos for prefixes:
        ### /foo/lib
        ### /foo/lib/arch
        ### /foo/site/lib
        ### /foo/site/lib/arch
        ### /foo/vendor/lib
        ### /foo/vendor/lib/arch
        for my $href ( @config_names ) {
            for my $key ( qw[lib arch] ) {

                ### look up the config value -- use EXP for the EXPANDED
                ### version, so no ~ etc are found in there
                my $dir     = $Config::Config{ $href-&gt;{ $key } .'exp' } or next;
                my $prefix  = $Config::Config{ $href-&gt;{prefix} };

                ### prefix may be relative to home, and contain a ~
                ### if so, fix it up.
                $prefix     =~ s/^~/$home/;

                ### remove the prefix from it, so we can append to our $lib
                $dir        =~ s/^\Q$prefix\E//;

                ### do the appending
                push @libs, File::Spec-&gt;catdir( $lib, $dir );

            }
        }
    }

    my $inst;
    unless( $inst = ExtUtils::Installed-&gt;new( extra_libs =&gt; \@libs ) ) {
        error( loc("Could not create an '%1' object", 'ExtUtils::Installed' ) );

        ### in case it's being used directly... ###
        return;
    }


    {   ### EU::Installed can die =/
        my @files;
        eval { @files = $inst-&gt;$method( $self-&gt;module, $type ) };

        if( $@ ) {
            chomp $@;
            error( loc("Could not get '%1' for '%2': %3",
                        $method, $self-&gt;module, $@ ) );
            return;
        }

        return wantarray ? @files : \@files;
    }
}

=head2 $bool = $self-&gt;add_to_includepath;

Adds the current modules path to C&lt;@INC&gt; and C&lt;$PERL5LIB&gt;. This allows
you to add the module from its build dir to your path.

It also adds the current modules C&lt;bin&gt; and/or C&lt;script&gt; paths to
the PATH.

You can reset C&lt;$PATH&gt;, C&lt;@INC&gt; and C&lt;$PERL5LIB&gt; to their original state when you
started the program, by calling:

    $self-&gt;parent-&gt;flush('lib');

=cut

sub add_to_includepath {
    my $self = shift;
    my $cb   = $self-&gt;parent;

    if( my $dir = $self-&gt;status-&gt;extract ) {

            $cb-&gt;_add_to_includepath(
                    directories =&gt; [
                        File::Spec-&gt;catdir(BLIB-&gt;($dir), LIB),
                        File::Spec-&gt;catdir(BLIB-&gt;($dir), ARCH),
                        BLIB-&gt;($dir),
                    ]
            ) or return;

            $cb-&gt;_add_to_path(
                    directories =&gt; [
                        File::Spec-&gt;catdir(BLIB-&gt;($dir), SCRIPT),
                        File::Spec-&gt;catdir(BLIB-&gt;($dir), BIN),
                    ]
            ) or return;

    } else {
        error(loc(  "No extract dir registered for '%1' -- can not add ".
                    "add builddir to search path!", $self-&gt;module ));
        return;
    }

    return 1;

}

=pod

=head2 $path = $self-&gt;best_path_to_module_build();

B&lt;OBSOLETE&gt;

If a newer version of Module::Build is found in your path, it will
return this C&lt;special&gt; path. If the newest version of C&lt;Module::Build&gt;
is found in your regular C&lt;@INC&gt;, the method will return false. This
indicates you do not need to add a special directory to your C&lt;@INC&gt;.

Note that this is only relevant if you're building your own
C&lt;CPANPLUS::Dist::*&gt; plugin -- the built-in dist types already have
this taken care of.

=cut

### make sure we're always running 'perl Build.PL' and friends
### against the highest version of module::build available
sub best_path_to_module_build {
    my $self = shift;

    ### Since M::B will actually shell out and run the Build.PL, we must
    ### make sure it refinds the proper version of M::B in the path.
    ### that may be either in our cp::inc or in site_perl, or even a
    ### new M::B being installed.
    ### don't add anything else here, as that might screw up prereq checks

    ### XXX this might be needed for Dist::MM too, if a makefile.pl is
    ###	masquerading as a Build.PL

    ### did we find the most recent module::build in our installer path?

    ### XXX can't do changes to @INC, they're being ignored by
    ### new_from_context when writing a Build script. see ticket:
    ### #8826 Module::Build ignores changes to @INC when writing Build
    ### from new_from_context
    ### XXX applied schwern's patches (as seen on CPANPLUS::Devel 10/12/04)
    ### and upped the version to 0.26061 of the bundled version, and things
    ### work again

    ### this functionality is now obsolete -- prereqs should be installed
    ### and we no longer use the CPANPLUS::inc magic.. so comment this out.
#     require Module::Build;
#     if( CPANPLUS::inc-&gt;path_to('Module::Build') and (
#         CPANPLUS::inc-&gt;path_to('Module::Build') eq
#         CPANPLUS::inc-&gt;installer_path )
#     ) {
#
#         ### if the module being installed is *not* Module::Build
#         ### itself -- as that would undoubtedly be newer -- add
#         ### the path to the installers to @INC
#         ### if it IS module::build itself, add 'lib' to its path,
#         ### as the Build.PL would do as well, but the API doesn't.
#         ### this makes self updates possible
#         return $self-&gt;module eq 'Module::Build'
#                         ? 'lib'
#                         : CPANPLUS::inc-&gt;installer_path;
#     }

    ### otherwise, the path was found through a 'normal' way of
    ### scanning @INC.
    return;
}

=pod

=head1 BUG REPORTS

Please report bugs or other issues to E&lt;lt&gt;bug-cpanplus@rt.cpan.org&lt;gt&gt;.

=head1 AUTHOR

This module by Jos Boumans E&lt;lt&gt;kane@cpan.orgE&lt;gt&gt;.

=head1 COPYRIGHT

The CPAN++ interface (of which this module is a part of) is copyright (c)
2001 - 2007, Jos Boumans E&lt;lt&gt;kane@cpan.orgE&lt;gt&gt;. All rights reserved.

This library is free software; you may redistribute and/or modify it
under the same terms as Perl itself.

=cut

# Local variables:
# c-indentation-style: bsd
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
# vim: expandtab shiftwidth=4:

1;

__END__

todo:
reports();
</pre></body></html>