<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
# vim:ts=8:sw=2:et:sta:sts=2
package Module::Build::Base;

use 5.006;
use strict;
use warnings;

our $VERSION = '0.4224';
$VERSION = eval $VERSION;

use Carp;
use Cwd ();
use File::Copy ();
use File::Find ();
use File::Path ();
use File::Basename ();
use File::Spec 0.82 ();
use File::Compare ();
use Module::Build::Dumper ();
use Text::ParseWords ();

use Module::Metadata;
use Module::Build::Notes;
use Module::Build::Config;
use version;


#################### Constructors ###########################
sub new {
  my $self = shift()-&gt;_construct(@_);

  $self-&gt;{invoked_action} = $self-&gt;{action} ||= 'Build_PL';
  $self-&gt;cull_args(@ARGV);

  die "Too early to specify a build action '$self-&gt;{action}'.  Do 'Build $self-&gt;{action}' instead.\n"
    if $self-&gt;{action} &amp;&amp; $self-&gt;{action} ne 'Build_PL';

  $self-&gt;check_manifest;
  $self-&gt;auto_require;

  # All checks must run regardless if one fails, so no short circuiting!
  if( grep { !$_ } $self-&gt;check_prereq, $self-&gt;check_autofeatures ) {
    $self-&gt;log_warn(&lt;&lt;EOF);

ERRORS/WARNINGS FOUND IN PREREQUISITES.  You may wish to install the versions
of the modules indicated above before proceeding with this installation

EOF
    unless (
      $self-&gt;dist_name eq 'Module-Build' ||
      $ENV{PERL5_CPANPLUS_IS_RUNNING} || $ENV{PERL5_CPAN_IS_RUNNING}
    ) {
      $self-&gt;log_warn(
        "Run 'Build installdeps' to install missing prerequisites.\n\n"
      );
    }
  }

  # record for later use in resume;
  $self-&gt;{properties}{_added_to_INC} = [ $self-&gt;_added_to_INC ];

  $self-&gt;set_bundle_inc;

  $self-&gt;dist_name;
  $self-&gt;dist_version;
  $self-&gt;release_status;
  $self-&gt;_guess_module_name unless $self-&gt;module_name;

  $self-&gt;_find_nested_builds;

  return $self;
}

sub resume {
  my $package = shift;
  my $self = $package-&gt;_construct(@_);
  $self-&gt;read_config;

  my @added_earlier = @{ $self-&gt;{properties}{_added_to_INC} || [] };

  @INC = ($self-&gt;_added_to_INC, @added_earlier, $self-&gt;_default_INC);

  # If someone called Module::Build-&gt;current() or
  # Module::Build-&gt;new_from_context() and the correct class to use is
  # actually a *subclass* of Module::Build, we may need to load that
  # subclass here and re-delegate the resume() method to it.
  unless ( $package-&gt;isa($self-&gt;build_class) ) {
    my $build_class = $self-&gt;build_class;
    my $config_dir = $self-&gt;config_dir || '_build';
    my $build_lib = File::Spec-&gt;catdir( $config_dir, 'lib' );
    unshift( @INC, $build_lib );
    unless ( $build_class-&gt;can('new') ) {
      eval "require $build_class; 1" or die "Failed to re-load '$build_class': $@";
    }
    return $build_class-&gt;resume(@_);
  }

  unless ($self-&gt;_perl_is_same($self-&gt;{properties}{perl})) {
    my $perl = $self-&gt;find_perl_interpreter;
    die(&lt;&lt;"DIEFATAL");
* FATAL ERROR: Perl interpreter mismatch. Configuration was initially
  created with '$self-&gt;{properties}{perl}'
  but we are now using '$perl'.  You must
  run 'Build realclean' or 'make realclean' and re-configure.
DIEFATAL
  }

  $self-&gt;cull_args(@ARGV);

  unless ($self-&gt;allow_mb_mismatch) {
    my $mb_version = $Module::Build::VERSION;
    if ( $mb_version ne $self-&gt;{properties}{mb_version} ) {
      $self-&gt;log_warn(&lt;&lt;"MISMATCH");
* WARNING: Configuration was initially created with Module::Build
  version '$self-&gt;{properties}{mb_version}' but we are now using version '$mb_version'.
  If errors occur, you must re-run the Build.PL or Makefile.PL script.
MISMATCH
    }
  }

  $self-&gt;{invoked_action} = $self-&gt;{action} ||= 'build';

  return $self;
}

sub new_from_context {
  my ($package, %args) = @_;

  $package-&gt;run_perl_script('Build.PL',[],[$package-&gt;unparse_args(\%args)]);
  return $package-&gt;resume;
}

sub current {
  # hmm, wonder what the right thing to do here is
  local @ARGV;
  return shift()-&gt;resume;
}

sub _construct {
  my ($package, %input) = @_;

  my $args   = delete $input{args}   || {};
  my $config = delete $input{config} || {};

  my $self = bless {
      args =&gt; {%$args},
      config =&gt; Module::Build::Config-&gt;new(values =&gt; $config),
      properties =&gt; {
          base_dir        =&gt; $package-&gt;cwd,
          mb_version      =&gt; $Module::Build::VERSION,
          %input,
      },
      phash =&gt; {},
      stash =&gt; {}, # temporary caching, not stored in _build
  }, $package;

  $self-&gt;_set_defaults;
  my ($p, $ph) = ($self-&gt;{properties}, $self-&gt;{phash});

  foreach (qw(notes config_data features runtime_params cleanup auto_features)) {
    my $file = File::Spec-&gt;catfile($self-&gt;config_dir, $_);
    $ph-&gt;{$_} = Module::Build::Notes-&gt;new(file =&gt; $file);
    $ph-&gt;{$_}-&gt;restore if -e $file;
    if (exists $p-&gt;{$_}) {
      my $vals = delete $p-&gt;{$_};
      foreach my $k (sort keys %$vals) {
        $self-&gt;$_($k, $vals-&gt;{$k});
      }
    }
  }

  # The following warning could be unnecessary if the user is running
  # an embedded perl, but there aren't too many of those around, and
  # embedded perls aren't usually used to install modules, and the
  # installation process sometimes needs to run external scripts
  # (e.g. to run tests).
  $p-&gt;{perl} = $self-&gt;find_perl_interpreter
    or $self-&gt;log_warn("Warning: Can't locate your perl binary");

  my $blibdir = sub { File::Spec-&gt;catdir($p-&gt;{blib}, @_) };
  $p-&gt;{bindoc_dirs} ||= [ $blibdir-&gt;("script") ];
  $p-&gt;{libdoc_dirs} ||= [ $blibdir-&gt;("lib"), $blibdir-&gt;("arch") ];

  $p-&gt;{dist_author} = [ $p-&gt;{dist_author} ] if defined $p-&gt;{dist_author} and not ref $p-&gt;{dist_author};

  # Synonyms
  $p-&gt;{requires} = delete $p-&gt;{prereq} if defined $p-&gt;{prereq};
  $p-&gt;{script_files} = delete $p-&gt;{scripts} if defined $p-&gt;{scripts};

  # Convert to from shell strings to arrays
  for ('extra_compiler_flags', 'extra_linker_flags') {
    $p-&gt;{$_} = [ $self-&gt;split_like_shell($p-&gt;{$_}) ] if exists $p-&gt;{$_};
  }

  # Convert to arrays
  for ('include_dirs') {
    $p-&gt;{$_} = [ $p-&gt;{$_} ] if exists $p-&gt;{$_} &amp;&amp; !ref $p-&gt;{$_}
  }

  $self-&gt;add_to_cleanup( @{delete $p-&gt;{add_to_cleanup}} )
    if $p-&gt;{add_to_cleanup};

  return $self;
}

################## End constructors #########################

sub log_info {
  my $self = shift;
  print @_ if ref($self) &amp;&amp; ( $self-&gt;verbose || ! $self-&gt;quiet );
}
sub log_verbose {
  my $self = shift;
  print @_ if ref($self) &amp;&amp; $self-&gt;verbose;
}
sub log_debug {
  my $self = shift;
  print @_ if ref($self) &amp;&amp; $self-&gt;debug;
}

sub log_warn {
  # Try to make our call stack invisible
  shift;
  if (@_ and $_[-1] !~ /\n$/) {
    my (undef, $file, $line) = caller();
    warn @_, " at $file line $line.\n";
  } else {
    warn @_;
  }
}


# install paths must be generated when requested to be sure all changes
# to config (from various sources) are included
sub _default_install_paths {
  my $self = shift;
  my $c = $self-&gt;{config};
  my $p = {};

  my @libstyle = $c-&gt;get('installstyle') ?
      File::Spec-&gt;splitdir($c-&gt;get('installstyle')) : qw(lib perl5);
  my $arch     = $c-&gt;get('archname');
  my $version  = $c-&gt;get('version');

  my $bindoc  = $c-&gt;get('installman1dir') || undef;
  my $libdoc  = $c-&gt;get('installman3dir') || undef;

  my $binhtml = $c-&gt;get('installhtml1dir') || $c-&gt;get('installhtmldir') || undef;
  my $libhtml = $c-&gt;get('installhtml3dir') || $c-&gt;get('installhtmldir') || undef;

  $p-&gt;{install_sets} =
    {
     core   =&gt; {
       lib     =&gt; $c-&gt;get('installprivlib'),
       arch    =&gt; $c-&gt;get('installarchlib'),
       bin     =&gt; $c-&gt;get('installbin'),
       script  =&gt; $c-&gt;get('installscript'),
       bindoc  =&gt; $bindoc,
       libdoc  =&gt; $libdoc,
       binhtml =&gt; $binhtml,
       libhtml =&gt; $libhtml,
     },
     site   =&gt; {
       lib     =&gt; $c-&gt;get('installsitelib'),
       arch    =&gt; $c-&gt;get('installsitearch'),
       bin     =&gt; $c-&gt;get('installsitebin')      || $c-&gt;get('installbin'),
       script  =&gt; $c-&gt;get('installsitescript')   ||
         $c-&gt;get('installsitebin') || $c-&gt;get('installscript'),
       bindoc  =&gt; $c-&gt;get('installsiteman1dir')  || $bindoc,
       libdoc  =&gt; $c-&gt;get('installsiteman3dir')  || $libdoc,
       binhtml =&gt; $c-&gt;get('installsitehtml1dir') || $binhtml,
       libhtml =&gt; $c-&gt;get('installsitehtml3dir') || $libhtml,
     },
     vendor =&gt; {
       lib     =&gt; $c-&gt;get('installvendorlib'),
       arch    =&gt; $c-&gt;get('installvendorarch'),
       bin     =&gt; $c-&gt;get('installvendorbin')      || $c-&gt;get('installbin'),
       script  =&gt; $c-&gt;get('installvendorscript')   ||
         $c-&gt;get('installvendorbin') || $c-&gt;get('installscript'),
       bindoc  =&gt; $c-&gt;get('installvendorman1dir')  || $bindoc,
       libdoc  =&gt; $c-&gt;get('installvendorman3dir')  || $libdoc,
       binhtml =&gt; $c-&gt;get('installvendorhtml1dir') || $binhtml,
       libhtml =&gt; $c-&gt;get('installvendorhtml3dir') || $libhtml,
     },
    };

  $p-&gt;{original_prefix} =
    {
     core   =&gt; $c-&gt;get('installprefixexp') || $c-&gt;get('installprefix') ||
               $c-&gt;get('prefixexp')        || $c-&gt;get('prefix') || '',
     site   =&gt; $c-&gt;get('siteprefixexp'),
     vendor =&gt; $c-&gt;get('usevendorprefix') ? $c-&gt;get('vendorprefixexp') : '',
    };
  $p-&gt;{original_prefix}{site} ||= $p-&gt;{original_prefix}{core};

  # Note: you might be tempted to use $Config{installstyle} here
  # instead of hard-coding lib/perl5, but that's been considered and
  # (at least for now) rejected.  `perldoc Config` has some wisdom
  # about it.
  $p-&gt;{install_base_relpaths} =
    {
     lib     =&gt; ['lib', 'perl5'],
     arch    =&gt; ['lib', 'perl5', $arch],
     bin     =&gt; ['bin'],
     script  =&gt; ['bin'],
     bindoc  =&gt; ['man', 'man1'],
     libdoc  =&gt; ['man', 'man3'],
     binhtml =&gt; ['html'],
     libhtml =&gt; ['html'],
    };

  $p-&gt;{prefix_relpaths} =
    {
     core =&gt; {
       lib        =&gt; [@libstyle],
       arch       =&gt; [@libstyle, $version, $arch],
       bin        =&gt; ['bin'],
       script     =&gt; ['bin'],
       bindoc     =&gt; ['man', 'man1'],
       libdoc     =&gt; ['man', 'man3'],
       binhtml    =&gt; ['html'],
       libhtml    =&gt; ['html'],
     },
     vendor =&gt; {
       lib        =&gt; [@libstyle],
       arch       =&gt; [@libstyle, $version, $arch],
       bin        =&gt; ['bin'],
       script     =&gt; ['bin'],
       bindoc     =&gt; ['man', 'man1'],
       libdoc     =&gt; ['man', 'man3'],
       binhtml    =&gt; ['html'],
       libhtml    =&gt; ['html'],
     },
     site =&gt; {
       lib        =&gt; [@libstyle, 'site_perl'],
       arch       =&gt; [@libstyle, 'site_perl', $version, $arch],
       bin        =&gt; ['bin'],
       script     =&gt; ['bin'],
       bindoc     =&gt; ['man', 'man1'],
       libdoc     =&gt; ['man', 'man3'],
       binhtml    =&gt; ['html'],
       libhtml    =&gt; ['html'],
     },
    };
    return $p
}

sub _find_nested_builds {
  my $self = shift;
  my $r = $self-&gt;recurse_into or return;

  my ($file, @r);
  if (!ref($r) &amp;&amp; $r eq 'auto') {
    local *DH;
    opendir DH, $self-&gt;base_dir
      or die "Can't scan directory " . $self-&gt;base_dir . " for nested builds: $!";
    while (defined($file = readdir DH)) {
      my $subdir = File::Spec-&gt;catdir( $self-&gt;base_dir, $file );
      next unless -d $subdir;
      push @r, $subdir if -e File::Spec-&gt;catfile( $subdir, 'Build.PL' );
    }
  }

  $self-&gt;recurse_into(\@r);
}

sub cwd {
  return Cwd::cwd();
}

sub _quote_args {
  # Returns a string that can become [part of] a command line with
  # proper quoting so that the subprocess sees this same list of args.
  my ($self, @args) = @_;

  my @quoted;

  for (@args) {
    if ( /^[^\s*?!\$&lt;&gt;;\\|'"\[\]\{\}]+$/ ) {
      # Looks pretty safe
      push @quoted, $_;
    } else {
      # XXX this will obviously have to improve - is there already a
      # core module lying around that does proper quoting?
      s/('+)/'"$1"'/g;
      push @quoted, qq('$_');
    }
  }

  return join " ", @quoted;
}

sub _backticks {
  my ($self, @cmd) = @_;
  if ($self-&gt;have_forkpipe) {
    local *FH;
    my $pid = open *FH, "-|";
    if ($pid) {
      return wantarray ? &lt;FH&gt; : join '', &lt;FH&gt;;
    } else {
      die "Can't execute @cmd: $!\n" unless defined $pid;
      exec { $cmd[0] } @cmd;
    }
  } else {
    my $cmd = $self-&gt;_quote_args(@cmd);
    return `$cmd`;
  }
}

# Tells us whether the construct open($fh, '-|', @command) is
# supported.  It would probably be better to dynamically sense this.
sub have_forkpipe { 1 }

# Determine whether a given binary is the same as the perl
# (configuration) that started this process.
sub _perl_is_same {
  my ($self, $perl) = @_;

  my @cmd = ($perl);

  # When run from the perl core, @INC will include the directories
  # where perl is yet to be installed. We need to reference the
  # absolute path within the source distribution where it can find
  # it's Config.pm This also prevents us from picking up a Config.pm
  # from a different configuration that happens to be already
  # installed in @INC.
  if ($ENV{PERL_CORE}) {
    push @cmd, '-I' . File::Spec-&gt;catdir(File::Basename::dirname($perl), 'lib');
  }

  push @cmd, qw(-MConfig=myconfig -e print -e myconfig);
  return $self-&gt;_backticks(@cmd) eq Config-&gt;myconfig;
}

# cache _discover_perl_interpreter() results
{
  my $known_perl;
  sub find_perl_interpreter {
    my $self = shift;

    return $known_perl if defined($known_perl);
    return $known_perl = $self-&gt;_discover_perl_interpreter;
  }
}

# Returns the absolute path of the perl interpreter used to invoke
# this process. The path is derived from $^X or $Config{perlpath}. On
# some platforms $^X contains the complete absolute path of the
# interpreter, on other it may contain a relative path, or simply
# 'perl'. This can also vary depending on whether a path was supplied
# when perl was invoked. Additionally, the value in $^X may omit the
# executable extension on platforms that use one. It's a fatal error
# if the interpreter can't be found because it can result in undefined
# behavior by routines that depend on it (generating errors or
# invoking the wrong perl.)
sub _discover_perl_interpreter {
  my $proto = shift;
  my $c     = ref($proto) ? $proto-&gt;{config} : 'Module::Build::Config';

  my $perl  = $^X;
  my $perl_basename = File::Basename::basename($perl);

  my @potential_perls;

  # Try 1, Check $^X for absolute path
  push( @potential_perls, $perl )
      if File::Spec-&gt;file_name_is_absolute($perl);

  # Try 2, Check $^X for a valid relative path
  my $abs_perl = File::Spec-&gt;rel2abs($perl);
  push( @potential_perls, $abs_perl );

  # Try 3, Last ditch effort: These two option use hackery to try to locate
  # a suitable perl. The hack varies depending on whether we are running
  # from an installed perl or an uninstalled perl in the perl source dist.
  if ($ENV{PERL_CORE}) {

    # Try 3.A, If we are in a perl source tree, running an uninstalled
    # perl, we can keep moving up the directory tree until we find our
    # binary. We wouldn't do this under any other circumstances.

    # CBuilder is also in the core, so it should be available here
    require ExtUtils::CBuilder;
    my $perl_src = Cwd::realpath( ExtUtils::CBuilder-&gt;perl_src );
    if ( defined($perl_src) &amp;&amp; length($perl_src) ) {
      my $uninstperl =
        File::Spec-&gt;rel2abs(File::Spec-&gt;catfile( $perl_src, $perl_basename ));
      push( @potential_perls, $uninstperl );
    }

  } else {

    # Try 3.B, First look in $Config{perlpath}, then search the user's
    # PATH. We do not want to do either if we are running from an
    # uninstalled perl in a perl source tree.

    push( @potential_perls, $c-&gt;get('perlpath') );

    push( @potential_perls,
          map File::Spec-&gt;catfile($_, $perl_basename), File::Spec-&gt;path() );
  }

  # Now that we've enumerated the potential perls, it's time to test
  # them to see if any of them match our configuration, returning the
  # absolute path of the first successful match.
  my $exe = $c-&gt;get('exe_ext');
  foreach my $thisperl ( @potential_perls ) {

    if (defined $exe) {
      $thisperl .= $exe unless $thisperl =~ m/$exe$/i;
    }

    if ( -f $thisperl &amp;&amp; $proto-&gt;_perl_is_same($thisperl) ) {
      return $thisperl;
    }
  }

  # We've tried all alternatives, and didn't find a perl that matches
  # our configuration. Throw an exception, and list alternatives we tried.
  my @paths = map File::Basename::dirname($_), @potential_perls;
  die "Can't locate the perl binary used to run this script " .
      "in (@paths)\n";
}

# Adapted from IPC::Cmd::can_run()
sub find_command {
  my ($self, $command) = @_;

  if( File::Spec-&gt;file_name_is_absolute($command) ) {
    return $self-&gt;_maybe_command($command);

  } else {
    for my $dir ( File::Spec-&gt;path ) {
      my $abs = File::Spec-&gt;catfile($dir, $command);
      return $abs if $abs = $self-&gt;_maybe_command($abs);
    }
  }
}

# Copied from ExtUtils::MM_Unix::maybe_command
sub _maybe_command {
  my($self,$file) = @_;
  return $file if -x $file &amp;&amp; ! -d $file;
  return;
}

sub _is_interactive {
  return -t STDIN &amp;&amp; (-t STDOUT || !(-f STDOUT || -c STDOUT)) ;   # Pipe?
}

# NOTE this is a blocking operation if(-t STDIN)
sub _is_unattended {
  my $self = shift;
  return $ENV{PERL_MM_USE_DEFAULT} ||
    ( !$self-&gt;_is_interactive &amp;&amp; eof STDIN );
}

sub _readline {
  my $self = shift;
  return undef if $self-&gt;_is_unattended;

  my $answer = &lt;STDIN&gt;;
  chomp $answer if defined $answer;
  return $answer;
}

sub prompt {
  my $self = shift;
  my $mess = shift
    or die "prompt() called without a prompt message";

  # use a list to distinguish a default of undef() from no default
  my @def;
  @def = (shift) if @_;
  # use dispdef for output
  my @dispdef = scalar(@def) ?
    ('[', (defined($def[0]) ? $def[0] . ' ' : ''), ']') :
    (' ', '');

  local $|=1;
  print "$mess ", @dispdef;

  if ( $self-&gt;_is_unattended &amp;&amp; !@def ) {
    die &lt;&lt;EOF;
ERROR: This build seems to be unattended, but there is no default value
for this question.  Aborting.
EOF
  }

  my $ans = $self-&gt;_readline();

  if ( !defined($ans)        # Ctrl-D or unattended
       or !length($ans) ) {  # User hit return
    print "$dispdef[1]\n";
    $ans = scalar(@def) ? $def[0] : '';
  }

  return $ans;
}

sub y_n {
  my $self = shift;
  my ($mess, $def)  = @_;

  die "y_n() called without a prompt message" unless $mess;
  die "Invalid default value: y_n() default must be 'y' or 'n'"
    if $def &amp;&amp; $def !~ /^[yn]/i;

  my $answer;
  while (1) { # XXX Infinite or a large number followed by an exception ?
    $answer = $self-&gt;prompt(@_);
    return 1 if $answer =~ /^y/i;
    return 0 if $answer =~ /^n/i;
    local $|=1;
    print "Please answer 'y' or 'n'.\n";
  }
}

sub current_action { shift-&gt;{action} }
sub invoked_action { shift-&gt;{invoked_action} }

sub notes        { shift()-&gt;{phash}{notes}-&gt;access(@_) }
sub config_data  { shift()-&gt;{phash}{config_data}-&gt;access(@_) }
sub runtime_params { shift-&gt;{phash}{runtime_params}-&gt;read( @_ ? shift : () ) }  # Read-only
sub auto_features  { shift()-&gt;{phash}{auto_features}-&gt;access(@_) }

sub features     {
  my $self = shift;
  my $ph = $self-&gt;{phash};

  if (@_) {
    my $key = shift;
    if ($ph-&gt;{features}-&gt;exists($key)) {
      return $ph-&gt;{features}-&gt;access($key, @_);
    }

    if (my $info = $ph-&gt;{auto_features}-&gt;access($key)) {
      my $disabled;
      for my $type ( @{$self-&gt;prereq_action_types} ) {
        next if $type eq 'description' || $type eq 'recommends' || ! exists $info-&gt;{$type};
        my $prereqs = $info-&gt;{$type};
        for my $modname ( sort keys %$prereqs ) {
          my $spec = $prereqs-&gt;{$modname};
          my $status = $self-&gt;check_installed_status($modname, $spec);
          if ((!$status-&gt;{ok}) xor ($type =~ /conflicts$/)) { return 0; }
          if ( ! eval "require $modname; 1" ) { return 0; }
        }
      }
      return 1;
    }

    return $ph-&gt;{features}-&gt;access($key, @_);
  }

  # No args - get the auto_features &amp; overlay the regular features
  my %features;
  my %auto_features = $ph-&gt;{auto_features}-&gt;access();
  while (my ($name, $info) = each %auto_features) {
    my $failures = $self-&gt;prereq_failures($info);
    my $disabled = grep( /^(?:\w+_)?(?:requires|conflicts)$/,
                        keys %$failures ) ? 1 : 0;
    $features{$name} = $disabled ? 0 : 1;
  }
  %features = (%features, $ph-&gt;{features}-&gt;access());

  return wantarray ? %features : \%features;
}
BEGIN { *feature = \&amp;features } # Alias

sub _mb_feature {
  my $self = shift;

  if (($self-&gt;module_name || '') eq 'Module::Build') {
    # We're building Module::Build itself, so ...::ConfigData isn't
    # valid, but $self-&gt;features() should be.
    return $self-&gt;feature(@_);
  } else {
    require Module::Build::ConfigData;
    return Module::Build::ConfigData-&gt;feature(@_);
  }
}

sub _warn_mb_feature_deps {
  my $self = shift;
  my $name = shift;
  $self-&gt;log_warn(
    "The '$name' feature is not available.  Please install missing\n" .
    "feature dependencies and try again.\n".
    $self-&gt;_feature_deps_msg($name) . "\n"
  );
}

sub add_build_element {
    my ($self, $elem) = @_;
    my $elems = $self-&gt;build_elements;
    push @$elems, $elem unless grep { $_ eq $elem } @$elems;
}

sub ACTION_config_data {
  my $self = shift;
  return unless $self-&gt;has_config_data;

  my $module_name = $self-&gt;module_name
    or die "The config_data feature requires that 'module_name' be set";
  my $notes_name = $module_name . '::ConfigData'; # TODO: Customize name ???
  my $notes_pm = File::Spec-&gt;catfile($self-&gt;blib, 'lib', split /::/, "$notes_name.pm");

  return if $self-&gt;up_to_date(['Build.PL',
                               $self-&gt;config_file('config_data'),
                               $self-&gt;config_file('features')
                              ], $notes_pm);

  $self-&gt;log_verbose("Writing config notes to $notes_pm\n");
  File::Path::mkpath(File::Basename::dirname($notes_pm));

  Module::Build::Notes-&gt;write_config_data
    (
     file =&gt; $notes_pm,
     module =&gt; $module_name,
     config_module =&gt; $notes_name,
     config_data =&gt; scalar $self-&gt;config_data,
     feature =&gt; scalar $self-&gt;{phash}{features}-&gt;access(),
     auto_features =&gt; scalar $self-&gt;auto_features,
    );
}

########################################################################
{ # enclosing these lexicals -- TODO
  my %valid_properties = ( __PACKAGE__,  {} );
  my %additive_properties;

  sub _mb_classes {
    my $class = ref($_[0]) || $_[0];
    return ($class, $class-&gt;mb_parents);
  }

  sub valid_property {
    my ($class, $prop) = @_;
    return grep exists( $valid_properties{$_}{$prop} ), $class-&gt;_mb_classes;
  }

  sub valid_properties {
    return keys %{ shift-&gt;valid_properties_defaults() };
  }

  sub valid_properties_defaults {
    my %out;
    for my $class (reverse shift-&gt;_mb_classes) {
      @out{ keys %{ $valid_properties{$class} } } = map {
        $_-&gt;()
      } values %{ $valid_properties{$class} };
    }
    return \%out;
  }

  sub array_properties {
    map { exists $additive_properties{$_}-&gt;{ARRAY} ? @{$additive_properties{$_}-&gt;{ARRAY}} : () } shift-&gt;_mb_classes;
  }

  sub hash_properties {
    map { exists $additive_properties{$_}-&gt;{HASH} ? @{$additive_properties{$_}-&gt;{HASH}} : () } shift-&gt;_mb_classes;
  }

  sub add_property {
    my ($class, $property) = (shift, shift);
    die "Property '$property' already exists"
      if $class-&gt;valid_property($property);
    my %p = @_ == 1 ? ( default =&gt; shift ) : @_;

    my $type = ref $p{default};
    $valid_properties{$class}{$property} =
      $type eq 'CODE' ? $p{default}                           :
      $type eq 'HASH' ? sub { return { %{ $p{default} } }   } :
      $type eq 'ARRAY'? sub { return [ @{ $p{default} } ]   } :
                        sub { return $p{default}            } ;

    push @{$additive_properties{$class}-&gt;{$type}}, $property
      if $type;

    unless ($class-&gt;can($property)) {
      # TODO probably should put these in a util package
      my $sub = $type eq 'HASH'
        ? _make_hash_accessor($property, \%p)
        : _make_accessor($property, \%p);
      no strict 'refs';
      *{"$class\::$property"} = $sub;
    }

    return $class;
  }

  sub property_error {
    my $self = shift;
    die 'ERROR: ', @_;
  }

  sub _set_defaults {
    my $self = shift;

    # Set the build class.
    $self-&gt;{properties}{build_class} ||= ref $self;

    # If there was no orig_dir, set to the same as base_dir
    $self-&gt;{properties}{orig_dir} ||= $self-&gt;{properties}{base_dir};

    my $defaults = $self-&gt;valid_properties_defaults;

    foreach my $prop (keys %$defaults) {
      $self-&gt;{properties}{$prop} = $defaults-&gt;{$prop}
        unless exists $self-&gt;{properties}{$prop};
    }

    # Copy defaults for arrays any arrays.
    for my $prop ($self-&gt;array_properties) {
      $self-&gt;{properties}{$prop} = [@{$defaults-&gt;{$prop}}]
        unless exists $self-&gt;{properties}{$prop};
    }
    # Copy defaults for arrays any hashes.
    for my $prop ($self-&gt;hash_properties) {
      $self-&gt;{properties}{$prop} = {%{$defaults-&gt;{$prop}}}
        unless exists $self-&gt;{properties}{$prop};
    }
  }

} # end enclosure
########################################################################
sub _make_hash_accessor {
  my ($property, $p) = @_;
  my $check = $p-&gt;{check} || sub { 1 };

  return sub {
    my $self = shift;

    # This is only here to deprecate the historic accident of calling
    # properties as class methods - I suspect it only happens in our
    # test suite.
    unless(ref($self)) {
      carp("\n$property not a class method (@_)");
      return;
    }

    my $x = $self-&gt;{properties};
    return $x-&gt;{$property} unless @_;

    my $prop = $x-&gt;{$property};
    if ( defined $_[0] &amp;&amp; !ref $_[0] ) {
      if ( @_ == 1 ) {
        return exists $prop-&gt;{$_[0]} ? $prop-&gt;{$_[0]} : undef;
      } elsif ( @_ % 2 == 0 ) {
        my %new = (%{ $prop }, @_);
        local $_ = \%new;
        $x-&gt;{$property} = \%new if $check-&gt;($self);
        return $x-&gt;{$property};
      } else {
        die "Unexpected arguments for property '$property'\n";
      }
    } else {
      die "Unexpected arguments for property '$property'\n"
          if defined $_[0] &amp;&amp; ref $_[0] ne 'HASH';
      local $_ = $_[0];
      $x-&gt;{$property} = shift if $check-&gt;($self);
    }
  };
}
########################################################################
sub _make_accessor {
  my ($property, $p) = @_;
  my $check = $p-&gt;{check} || sub { 1 };

  return sub {
    my $self = shift;

    # This is only here to deprecate the historic accident of calling
    # properties as class methods - I suspect it only happens in our
    # test suite.
    unless(ref($self)) {
      carp("\n$property not a class method (@_)");
      return;
    }

    my $x = $self-&gt;{properties};
    return $x-&gt;{$property} unless @_;
    local $_ = $_[0];
    $x-&gt;{$property} = shift if $check-&gt;($self);
    return $x-&gt;{$property};
  };
}
########################################################################

# Add the default properties.
__PACKAGE__-&gt;add_property(auto_configure_requires =&gt; 1);
__PACKAGE__-&gt;add_property(blib =&gt; 'blib');
__PACKAGE__-&gt;add_property(build_class =&gt; 'Module::Build');
__PACKAGE__-&gt;add_property(build_elements =&gt; [qw(PL support pm xs share_dir pod script)]);
__PACKAGE__-&gt;add_property(build_script =&gt; 'Build');
__PACKAGE__-&gt;add_property(build_bat =&gt; 0);
__PACKAGE__-&gt;add_property(bundle_inc =&gt; []);
__PACKAGE__-&gt;add_property(bundle_inc_preload =&gt; []);
__PACKAGE__-&gt;add_property(config_dir =&gt; '_build');
__PACKAGE__-&gt;add_property(dynamic_config =&gt; 1);
__PACKAGE__-&gt;add_property(include_dirs =&gt; []);
__PACKAGE__-&gt;add_property(license =&gt; 'unknown');
__PACKAGE__-&gt;add_property(metafile =&gt; 'META.yml');
__PACKAGE__-&gt;add_property(mymetafile =&gt; 'MYMETA.yml');
__PACKAGE__-&gt;add_property(metafile2 =&gt; 'META.json');
__PACKAGE__-&gt;add_property(mymetafile2 =&gt; 'MYMETA.json');
__PACKAGE__-&gt;add_property(recurse_into =&gt; []);
__PACKAGE__-&gt;add_property(use_rcfile =&gt; 1);
__PACKAGE__-&gt;add_property(create_packlist =&gt; 1);
__PACKAGE__-&gt;add_property(allow_mb_mismatch =&gt; 0);
__PACKAGE__-&gt;add_property(config =&gt; undef);
__PACKAGE__-&gt;add_property(test_file_exts =&gt; ['.t']);
__PACKAGE__-&gt;add_property(use_tap_harness =&gt; 0);
__PACKAGE__-&gt;add_property(cpan_client =&gt; 'cpan');
__PACKAGE__-&gt;add_property(tap_harness_args =&gt; {});
__PACKAGE__-&gt;add_property(pureperl_only =&gt; 0);
__PACKAGE__-&gt;add_property(allow_pureperl =&gt; 0);
__PACKAGE__-&gt;add_property(
  'installdirs',
  default =&gt; 'site',
  check   =&gt; sub {
    return 1 if /^(core|site|vendor)$/;
    return shift-&gt;property_error(
      $_ eq 'perl'
      ? 'Perhaps you meant installdirs to be "core" rather than "perl"?'
      : 'installdirs must be one of "core", "site", or "vendor"'
    );
    return shift-&gt;property_error("Perhaps you meant 'core'?") if $_ eq 'perl';
    return 0;
  },
);

{
  __PACKAGE__-&gt;add_property(html_css =&gt; '');
}

{
  my @prereq_action_types = qw(requires build_requires test_requires conflicts recommends);
  foreach my $type (@prereq_action_types) {
    __PACKAGE__-&gt;add_property($type =&gt; {});
  }
  __PACKAGE__-&gt;add_property(prereq_action_types =&gt; \@prereq_action_types);
}

__PACKAGE__-&gt;add_property($_ =&gt; {}) for qw(
  get_options
  install_base_relpaths
  install_path
  install_sets
  meta_add
  meta_merge
  original_prefix
  prefix_relpaths
  configure_requires
);

__PACKAGE__-&gt;add_property($_) for qw(
  PL_files
  autosplit
  base_dir
  bindoc_dirs
  c_source
  cover
  create_license
  create_makefile_pl
  create_readme
  debugger
  destdir
  dist_abstract
  dist_author
  dist_name
  dist_suffix
  dist_version
  dist_version_from
  extra_compiler_flags
  extra_linker_flags
  has_config_data
  install_base
  libdoc_dirs
  magic_number
  mb_version
  module_name
  needs_compiler
  orig_dir
  perl
  pm_files
  pod_files
  pollute
  prefix
  program_name
  quiet
  recursive_test_files
  release_status
  script_files
  scripts
  share_dir
  sign
  test_files
  verbose
  debug
  xs_files
  extra_manify_args
);

sub config {
  my $self = shift;
  my $c = ref($self) ? $self-&gt;{config} : 'Module::Build::Config';
  return $c-&gt;all_config unless @_;

  my $key = shift;
  return $c-&gt;get($key) unless @_;

  my $val = shift;
  return $c-&gt;set($key =&gt; $val);
}

sub mb_parents {
    # Code borrowed from Class::ISA.
    my @in_stack = (shift);
    my %seen = ($in_stack[0] =&gt; 1);

    my ($current, @out);
    while (@in_stack) {
        next unless defined($current = shift @in_stack)
          &amp;&amp; $current-&gt;isa('Module::Build::Base');
        push @out, $current;
        next if $current eq 'Module::Build::Base';
        no strict 'refs';
        unshift @in_stack,
          map {
              my $c = $_; # copy, to avoid being destructive
              substr($c,0,2) = "main::" if substr($c,0,2) eq '::';
              # Canonize the :: -&gt; main::, ::foo -&gt; main::foo thing.
              # Should I ever canonize the Foo'Bar = Foo::Bar thing?
              $seen{$c}++ ? () : $c;
          } @{"$current\::ISA"};

        # I.e., if this class has any parents (at least, ones I've never seen
        # before), push them, in order, onto the stack of classes I need to
        # explore.
    }
    shift @out;
    return @out;
}

sub extra_linker_flags   { shift-&gt;_list_accessor('extra_linker_flags',   @_) }
sub extra_compiler_flags { shift-&gt;_list_accessor('extra_compiler_flags', @_) }

sub _list_accessor {
  (my $self, local $_) = (shift, shift);
  my $p = $self-&gt;{properties};
  $p-&gt;{$_} = [@_] if @_;
  $p-&gt;{$_} = [] unless exists $p-&gt;{$_};
  return ref($p-&gt;{$_}) ? $p-&gt;{$_} : [$p-&gt;{$_}];
}

# XXX Problem - if Module::Build is loaded from a different directory,
# it'll look for (and perhaps destroy/create) a _build directory.
sub subclass {
  my ($pack, %opts) = @_;

  my $build_dir = '_build'; # XXX The _build directory is ostensibly settable by the user.  Shouldn't hard-code here.
  $pack-&gt;delete_filetree($build_dir) if -e $build_dir;

  die "Must provide 'code' or 'class' option to subclass()\n"
    unless $opts{code} or $opts{class};

  $opts{code}  ||= '';
  $opts{class} ||= 'MyModuleBuilder';

  my $filename = File::Spec-&gt;catfile($build_dir, 'lib', split '::', $opts{class}) . '.pm';
  my $filedir  = File::Basename::dirname($filename);
  $pack-&gt;log_verbose("Creating custom builder $filename in $filedir\n");

  File::Path::mkpath($filedir);
  die "Can't create directory $filedir: $!" unless -d $filedir;

  open(my $fh, '&gt;', $filename) or die "Can't create $filename: $!";
  print $fh &lt;&lt;EOF;
package $opts{class};
use $pack;
\@ISA = qw($pack);
$opts{code}
1;
EOF
  close $fh;

  unshift @INC, File::Spec-&gt;catdir(File::Spec-&gt;rel2abs($build_dir), 'lib');
  eval "use $opts{class}";
  die $@ if $@;

  return $opts{class};
}

sub _guess_module_name {
  my $self = shift;
  my $p = $self-&gt;{properties};
  return if $p-&gt;{module_name};
  if ( $p-&gt;{dist_version_from} &amp;&amp; -e $p-&gt;{dist_version_from} ) {
    my $mi = Module::Metadata-&gt;new_from_file($self-&gt;dist_version_from);
    $p-&gt;{module_name} = $mi-&gt;name;
  }
  else {
    my $mod_path = my $mod_name = $p-&gt;{dist_name};
    $mod_name =~ s{-}{::}g;
    $mod_path =~ s{-}{/}g;
    $mod_path .= ".pm";
    if ( -e $mod_path || -e "lib/$mod_path" ) {
      $p-&gt;{module_name} = $mod_name;
    }
    else {
      $self-&gt;log_warn( &lt;&lt; 'END_WARN' );
No 'module_name' was provided and it could not be inferred
from other properties.  This will prevent a packlist from
being written for this file.  Please set either 'module_name'
or 'dist_version_from' in Build.PL.
END_WARN
    }
  }
}

sub dist_name {
  my $self = shift;
  my $p = $self-&gt;{properties};
  my $me = 'dist_name';
  return $p-&gt;{$me} if defined $p-&gt;{$me};

  die "Can't determine distribution name, must supply either 'dist_name' or 'module_name' parameter"
    unless $self-&gt;module_name;

  ($p-&gt;{$me} = $self-&gt;module_name) =~ s/::/-/g;

  return $p-&gt;{$me};
}

sub release_status {
  my ($self) = @_;
  my $me = 'release_status';
  my $p = $self-&gt;{properties};

  if ( ! defined $p-&gt;{$me} ) {
    $p-&gt;{$me} = $self-&gt;_is_dev_version ? 'testing' : 'stable';
  }

  unless ( $p-&gt;{$me} =~ qr/\A(?:stable|testing|unstable)\z/ ) {
    die "Illegal value '$p-&gt;{$me}' for $me\n";
  }

  if ( $p-&gt;{$me} eq 'stable' &amp;&amp; $self-&gt;_is_dev_version ) {
    my $version = $self-&gt;dist_version;
    die "Illegal value '$p-&gt;{$me}' with version '$version'\n";
  }
  return $p-&gt;{$me};
}

sub dist_suffix {
  my ($self) = @_;
  my $p = $self-&gt;{properties};
  my $me = 'dist_suffix';

  return $p-&gt;{$me} if defined $p-&gt;{$me};

  if ( $self-&gt;release_status eq 'stable' ) {
    $p-&gt;{$me} = "";
  }
  else {
    # non-stable release but non-dev version number needs '-TRIAL' appended
    $p-&gt;{$me} = $self-&gt;_is_dev_version ? "" : "TRIAL" ;
  }

  return $p-&gt;{$me};
}

sub dist_version_from {
  my ($self) = @_;
  my $p = $self-&gt;{properties};
  my $me = 'dist_version_from';

  if ($self-&gt;module_name) {
    $p-&gt;{$me} ||=
      join( '/', 'lib', split(/::/, $self-&gt;module_name) ) . '.pm';
  }
  return $p-&gt;{$me} || undef;
}

sub dist_version {
  my ($self) = @_;
  my $p = $self-&gt;{properties};
  my $me = 'dist_version';

  return $p-&gt;{$me} if defined $p-&gt;{$me};

  if ( my $dist_version_from = $self-&gt;dist_version_from ) {
    my $version_from = File::Spec-&gt;catfile( split( qr{/}, $dist_version_from ) );
    my $pm_info = Module::Metadata-&gt;new_from_file( $version_from )
      or die "Can't find file $version_from to determine version";
    #$p-&gt;{$me} is undef here
    $p-&gt;{$me} = $self-&gt;normalize_version( $pm_info-&gt;version() );
    unless (defined $p-&gt;{$me}) {
      die "Can't determine distribution version from $version_from";
    }
  }

  die ("Can't determine distribution version, must supply either 'dist_version',\n".
       "'dist_version_from', or 'module_name' parameter")
    unless defined $p-&gt;{$me};

  return $p-&gt;{$me};
}

sub _is_dev_version {
  my ($self) = @_;
  my $dist_version = $self-&gt;dist_version;
  my $version_obj = eval { version-&gt;new( $dist_version ) };
  # assume it's normal if the version string is fatal -- in this case
  # the author might be doing something weird so should play along and
  # assume they'll specify all necessary behavior
  return $@ ? 0 : $version_obj-&gt;is_alpha;
}

sub dist_author   { shift-&gt;_pod_parse('author')   }
sub dist_abstract { shift-&gt;_pod_parse('abstract') }

sub _pod_parse {
  my ($self, $part) = @_;
  my $p = $self-&gt;{properties};
  my $member = "dist_$part";
  return $p-&gt;{$member} if defined $p-&gt;{$member};

  my $docfile = $self-&gt;_main_docfile
    or return;
  open(my $fh, '&lt;', $docfile)
    or return;

  require Module::Build::PodParser;
  my $parser = Module::Build::PodParser-&gt;new(fh =&gt; $fh);
  my $method = "get_$part";
  return $p-&gt;{$member} = $parser-&gt;$method();
}

sub version_from_file { # Method provided for backwards compatibility
  return Module::Metadata-&gt;new_from_file($_[1])-&gt;version();
}

sub find_module_by_name { # Method provided for backwards compatibility
  return Module::Metadata-&gt;find_module_by_name(@_[1,2]);
}

{
  # $unlink_list_for_pid{$$} = [ ... ]
  my %unlink_list_for_pid;

  sub _unlink_on_exit {
    my $self = shift;
    for my $f ( @_ ) {
      push @{$unlink_list_for_pid{$$}}, $f if -f $f;
    }
    return 1;
  }

  END {
    for my $f ( map glob($_), @{ $unlink_list_for_pid{$$} || [] } ) {
      next unless -e $f;
      File::Path::rmtree($f, 0, 0);
    }
  }
}

sub add_to_cleanup {
  my $self = shift;
  my %files = map {$self-&gt;localize_file_path($_), 1} @_;
  $self-&gt;{phash}{cleanup}-&gt;write(\%files);
}

sub cleanup {
  my $self = shift;
  my $all = $self-&gt;{phash}{cleanup}-&gt;read;
  return wantarray ? sort keys %$all : keys %$all;
}

sub config_file {
  my $self = shift;
  return unless -d $self-&gt;config_dir;
  return File::Spec-&gt;catfile($self-&gt;config_dir, @_);
}

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

  my $file = $self-&gt;config_file('build_params')
    or die "Can't find 'build_params' in " . $self-&gt;config_dir;
  open(my $fh, '&lt;', $file) or die "Can't read '$file': $!";
  my $ref = eval do {local $/; &lt;$fh&gt;};
  die if $@;
  close $fh;
  my $c;
  ($self-&gt;{args}, $c, $self-&gt;{properties}) = @$ref;
  $self-&gt;{config} = Module::Build::Config-&gt;new(values =&gt; $c);
}

sub has_config_data {
  my $self = shift;
  return scalar grep $self-&gt;{phash}{$_}-&gt;has_data(), qw(config_data features auto_features);
}

sub _write_data {
  my ($self, $filename, $data) = @_;

  my $file = $self-&gt;config_file($filename);
  open(my $fh, '&gt;', $file) or die "Can't create '$file': $!";
  unless (ref($data)) {  # e.g. magicnum
    print $fh $data;
    return;
  }

  print {$fh} Module::Build::Dumper-&gt;_data_dump($data);
  close $fh;
}

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

  File::Path::mkpath($self-&gt;{properties}{config_dir});
  -d $self-&gt;{properties}{config_dir} or die "Can't mkdir $self-&gt;{properties}{config_dir}: $!";

  my @items = @{ $self-&gt;prereq_action_types };
  $self-&gt;_write_data('prereqs', { map { $_, $self-&gt;$_() } @items });
  $self-&gt;_write_data('build_params', [$self-&gt;{args}, $self-&gt;{config}-&gt;values_set, $self-&gt;{properties}]);

  # Set a new magic number and write it to a file
  $self-&gt;_write_data('magicnum', $self-&gt;magic_number(int rand 1_000_000));

  $self-&gt;{phash}{$_}-&gt;write() foreach qw(notes cleanup features auto_features config_data runtime_params);
}

{
  # packfile map -- keys are guts of regular expressions;  If they match,
  # values are module names corresponding to the packlist
  my %packlist_map = (
    '^File::Spec'         =&gt; 'Cwd',
    '^Devel::AssertOS'    =&gt; 'Devel::CheckOS',
  );

  sub _find_packlist {
    my ($self, $inst, $mod) = @_;
    my $lookup = $mod;
    my $packlist = eval { $inst-&gt;packlist($lookup) };
    if ( ! $packlist ) {
      # try from packlist_map
      while ( my ($re, $new_mod) = each %packlist_map ) {
        if ( $mod =~ qr/$re/ ) {
          $lookup = $new_mod;
          $packlist = eval { $inst-&gt;packlist($lookup) };
          last;
        }
      }
    }
    return $packlist ? $lookup : undef;
  }

  sub set_bundle_inc {
    my $self = shift;

    my $bundle_inc = $self-&gt;{properties}{bundle_inc};
    my $bundle_inc_preload = $self-&gt;{properties}{bundle_inc_preload};
    # We're in author mode if inc::latest is loaded, but not from cwd
    return unless inc::latest-&gt;can('loaded_modules');
    require ExtUtils::Installed;
    # ExtUtils::Installed is buggy about finding additions to default @INC
    my $inst = eval { ExtUtils::Installed-&gt;new(extra_libs =&gt; [@INC]) };
    if ($@) {
      $self-&gt;log_warn( &lt;&lt; "EUI_ERROR" );
Bundling in inc/ is disabled because ExtUtils::Installed could not
create a list of your installed modules.  Here is the error:
$@
EUI_ERROR
      return;
    }
    my @bundle_list = map { [ $_, 0 ] } inc::latest-&gt;loaded_modules;

    # XXX TODO: Need to get ordering of prerequisites correct so they are
    # are loaded in the right order. Use an actual tree?!

    while( @bundle_list ) {
      my ($mod, $prereq) = @{ shift @bundle_list };

      # XXX TODO: Append prereqs to list
      # skip if core or already in bundle or preload lists
      # push @bundle_list, [$_, 1] for prereqs()

      # Locate packlist for bundling
      my $lookup = $self-&gt;_find_packlist($inst,$mod);
      if ( ! $lookup ) {
        # XXX Really needs a more helpful error message here
        die &lt;&lt; "NO_PACKLIST";
Could not find a packlist for '$mod'.  If it's a core module, try
force installing it from CPAN.
NO_PACKLIST
      }
      else {
        push @{ $prereq ? $bundle_inc_preload : $bundle_inc }, $lookup;
      }
    }
  } # sub check_bundling
}

sub check_autofeatures {
  my ($self) = @_;
  my $features = $self-&gt;auto_features;

  return 1 unless %$features;

  # TODO refactor into ::Util
  my $longest = sub {
    my @str = @_ or croak("no strings given");

    my @len = map({length($_)} @str);
    my $max = 0;
    my $longest;
    for my $i (0..$#len) {
      ($max, $longest) = ($len[$i], $str[$i]) if($len[$i] &gt; $max);
    }
    return($longest);
  };
  my $max_name_len = length($longest-&gt;(keys %$features));

  my ($num_disabled, $log_text) = (0, "\nChecking optional features...\n");
  for my $name ( sort keys %$features ) {
    $log_text .= $self-&gt;_feature_deps_msg($name, $max_name_len);
  }

  $num_disabled = () = $log_text =~ /disabled/g;

  # warn user if features disabled
  if ( $num_disabled ) {
    $self-&gt;log_warn( $log_text );
    return 0;
  }
  else {
    $self-&gt;log_verbose( $log_text );
    return 1;
  }
}

sub _feature_deps_msg {
  my ($self, $name, $max_name_len) = @_;
    $max_name_len ||= length $name;
    my $features = $self-&gt;auto_features;
    my $info = $features-&gt;{$name};
    my $feature_text = "$name" . '.' x ($max_name_len - length($name) + 4);

    my ($log_text, $disabled) = ('','');
    if ( my $failures = $self-&gt;prereq_failures($info) ) {
      $disabled = grep( /^(?:\w+_)?(?:requires|conflicts)$/,
                  keys %$failures ) ? 1 : 0;
      $feature_text .= $disabled ? "disabled\n" : "enabled\n";

      for my $type ( @{ $self-&gt;prereq_action_types } ) {
        next unless exists $failures-&gt;{$type};
        $feature_text .= "  $type:\n";
        my $prereqs = $failures-&gt;{$type};
        for my $module ( sort keys %$prereqs ) {
          my $status = $prereqs-&gt;{$module};
          my $required =
            ($type =~ /^(?:\w+_)?(?:requires|conflicts)$/) ? 1 : 0;
          my $prefix = ($required) ? '!' : '*';
          $feature_text .= "    $prefix $status-&gt;{message}\n";
        }
      }
    } else {
      $feature_text .= "enabled\n";
    }
    $log_text .= $feature_text if $disabled || $self-&gt;verbose;
    return $log_text;
}

# Automatically detect configure_requires prereqs
sub auto_config_requires {
  my ($self) = @_;
  my $p = $self-&gt;{properties};

  # add current Module::Build to configure_requires if there
  # isn't one already specified (but not ourself, so we're not circular)
  if ( $self-&gt;dist_name ne 'Module-Build'
    &amp;&amp; $self-&gt;auto_configure_requires
    &amp;&amp; ! exists $p-&gt;{configure_requires}{'Module::Build'}
  ) {
    (my $ver = $VERSION) =~ s/^(\d+\.\d\d).*$/$1/; # last major release only
    $self-&gt;log_warn(&lt;&lt;EOM);
Module::Build was not found in configure_requires! Adding it now
automatically as: configure_requires =&gt; { 'Module::Build' =&gt; $ver }
EOM
    $self-&gt;_add_prereq('configure_requires', 'Module::Build', $ver);
  }

  # if we're in author mode, add inc::latest modules to
  # configure_requires if not already set.  If we're not in author mode
  # then configure_requires will have been satisfied, or we'll just
  # live with what we've bundled
  if ( inc::latest-&gt;can('loaded_module') ) {
    for my $mod ( inc::latest-&gt;loaded_modules ) {
      next if exists $p-&gt;{configure_requires}{$mod};
      $self-&gt;_add_prereq('configure_requires', $mod, $mod-&gt;VERSION);
    }
  }

  return;
}

# Automatically detect and add prerequisites based on configuration
sub auto_require {
  my ($self) = @_;
  my $p = $self-&gt;{properties};

  # If needs_compiler is not explicitly set, automatically set it
  # If set, we need ExtUtils::CBuilder (and a compiler)
  my $xs_files = $self-&gt;find_xs_files;
  if ( ! defined $p-&gt;{needs_compiler} ) {
    $self-&gt;needs_compiler( keys %$xs_files || defined $self-&gt;c_source );
  }
  if ($self-&gt;needs_compiler) {
    $self-&gt;_add_prereq('build_requires', 'ExtUtils::CBuilder', 0);
    if ( ! $self-&gt;have_c_compiler ) {
      $self-&gt;log_warn(&lt;&lt;'EOM');
Warning: ExtUtils::CBuilder not installed or no compiler detected
Proceeding with configuration, but compilation may fail during Build

EOM
    }
  }

  # If using share_dir, require File::ShareDir
  if ( $self-&gt;share_dir ) {
    $self-&gt;_add_prereq( 'requires', 'File::ShareDir', '1.00' );
  }

  return;
}

sub _add_prereq {
  my ($self, $type, $module, $version) = @_;
  my $p = $self-&gt;{properties};
  $version = 0 unless defined $version;
  if ( exists $p-&gt;{$type}{$module} ) {
    return if $self-&gt;compare_versions( $version, '&lt;=', $p-&gt;{$type}{$module} );
  }
  $self-&gt;log_verbose("Adding to $type\: $module =&gt; $version\n");
  $p-&gt;{$type}{$module} = $version;
  return 1;
}

sub prereq_failures {
  my ($self, $info) = @_;

  my @types = @{ $self-&gt;prereq_action_types };
  $info ||= {map {$_, $self-&gt;$_()} @types};

  my $out;

  foreach my $type (@types) {
    my $prereqs = $info-&gt;{$type};
    for my $modname ( keys %$prereqs ) {
      my $spec = $prereqs-&gt;{$modname};
      my $status = $self-&gt;check_installed_status($modname, $spec);

      if ($type =~ /^(?:\w+_)?conflicts$/) {
        next if !$status-&gt;{ok};
        $status-&gt;{conflicts} = delete $status-&gt;{need};
        $status-&gt;{message} = "$modname ($status-&gt;{have}) conflicts with this distribution";

      } elsif ($type =~ /^(?:\w+_)?recommends$/) {
        next if $status-&gt;{ok};
        $status-&gt;{message} = (!ref($status-&gt;{have}) &amp;&amp; $status-&gt;{have} eq '&lt;none&gt;'
                              ? "$modname is not installed"
                              : "$modname ($status-&gt;{have}) is installed, but we prefer to have $spec");
      } else {
        next if $status-&gt;{ok};
      }

      $out-&gt;{$type}{$modname} = $status;
    }
  }

  return $out;
}

# returns a hash of defined prerequisites; i.e. only prereq types with values
sub _enum_prereqs {
  my $self = shift;
  my %prereqs;
  foreach my $type ( @{ $self-&gt;prereq_action_types } ) {
    if ( $self-&gt;can( $type ) ) {
      my $prereq = $self-&gt;$type() || {};
      $prereqs{$type} = $prereq if %$prereq;
    }
  }
  return \%prereqs;
}

sub check_prereq {
  my $self = shift;

  # Check to see if there are any prereqs to check
  my $info = $self-&gt;_enum_prereqs;
  return 1 unless $info;

  my $log_text = "Checking prerequisites...\n";

  my $failures = $self-&gt;prereq_failures($info);

  if ( $failures ) {
    $self-&gt;log_warn($log_text);
    for my $type ( @{ $self-&gt;prereq_action_types } ) {
      my $prereqs = $failures-&gt;{$type};
      $self-&gt;log_warn("  ${type}:\n") if keys %$prereqs;
      for my $module ( sort keys %$prereqs ) {
        my $status = $prereqs-&gt;{$module};
        my $prefix = ($type =~ /^(?:\w+_)?recommends$/) ? "* " : "! ";
        $self-&gt;log_warn("    $prefix $status-&gt;{message}\n");
      }
    }
    return 0;
  } else {
    $self-&gt;log_verbose($log_text . "Looks good\n\n");
    return 1;
  }
}

sub perl_version {
  my ($self) = @_;
  # Check the current perl interpreter
  # It's much more convenient to use $] here than $^V, but 'man
  # perlvar' says I'm not supposed to.  Bloody tyrant.
  return $^V ? $self-&gt;perl_version_to_float(sprintf "%vd", $^V) : $];
}

sub perl_version_to_float {
  my ($self, $version) = @_;
  return $version if grep( /\./, $version ) &lt; 2;
  $version =~ s/\./../;
  $version =~ s/\.(\d+)/sprintf '%03d', $1/eg;
  return $version;
}

sub _parse_conditions {
  my ($self, $spec) = @_;

  return "&gt;= 0" if not defined $spec;
  if ($spec =~ /^\s*([\w.]+)\s*$/) { # A plain number, maybe with dots, letters, and underscores
    return ("&gt;= $spec");
  } else {
    return split /\s*,\s*/, $spec;
  }
}

sub try_require {
  my ($self, $modname, $spec) = @_;
  my $status = $self-&gt;check_installed_status($modname, defined($spec) ? $spec : 0);
  return unless $status-&gt;{ok};
  my $path = $modname;
  $path =~ s{::}{/}g;
  $path .= ".pm";
  if ( defined $INC{$path} ) {
    return 1;
  }
  elsif ( exists $INC{$path} ) { # failed before, don't try again
    return;
  }
  else {
    return eval "require $modname";
  }
}

sub check_installed_status {
  my ($self, $modname, $spec) = @_;
  my %status = (need =&gt; $spec);

  if ($modname eq 'perl') {
    $status{have} = $self-&gt;perl_version;

  } elsif (eval { no strict; $status{have} = ${"${modname}::VERSION"} }) {
    # Don't try to load if it's already loaded

  } else {
    my $pm_info = Module::Metadata-&gt;new_from_module( $modname );
    unless (defined( $pm_info )) {
      @status{ qw(have message) } = ('&lt;none&gt;', "$modname is not installed");
      return \%status;
    }

    $status{have} = eval { $pm_info-&gt;version() };
    if ($spec and !defined($status{have})) {
      @status{ qw(have message) } = (undef, "Couldn't find a \$VERSION in prerequisite $modname");
      return \%status;
    }
  }

  my @conditions = $self-&gt;_parse_conditions($spec);

  foreach (@conditions) {
    my ($op, $version) = /^\s*  (&lt;=?|&gt;=?|==|!=)  \s*  ([\w.]+)  \s*$/x
      or die "Invalid prerequisite condition '$_' for $modname";

    $version = $self-&gt;perl_version_to_float($version)
      if $modname eq 'perl';

    next if $op eq '&gt;=' and !$version;  # Module doesn't have to actually define a $VERSION

    unless ($self-&gt;compare_versions( $status{have}, $op, $version )) {
      $status{message} = "$modname ($status{have}) is installed, but we need version $op $version";
      return \%status;
    }
  }

  $status{ok} = 1;
  return \%status;
}

sub compare_versions {
  my $self = shift;
  my ($v1, $op, $v2) = @_;
  $v1 = version-&gt;new($v1)
    unless eval { $v1-&gt;isa('version') };

  my $eval_str = "\$v1 $op \$v2";
  my $result   = eval $eval_str;
  $self-&gt;log_warn("error comparing versions: '$eval_str' $@") if $@;

  return $result;
}

# I wish I could set $! to a string, but I can't, so I use $@
sub check_installed_version {
  my ($self, $modname, $spec) = @_;

  my $status = $self-&gt;check_installed_status($modname, $spec);

  if ($status-&gt;{ok}) {
    return $status-&gt;{have} if $status-&gt;{have} and "$status-&gt;{have}" ne '&lt;none&gt;';
    return '0 but true';
  }

  $@ = $status-&gt;{message};
  return 0;
}

sub make_executable {
  # Perl's chmod() is mapped to useful things on various non-Unix
  # platforms, so we use it in the base class even though it looks
  # Unixish.

  my $self = shift;
  foreach (@_) {
    my $current_mode = (stat $_)[2];
    chmod $current_mode | oct(111), $_;
  }
}

sub is_executable {
  # We assume this does the right thing on generic platforms, though
  # we do some other more specific stuff on Unixish platforms.
  my ($self, $file) = @_;
  return -x $file;
}

sub _startperl { shift()-&gt;config('startperl') }

# Return any directories in @INC which are not in the default @INC for
# this perl.  For example, stuff passed in with -I or loaded with "use lib".
sub _added_to_INC {
  my $self = shift;

  my %seen;
  $seen{$_}++ foreach $self-&gt;_default_INC;
  return grep !$seen{$_}++, @INC;
}

# Determine the default @INC for this Perl
{
  my @default_inc; # Memoize
  sub _default_INC {
    my $self = shift;
    return @default_inc if @default_inc;

    local $ENV{PERL5LIB};  # this is not considered part of the default.

    my $perl = ref($self) ? $self-&gt;perl : $self-&gt;find_perl_interpreter;

    my @inc = $self-&gt;_backticks($perl, '-le', 'print for @INC');
    chomp @inc;

    return @default_inc = @inc;
  }
}

sub print_build_script {
  my ($self, $fh) = @_;

  my $build_package = $self-&gt;build_class;

  my $closedata="";

  my $config_requires;
  if ( -f $self-&gt;metafile ) {
    my $meta = eval { $self-&gt;read_metafile( $self-&gt;metafile ) };
    $config_requires = $meta &amp;&amp; $meta-&gt;{prereqs}{configure}{requires}{'Module::Build'};
  }
  $config_requires ||= 0;

  my %q = map {$_, $self-&gt;$_()} qw(config_dir base_dir);

  $q{base_dir} = Win32::GetShortPathName($q{base_dir}) if $self-&gt;is_windowsish;

  $q{magic_numfile} = $self-&gt;config_file('magicnum');

  my @myINC = $self-&gt;_added_to_INC;
  for (@myINC, values %q) {
    $_ = File::Spec-&gt;canonpath( $_ ) unless $self-&gt;is_vmsish;
    s/([\\\'])/\\$1/g;
  }

  my $quoted_INC = join ",\n", map "     '$_'", @myINC;
  my $shebang = $self-&gt;_startperl;
  my $magic_number = $self-&gt;magic_number;

my $dot_in_inc_code = $INC[-1] eq '.' ? &lt;&lt;'END' : '';
    if ($INC[-1] ne '.') {
        push @INC, '.';
    }
END
  print $fh &lt;&lt;EOF;
$shebang

use strict;
use Cwd;
use File::Basename;
use File::Spec;

sub magic_number_matches {
  return 0 unless -e '$q{magic_numfile}';
  my \$FH;
  open \$FH, '&lt;','$q{magic_numfile}' or return 0;
  my \$filenum = &lt;\$FH&gt;;
  close \$FH;
  return \$filenum == $magic_number;
}

my \$progname;
my \$orig_dir;
BEGIN {
  \$^W = 1;  # Use warnings
  \$progname = basename(\$0);
  \$orig_dir = Cwd::cwd();
  my \$base_dir = '$q{base_dir}';
  if (!magic_number_matches()) {
    unless (chdir(\$base_dir)) {
      die ("Couldn't chdir(\$base_dir), aborting\\n");
    }
    unless (magic_number_matches()) {
      die ("Configuration seems to be out of date, please re-run 'perl Build.PL' again.\\n");
    }
  }
  unshift \@INC,
    (
$quoted_INC
    );
$dot_in_inc_code
}

close(*DATA) unless eof(*DATA); # ensure no open handles to this script

use $build_package;
Module::Build-&gt;VERSION(q{$config_requires});

# Some platforms have problems setting \$^X in shebang contexts, fix it up here
\$^X = Module::Build-&gt;find_perl_interpreter;

if (-e 'Build.PL' and not $build_package-&gt;up_to_date('Build.PL', \$progname)) {
   warn "Warning: Build.PL has been altered.  You may need to run 'perl Build.PL' again.\\n";
}

# This should have just enough arguments to be able to bootstrap the rest.
my \$build = $build_package-&gt;resume (
  properties =&gt; {
    config_dir =&gt; '$q{config_dir}',
    orig_dir =&gt; \$orig_dir,
  },
);

\$build-&gt;dispatch;
EOF
}

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

  my ($meta_obj, $mymeta);
  my @metafiles = ( $self-&gt;metafile2, $self-&gt;metafile,  );
  my @mymetafiles = ( $self-&gt;mymetafile2, $self-&gt;mymetafile, );

  # cleanup old MYMETA
  for my $f ( @mymetafiles ) {
    if ( $self-&gt;delete_filetree($f) ) {
      $self-&gt;log_verbose("Removed previous '$f'\n");
    }
  }

  # Try loading META.json or META.yml
  if ( $self-&gt;try_require("CPAN::Meta", "2.142060") ) {
    for my $file ( @metafiles ) {
      next unless -f $file;
      $meta_obj = eval { CPAN::Meta-&gt;load_file($file, { lazy_validation =&gt; 0 }) };
      last if $meta_obj;
    }
  }

  # maybe get a copy in spec v2 format (regardless of original source)

  my $mymeta_obj;
  if ($meta_obj) {
    # if we have metadata, just update it
    my %updated = (
      %{ $meta_obj-&gt;as_struct({ version =&gt; 2.0 }) },
      prereqs =&gt; $self-&gt;_normalize_prereqs,
      dynamic_config =&gt; 0,
      generated_by =&gt; "Module::Build version $Module::Build::VERSION",
    );
    $mymeta_obj = CPAN::Meta-&gt;new( \%updated, { lazy_validation =&gt; 0 } );
  }
  else {
    $mymeta_obj = $self-&gt;_get_meta_object(quiet =&gt; 0, dynamic =&gt; 0, fatal =&gt; 1, auto =&gt; 0);
  }

  my @created = $self-&gt;_write_meta_files( $mymeta_obj, 'MYMETA' );

  $self-&gt;log_warn("Could not create MYMETA files\n")
    unless @created;

  return 1;
}

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

  $self-&gt;write_config;
  $self-&gt;create_mymeta;

  # Create Build
  my ($build_script, $dist_name, $dist_version)
    = map $self-&gt;$_(), qw(build_script dist_name dist_version);

  if ( $self-&gt;delete_filetree($build_script) ) {
    $self-&gt;log_verbose("Removed previous script '$build_script'\n");
  }

  $self-&gt;log_info("Creating new '$build_script' script for ",
                  "'$dist_name' version '$dist_version'\n");
  open(my $fh, '&gt;', $build_script) or die "Can't create '$build_script': $!";
  $self-&gt;print_build_script($fh);
  close $fh;

  $self-&gt;make_executable($build_script);

  return 1;
}

sub check_manifest {
  my $self = shift;
  return unless -e 'MANIFEST';

  # Stolen nearly verbatim from MakeMaker.  But ExtUtils::Manifest
  # could easily be re-written into a modern Perl dialect.

  require ExtUtils::Manifest;  # ExtUtils::Manifest is not warnings clean.
  local ($^W, $ExtUtils::Manifest::Quiet) = (0,1);

  $self-&gt;log_verbose("Checking whether your kit is complete...\n");
  if (my @missed = ExtUtils::Manifest::manicheck()) {
    $self-&gt;log_warn("WARNING: the following files are missing in your kit:\n",
                    "\t", join("\n\t", @missed), "\n",
                    "Please inform the author.\n\n");
  } else {
    $self-&gt;log_verbose("Looks good\n\n");
  }
}

sub dispatch {
  my $self = shift;
  local $self-&gt;{_completed_actions} = {};

  if (@_) {
    my ($action, %p) = @_;
    my $args = $p{args} ? delete($p{args}) : {};

    local $self-&gt;{invoked_action} = $action;
    local $self-&gt;{args} = {%{$self-&gt;{args}}, %$args};
    local $self-&gt;{properties} = {%{$self-&gt;{properties}}, %p};
    return $self-&gt;_call_action($action);
  }

  die "No build action specified" unless $self-&gt;{action};
  local $self-&gt;{invoked_action} = $self-&gt;{action};
  $self-&gt;_call_action($self-&gt;{action});
}

sub _call_action {
  my ($self, $action) = @_;

  return if $self-&gt;{_completed_actions}{$action}++;

  local $self-&gt;{action} = $action;
  my $method = $self-&gt;can_action( $action );
  die "No action '$action' defined, try running the 'help' action.\n" unless $method;
  $self-&gt;log_debug("Starting ACTION_$action\n");
  my $rc = $self-&gt;$method();
  $self-&gt;log_debug("Finished ACTION_$action\n");
  return $rc;
}

sub can_action {
  my ($self, $action) = @_;
  return $self-&gt;can( "ACTION_$action" );
}

# cuts the user-specified options out of the command-line args
sub cull_options {
    my $self = shift;
    my (@argv) = @_;

    # XXX is it even valid to call this as a class method?
    return({}, @argv) unless(ref($self)); # no object

    my $specs = $self-&gt;get_options;
    return({}, @argv) unless($specs and %$specs); # no user options

    require Getopt::Long;
    # XXX Should we let Getopt::Long handle M::B's options? That would
    # be easy-ish to add to @specs right here, but wouldn't handle options
    # passed without "--" as M::B currently allows. We might be able to
    # get around this by setting the "prefix_pattern" Configure option.
    my @specs;
    my $args = {};
    # Construct the specifications for GetOptions.
    foreach my $k (sort keys %$specs) {
        my $v = $specs-&gt;{$k};
        # Throw an error if specs conflict with our own.
        die "Option specification '$k' conflicts with a " . ref $self
          . " option of the same name"
          if $self-&gt;valid_property($k);
        push @specs, $k . (defined $v-&gt;{type} ? $v-&gt;{type} : '');
        push @specs, $v-&gt;{store} if exists $v-&gt;{store};
        $args-&gt;{$k} = $v-&gt;{default} if exists $v-&gt;{default};
    }

    local @ARGV = @argv; # No other way to dupe Getopt::Long

    # Get the options values and return them.
    # XXX Add option to allow users to set options?
    if ( @specs ) {
      Getopt::Long::Configure('pass_through');
      Getopt::Long::GetOptions($args, @specs);
    }

    return $args, @ARGV;
}

sub unparse_args {
  my ($self, $args) = @_;
  my @out;
  foreach my $k (sort keys %$args) {
    my $v = $args-&gt;{$k};
    push @out, (ref $v eq 'HASH'  ? map {+"--$k", "$_=$v-&gt;{$_}"} sort keys %$v :
                ref $v eq 'ARRAY' ? map {+"--$k", $_} @$v :
                ("--$k", $v));
  }
  return @out;
}

sub args {
    my $self = shift;
    return wantarray ? %{ $self-&gt;{args} } : $self-&gt;{args} unless @_;
    my $key = shift;
    $self-&gt;{args}{$key} = shift if @_;
    return $self-&gt;{args}{$key};
}

# allows select parameters (with underscores) to be spoken with dashes
# when used as command-line options
sub _translate_option {
  my $self = shift;
  my $opt  = shift;

  (my $tr_opt = $opt) =~ tr/-/_/;

  return $tr_opt if grep $tr_opt =~ /^(?:no_?)?$_$/, qw(
    create_license
    create_makefile_pl
    create_readme
    extra_compiler_flags
    extra_linker_flags
    install_base
    install_path
    meta_add
    meta_merge
    test_files
    use_rcfile
    use_tap_harness
    tap_harness_args
    cpan_client
    pureperl_only
    allow_pureperl
  ); # normalize only selected option names

  return $opt;
}

my %singular_argument = map { ($_ =&gt; 1) } qw/install_base prefix destdir installdirs verbose quiet uninst debug sign/;

sub _read_arg {
  my ($self, $args, $key, $val) = @_;

  $key = $self-&gt;_translate_option($key);

  if ( exists $args-&gt;{$key} and not $singular_argument{$key} ) {
    $args-&gt;{$key} = [ $args-&gt;{$key} ] unless ref $args-&gt;{$key};
    push @{$args-&gt;{$key}}, $val;
  } else {
    $args-&gt;{$key} = $val;
  }
}

# decide whether or not an option requires/has an operand
sub _optional_arg {
  my $self = shift;
  my $opt  = shift;
  my $argv = shift;

  $opt = $self-&gt;_translate_option($opt);

  my @bool_opts = qw(
    build_bat
    create_license
    create_readme
    pollute
    quiet
    uninst
    use_rcfile
    verbose
    debug
    sign
    use_tap_harness
    pureperl_only
    allow_pureperl
  );

  # inverted boolean options; eg --noverbose or --no-verbose
  # converted to proper name &amp; returned with false value (verbose, 0)
  if ( grep $opt =~ /^no[-_]?$_$/, @bool_opts ) {
    $opt =~ s/^no-?//;
    return ($opt, 0);
  }

  # non-boolean option; return option unchanged along with its argument
  return ($opt, shift(@$argv)) unless grep $_ eq $opt, @bool_opts;

  # we're punting a bit here, if an option appears followed by a digit
  # we take the digit as the argument for the option. If there is
  # nothing that looks like a digit, we pretend the option is a flag
  # that is being set and has no argument.
  my $arg = 1;
  $arg = shift(@$argv) if @$argv &amp;&amp; $argv-&gt;[0] =~ /^\d+$/;

  return ($opt, $arg);
}

sub read_args {
  my $self = shift;

  (my $args, @_) = $self-&gt;cull_options(@_);
  my %args = %$args;

  my $opt_re = qr/[\w\-]+/;

  my ($action, @argv);
  while (@_) {
    local $_ = shift;
    if ( /^(?:--)?($opt_re)=(.*)$/ ) {
      $self-&gt;_read_arg(\%args, $1, $2);
    } elsif ( /^--($opt_re)$/ ) {
      my($opt, $arg) = $self-&gt;_optional_arg($1, \@_);
      $self-&gt;_read_arg(\%args, $opt, $arg);
    } elsif ( /^($opt_re)$/ and !defined($action)) {
      $action = $1;
    } else {
      push @argv, $_;
    }
  }
  $args{ARGV} = \@argv;

  for ('extra_compiler_flags', 'extra_linker_flags') {
    $args{$_} = [ $self-&gt;split_like_shell($args{$_}) ] if exists $args{$_};
  }

  # Convert to arrays
  for ('include_dirs') {
    $args{$_} = [ $args{$_} ] if exists $args{$_} &amp;&amp; !ref $args{$_}
  }

  # Hashify these parameters
  for ($self-&gt;hash_properties, 'config') {
    next unless exists $args{$_};
    my %hash;
    $args{$_} ||= [];
    $args{$_} = [ $args{$_} ] unless ref $args{$_};
    foreach my $arg ( @{$args{$_}} ) {
      $arg =~ /($opt_re)=(.*)/
        or die "Malformed '$_' argument: '$arg' should be something like 'foo=bar'";
      $hash{$1} = $2;
    }
    $args{$_} = \%hash;
  }

  # De-tilde-ify any path parameters
  for my $key (qw(prefix install_base destdir)) {
    next if !defined $args{$key};
    $args{$key} = $self-&gt;_detildefy($args{$key});
  }

  for my $key (qw(install_path)) {
    next if !defined $args{$key};

    for my $subkey (keys %{$args{$key}}) {
      next if !defined $args{$key}{$subkey};
      my $subkey_ext = $self-&gt;_detildefy($args{$key}{$subkey});
      if ( $subkey eq 'html' ) { # translate for compatibility
        $args{$key}{binhtml} = $subkey_ext;
        $args{$key}{libhtml} = $subkey_ext;
      } else {
        $args{$key}{$subkey} = $subkey_ext;
      }
    }
  }

  if ($args{makefile_env_macros}) {
    require Module::Build::Compat;
    %args = (%args, Module::Build::Compat-&gt;makefile_to_build_macros);
  }

  return \%args, $action;
}

# Default: do nothing.  Overridden for Unix &amp; Windows.
sub _detildefy {}


# merge Module::Build argument lists that have already been parsed
# by read_args(). Takes two references to option hashes and merges
# the contents, giving priority to the first.
sub _merge_arglist {
  my( $self, $opts1, $opts2 ) = @_;

  $opts1 ||= {};
  $opts2 ||= {};
  my %new_opts = %$opts1;
  while (my ($key, $val) = each %$opts2) {
    if ( exists( $opts1-&gt;{$key} ) ) {
      if ( ref( $val ) eq 'HASH' ) {
        while (my ($k, $v) = each %$val) {
          $new_opts{$key}{$k} = $v unless exists( $opts1-&gt;{$key}{$k} );
        }
      }
    } else {
      $new_opts{$key} = $val
    }
  }

  return %new_opts;
}

# Look for a home directory on various systems.
sub _home_dir {
  my @home_dirs;
  push( @home_dirs, $ENV{HOME} ) if $ENV{HOME};

  push( @home_dirs, File::Spec-&gt;catpath($ENV{HOMEDRIVE}, $ENV{HOMEPATH}, '') )
      if $ENV{HOMEDRIVE} &amp;&amp; $ENV{HOMEPATH};

  my @other_home_envs = qw( USERPROFILE APPDATA WINDIR SYS$LOGIN );
  push( @home_dirs, map $ENV{$_}, grep $ENV{$_}, @other_home_envs );

  my @real_home_dirs = grep -d, @home_dirs;

  return wantarray ? @real_home_dirs : shift( @real_home_dirs );
}

sub _find_user_config {
  my $self = shift;
  my $file = shift;
  foreach my $dir ( $self-&gt;_home_dir ) {
    my $path = File::Spec-&gt;catfile( $dir, $file );
    return $path if -e $path;
  }
  return undef;
}

# read ~/.modulebuildrc returning global options '*' and
# options specific to the currently executing $action.
sub read_modulebuildrc {
  my( $self, $action ) = @_;

  return () unless $self-&gt;use_rcfile;

  my $modulebuildrc;
  if ( exists($ENV{MODULEBUILDRC}) &amp;&amp; $ENV{MODULEBUILDRC} eq 'NONE' ) {
    return ();
  } elsif ( exists($ENV{MODULEBUILDRC}) &amp;&amp; -e $ENV{MODULEBUILDRC} ) {
    $modulebuildrc = $ENV{MODULEBUILDRC};
  } elsif ( exists($ENV{MODULEBUILDRC}) ) {
    $self-&gt;log_warn("WARNING: Can't find resource file " .
                    "'$ENV{MODULEBUILDRC}' defined in environment.\n" .
                    "No options loaded\n");
    return ();
  } else {
    $modulebuildrc = $self-&gt;_find_user_config( '.modulebuildrc' );
    return () unless $modulebuildrc;
  }

  open(my $fh, '&lt;', $modulebuildrc )
      or die "Can't open $modulebuildrc: $!";

  my %options; my $buffer = '';
  while (defined( my $line = &lt;$fh&gt; )) {
    chomp( $line );
    $line =~ s/#.*$//;
    next unless length( $line );

    if ( $line =~ /^\S/ ) {
      if ( $buffer ) {
        my( $action, $options ) = split( /\s+/, $buffer, 2 );
        $options{$action} .= $options . ' ';
        $buffer = '';
      }
      $buffer = $line;
    } else {
      $buffer .= $line;
    }
  }

  if ( $buffer ) { # anything left in $buffer ?
    my( $action, $options ) = split( /\s+/, $buffer, 2 );
    $options{$action} .= $options . ' '; # merge if more than one line
  }

  my ($global_opts) =
    $self-&gt;read_args( $self-&gt;split_like_shell( $options{'*'} || '' ) );

  # let fakeinstall act like install if not provided
  if ( $action eq 'fakeinstall' &amp;&amp; ! exists $options{fakeinstall} ) {
    $action = 'install';
  }
  my ($action_opts) =
    $self-&gt;read_args( $self-&gt;split_like_shell( $options{$action} || '' ) );

  # specific $action options take priority over global options '*'
  return $self-&gt;_merge_arglist( $action_opts, $global_opts );
}

# merge the relevant options in ~/.modulebuildrc into Module::Build's
# option list where they do not conflict with commandline options.
sub merge_modulebuildrc {
  my( $self, $action, %cmdline_opts ) = @_;
  my %rc_opts = $self-&gt;read_modulebuildrc( $action || $self-&gt;{action} || 'build' );
  my %new_opts = $self-&gt;_merge_arglist( \%cmdline_opts, \%rc_opts );
  $self-&gt;merge_args( $action, %new_opts );
}

sub merge_args {
  my ($self, $action, %args) = @_;
  $self-&gt;{action} = $action if defined $action;

  my %additive = map { $_ =&gt; 1 } $self-&gt;hash_properties;

  # Extract our 'properties' from $cmd_args, the rest are put in 'args'.
  while (my ($key, $val) = each %args) {
    $self-&gt;{phash}{runtime_params}-&gt;access( $key =&gt; $val )
      if $self-&gt;valid_property($key);

    if ($key eq 'config') {
      $self-&gt;config($_ =&gt; $val-&gt;{$_}) foreach keys %$val;
    } else {
      my $add_to = $additive{$key}             ? $self-&gt;{properties}{$key} :
                   $self-&gt;valid_property($key) ? $self-&gt;{properties}       :
                   $self-&gt;{args}               ;

      if ($additive{$key}) {
        $add_to-&gt;{$_} = $val-&gt;{$_} foreach keys %$val;
      } else {
        $add_to-&gt;{$key} = $val;
      }
    }
  }
}

sub cull_args {
  my $self = shift;
  my @arg_list = @_;
  unshift @arg_list, $self-&gt;split_like_shell($ENV{PERL_MB_OPT})
    if $ENV{PERL_MB_OPT};
  my ($args, $action) = $self-&gt;read_args(@arg_list);
  $self-&gt;merge_args($action, %$args);
  $self-&gt;merge_modulebuildrc( $action, %$args );
}

sub super_classes {
  my ($self, $class, $seen) = @_;
  $class ||= ref($self) || $self;
  $seen  ||= {};

  no strict 'refs';
  my @super = grep {not $seen-&gt;{$_}++} $class, @{ $class . '::ISA' };
  return @super, map {$self-&gt;super_classes($_,$seen)} @super;
}

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

  my %actions;
  no strict 'refs';

  foreach my $class ($self-&gt;super_classes) {
    foreach ( keys %{ $class . '::' } ) {
      $actions{$1}++ if /^ACTION_(\w+)/;
    }
  }

  return wantarray ? sort keys %actions : \%actions;
}

sub get_action_docs {
  my ($self, $action) = @_;
  my $actions = $self-&gt;known_actions;
  die "No known action '$action'" unless $actions-&gt;{$action};

  my ($files_found, @docs) = (0);
  foreach my $class ($self-&gt;super_classes) {
    (my $file = $class) =~ s{::}{/}g;
    # NOTE: silently skipping relative paths if any chdir() happened
    $file = $INC{$file . '.pm'} or next;
    open(my $fh, '&lt;', $file) or next;
    $files_found++;

    # Code below modified from /usr/bin/perldoc

    # Skip to ACTIONS section
    local $_;
    while (&lt;$fh&gt;) {
      last if /^=head1 ACTIONS\s/;
    }

    # Look for our action and determine the style
    my $style;
    while (&lt;$fh&gt;) {
      last if /^=head1 /;

      # only item and head2 are allowed (3&amp;4 are not in 5.005)
      if(/^=(item|head2)\s+\Q$action\E\b/) {
        $style = $1;
        push @docs, $_;
        last;
      }
    }
    $style or next; # not here

    # and the content
    if($style eq 'item') {
      my ($found, $inlist) = (0, 0);
      while (&lt;$fh&gt;) {
        if (/^=(item|back)/) {
          last unless $inlist;
        }
        push @docs, $_;
        ++$inlist if /^=over/;
        --$inlist if /^=back/;
      }
    }
    else { # head2 style
      # stop at anything equal or greater than the found level
      while (&lt;$fh&gt;) {
        last if(/^=(?:head[12]|cut)/);
        push @docs, $_;
      }
    }
    # TODO maybe disallow overriding just pod for an action
    # TODO and possibly: @docs and last;
  }

  unless ($files_found) {
    $@ = "Couldn't find any documentation to search";
    return;
  }
  unless (@docs) {
    $@ = "Couldn't find any docs for action '$action'";
    return;
  }

  return join '', @docs;
}

sub ACTION_prereq_report {
  my $self = shift;
  $self-&gt;log_info( $self-&gt;prereq_report );
}

sub ACTION_prereq_data {
  my $self = shift;
  $self-&gt;log_info( Module::Build::Dumper-&gt;_data_dump( $self-&gt;prereq_data ) );
}

sub prereq_data {
  my $self = shift;
  my @types = ('configure_requires', @{ $self-&gt;prereq_action_types } );
  my $info = { map { $_ =&gt; $self-&gt;$_() } grep { %{$self-&gt;$_()} } @types };
  return $info;
}

sub prereq_report {
  my $self = shift;
  my $info = $self-&gt;prereq_data;

  my $output = '';
  foreach my $type (sort keys %$info) {
    my $prereqs = $info-&gt;{$type};
    $output .= "\n$type:\n";
    my $mod_len = 2;
    my $ver_len = 4;
    my %mods;
    foreach my $modname (sort keys %$prereqs) {
      my $spec = $prereqs-&gt;{$modname};
      my $len  = length $modname;
      $mod_len = $len if $len &gt; $mod_len;
      $spec    ||= '0';
      $len     = length $spec;
      $ver_len = $len if $len &gt; $ver_len;

      my $mod = $self-&gt;check_installed_status($modname, $spec);
      $mod-&gt;{name} = $modname;
      $mod-&gt;{ok} ||= 0;
      $mod-&gt;{ok} = ! $mod-&gt;{ok} if $type =~ /^(\w+_)?conflicts$/;

      $mods{lc $modname} = $mod;
    }

    my $space  = q{ } x ($mod_len - 3);
    my $vspace = q{ } x ($ver_len - 3);
    my $sline  = q{-} x ($mod_len - 3);
    my $vline  = q{-} x ($ver_len - 3);
    my $disposition = ($type =~ /^(\w+_)?conflicts$/) ?
                        'Clash' : 'Need';
    $output .=
      "    Module $space  $disposition $vspace  Have\n".
      "    ------$sline+------$vline-+----------\n";


    for my $k (sort keys %mods) {
      my $mod = $mods{$k};
      my $space  = q{ } x ($mod_len - length $k);
      my $vspace = q{ } x ($ver_len - length $mod-&gt;{need});
      my $f = $mod-&gt;{ok} ? ' ' : '!';
      $output .=
        "  $f $mod-&gt;{name} $space     $mod-&gt;{need}  $vspace   ".
        (defined($mod-&gt;{have}) ? $mod-&gt;{have} : "")."\n";
    }
  }
  return $output;
}

sub ACTION_help {
  my ($self) = @_;
  my $actions = $self-&gt;known_actions;

  if (@{$self-&gt;{args}{ARGV}}) {
    my $msg = eval {$self-&gt;get_action_docs($self-&gt;{args}{ARGV}[0], $actions)};
    print $@ ? "$@\n" : $msg;
    return;
  }

  print &lt;&lt;EOF;

 Usage: $0 &lt;action&gt; --arg1=value --arg2=value ...
 Example: $0 test --verbose=1

 Actions defined:
EOF

  print $self-&gt;_action_listing($actions);

  print "\nRun `Build help &lt;action&gt;` for details on an individual action.\n";
  print "See `perldoc Module::Build` for complete documentation.\n";
}

sub _action_listing {
  my ($self, $actions) = @_;

  # Flow down columns, not across rows
  my @actions = sort keys %$actions;
  @actions = map $actions[($_ + ($_ % 2) * @actions) / 2],  0..$#actions;

  my $out = '';
  while (my ($one, $two) = splice @actions, 0, 2) {
    $out .= sprintf("  %-12s                   %-12s\n", $one, $two||'');
  }
  $out =~ s{\s*$}{}mg; # remove trailing spaces
  return $out;
}

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

  # Protect others against our @INC changes
  local @INC = @INC;

  # Filter out nonsensical @INC entries - some versions of
  # Test::Harness will really explode the number of entries here
  @INC = grep {ref() || -d} @INC if @INC &gt; 100;

  $self-&gt;do_tests;
}

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

  my @types;
  for my $action (grep { $_ ne 'all' } $self-&gt;get_test_types) {
    # XXX We can't just dispatch because we get multiple summaries but
    # we'll need to dispatch to support custom setup/teardown in the
    # action.  To support that, we'll need to call something besides
    # Harness::runtests() because we'll need to collect the results in
    # parts, then run the summary.
    push(@types, $action);
    #$self-&gt;_call_action( "test$action" );
  }
  $self-&gt;generic_test(types =&gt; ['default', @types]);
}

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

  my $t = $self-&gt;{properties}-&gt;{test_types};
  return ( defined $t ? ( wantarray ? sort keys %$t : keys %$t ) : () );
}


sub ACTION_test {
  my ($self) = @_;
  $self-&gt;generic_test(type =&gt; 'default');
}

sub generic_test {
  my $self = shift;
  (@_ % 2) and croak('Odd number of elements in argument hash');
  my %args = @_;

  my $p = $self-&gt;{properties};

  my @types = (
    (exists($args{type})  ? $args{type} : ()),
    (exists($args{types}) ? @{$args{types}} : ()),
  );
  @types or croak "need some types of tests to check";

  my %test_types = (
    default =&gt; $p-&gt;{test_file_exts},
    (defined($p-&gt;{test_types}) ? %{$p-&gt;{test_types}} : ()),
  );

  for my $type (@types) {
    croak "$type not defined in test_types!"
      unless defined $test_types{ $type };
  }

  # we use local here because it ends up two method calls deep
  local $p-&gt;{test_file_exts} = [ map { ref $_ ? @$_ : $_ } @test_types{@types} ];
  $self-&gt;depends_on('code');

  # Protect others against our @INC changes
  local @INC = @INC;

  # Make sure we test the module in blib/
  unshift @INC, (File::Spec-&gt;catdir($p-&gt;{base_dir}, $self-&gt;blib, 'lib'),
                 File::Spec-&gt;catdir($p-&gt;{base_dir}, $self-&gt;blib, 'arch'));

  # Filter out nonsensical @INC entries - some versions of
  # Test::Harness will really explode the number of entries here
  @INC = grep {ref() || -d} @INC if @INC &gt; 100;

  $self-&gt;do_tests;
}

# Test::Harness dies on failure but TAP::Harness does not, so we must
# die if running under TAP::Harness
sub do_tests {
  my $self = shift;

  my $tests = $self-&gt;find_test_files;

  local $ENV{PERL_DL_NONLAZY} = 1;

  if(@$tests) {
    my $args = $self-&gt;tap_harness_args;
    if($self-&gt;use_tap_harness or ($args and %$args)) {
      my $aggregate = $self-&gt;run_tap_harness($tests);
      if ( $aggregate-&gt;has_errors ) {
        die "Errors in testing.  Cannot continue.\n";
      }
    }
    else {
      $self-&gt;run_test_harness($tests);
    }
  }
  else {
    $self-&gt;log_info("No tests defined.\n");
  }

  $self-&gt;run_visual_script;
}

sub run_tap_harness {
  my ($self, $tests) = @_;

  require TAP::Harness::Env;

  # TODO allow the test @INC to be set via our API?

  my $aggregate = TAP::Harness::Env-&gt;create({
    lib =&gt; [@INC],
    verbosity =&gt; $self-&gt;{properties}{verbose},
    switches  =&gt; [ $self-&gt;harness_switches ],
    %{ $self-&gt;tap_harness_args },
  })-&gt;runtests(@$tests);

  return $aggregate;
}

sub run_test_harness {
    my ($self, $tests) = @_;
    require Test::Harness;

    local $Test::Harness::verbose = $self-&gt;verbose || 0;
    local $Test::Harness::switches = join ' ', $self-&gt;harness_switches;

    Test::Harness::runtests(@$tests);
}

sub run_visual_script {
    my $self = shift;
    # This will get run and the user will see the output.  It doesn't
    # emit Test::Harness-style output.
    $self-&gt;run_perl_script('visual.pl', '-Mblib='.$self-&gt;blib)
        if -e 'visual.pl';
}

sub harness_switches {
    my $self = shift;
    my @res;
    push @res, qw(-w -d) if $self-&gt;{properties}{debugger};
    push @res, '-MDevel::Cover' if $self-&gt;{properties}{cover};
    return @res;
}

sub test_files {
  my $self = shift;
  my $p = $self-&gt;{properties};
  if (@_) {
    return $p-&gt;{test_files} = (@_ == 1 ? shift : [@_]);
  }
  return $self-&gt;find_test_files;
}

sub expand_test_dir {
  my ($self, $dir) = @_;
  my $exts = $self-&gt;{properties}{test_file_exts};

  return sort map { @{$self-&gt;rscan_dir($dir, qr{^[^.].*\Q$_\E$})} } @$exts
    if $self-&gt;recursive_test_files;

  return sort map { glob File::Spec-&gt;catfile($dir, "*$_") } @$exts;
}

sub ACTION_testdb {
  my ($self) = @_;
  local $self-&gt;{properties}{debugger} = 1;
  $self-&gt;depends_on('test');
}

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

  unless (Module::Metadata-&gt;find_module_by_name('Devel::Cover')) {
    warn("Cannot run testcover action unless Devel::Cover is installed.\n");
    return;
  }

  $self-&gt;add_to_cleanup('coverage', 'cover_db');
  $self-&gt;depends_on('code');

  # See whether any of the *.pm files have changed since last time
  # testcover was run.  If so, start over.
  if (-e 'cover_db') {
    my $pm_files = $self-&gt;rscan_dir
        (File::Spec-&gt;catdir($self-&gt;blib, 'lib'), $self-&gt;file_qr('\.pm$') );
    my $cover_files = $self-&gt;rscan_dir('cover_db', sub {-f $_ and not /\.html$/});

    $self-&gt;do_system(qw(cover -delete))
      unless $self-&gt;up_to_date($pm_files,         $cover_files)
          &amp;&amp; $self-&gt;up_to_date($self-&gt;test_files, $cover_files);
  }

  local $self-&gt;{properties}{cover} = 1;
  $self-&gt;depends_on('test');
  $self-&gt;do_system('cover');
}

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

  # All installable stuff gets created in blib/ .
  # Create blib/arch to keep blib.pm happy
  my $blib = $self-&gt;blib;
  $self-&gt;add_to_cleanup($blib);
  File::Path::mkpath( File::Spec-&gt;catdir($blib, 'arch') );

  if (my $split = $self-&gt;autosplit) {
    $self-&gt;autosplit_file($_, $blib) for ref($split) ? @$split : ($split);
  }

  foreach my $element (@{$self-&gt;build_elements}) {
    my $method = "process_${element}_files";
    $method = "process_files_by_extension" unless $self-&gt;can($method);
    $self-&gt;$method($element);
  }

  $self-&gt;depends_on('config_data');
}

sub ACTION_build {
  my $self = shift;
  $self-&gt;log_info("Building " . $self-&gt;dist_name . "\n");
  $self-&gt;depends_on('code');
  $self-&gt;depends_on('docs');
}

sub process_files_by_extension {
  my ($self, $ext) = @_;

  my $method = "find_${ext}_files";
  my $files = $self-&gt;can($method) ? $self-&gt;$method() : $self-&gt;_find_file_by_type($ext,  'lib');

  foreach my $file (sort keys %$files) {
    $self-&gt;copy_if_modified(from =&gt; $file, to =&gt; File::Spec-&gt;catfile($self-&gt;blib, $files-&gt;{$file}) );
  }
}

sub process_support_files {
  my $self = shift;
  my $p = $self-&gt;{properties};
  return unless $p-&gt;{c_source};

  my $files;
  if (ref($p-&gt;{c_source}) eq "ARRAY") {
      push @{$p-&gt;{include_dirs}}, @{$p-&gt;{c_source}};
      for my $path (@{$p-&gt;{c_source}}) {
          push @$files, @{ $self-&gt;rscan_dir($path, $self-&gt;file_qr('\.c(c|p|pp|xx|\+\+)?$')) };
      }
  } else {
      push @{$p-&gt;{include_dirs}}, $p-&gt;{c_source};
      $files = $self-&gt;rscan_dir($p-&gt;{c_source}, $self-&gt;file_qr('\.c(c|p|pp|xx|\+\+)?$'));
  }

  foreach my $file (@$files) {
      push @{$p-&gt;{objects}}, $self-&gt;compile_c($file);
  }
}

sub process_share_dir_files {
  my $self = shift;
  my $files = $self-&gt;_find_share_dir_files;
  return unless $files;

  # root for all File::ShareDir paths
  my $share_prefix = File::Spec-&gt;catdir($self-&gt;blib, qw/lib auto share/);

  # copy all share files to blib
  foreach my $file (sort keys %$files) {
    $self-&gt;copy_if_modified(
      from =&gt; $file, to =&gt; File::Spec-&gt;catfile( $share_prefix, $files-&gt;{$file} )
    );
  }
}

sub _find_share_dir_files {
  my $self = shift;
  my $share_dir = $self-&gt;share_dir;
  return unless $share_dir;

  my @file_map;
  if ( $share_dir-&gt;{dist} ) {
    my $prefix = "dist/".$self-&gt;dist_name;
    push @file_map, $self-&gt;_share_dir_map( $prefix, $share_dir-&gt;{dist} );
  }

  if ( $share_dir-&gt;{module} ) {
    for my $mod ( sort keys %{ $share_dir-&gt;{module} } ) {
      (my $altmod = $mod) =~ s{::}{-}g;
      my $prefix = "module/$altmod";
      push @file_map, $self-&gt;_share_dir_map($prefix, $share_dir-&gt;{module}{$mod});
    }
  }

  return { @file_map };
}

sub _share_dir_map {
  my ($self, $prefix, $list) = @_;
  my %files;
  for my $dir ( @$list ) {
    for my $f ( @{ $self-&gt;rscan_dir( $dir, sub {-f} )} ) {
      $f =~ s{\A.*?\Q$dir\E/}{};
      $files{"$dir/$f"} = "$prefix/$f";
    }
  }
  return %files;
}

sub process_PL_files {
  my ($self) = @_;
  my $files = $self-&gt;find_PL_files;

  foreach my $file (sort keys %$files) {
    my $to = $files-&gt;{$file};
    unless ($self-&gt;up_to_date( $file, $to )) {
      $self-&gt;run_perl_script($file, [], [@$to]) or die "$file failed";
      $self-&gt;add_to_cleanup(@$to);
    }
  }
}

sub process_xs_files {
  my $self = shift;
  return if $self-&gt;pureperl_only &amp;&amp; $self-&gt;allow_pureperl;
  my $files = $self-&gt;find_xs_files;
  croak 'Can\'t build xs files under --pureperl-only' if %$files &amp;&amp; $self-&gt;pureperl_only;
  foreach my $from (sort keys %$files) {
    my $to = $files-&gt;{$from};
    unless ($from eq $to) {
      $self-&gt;add_to_cleanup($to);
      $self-&gt;copy_if_modified( from =&gt; $from, to =&gt; $to );
    }
    $self-&gt;process_xs($to);
  }
}

sub process_pod_files { shift()-&gt;process_files_by_extension(shift()) }
sub process_pm_files  { shift()-&gt;process_files_by_extension(shift()) }

sub process_script_files {
  my $self = shift;
  my $files = $self-&gt;find_script_files;
  return unless keys %$files;

  my $script_dir = File::Spec-&gt;catdir($self-&gt;blib, 'script');
  File::Path::mkpath( $script_dir );

  foreach my $file (sort keys %$files) {
    my $result = $self-&gt;copy_if_modified($file, $script_dir, 'flatten') or next;
    $self-&gt;fix_shebang_line($result) unless $self-&gt;is_vmsish;
    $self-&gt;make_executable($result);
  }
}

sub find_PL_files {
  my $self = shift;
  if (my $files = $self-&gt;{properties}{PL_files}) {
    # 'PL_files' is given as a Unix file spec, so we localize_file_path().

    if (ref $files eq 'ARRAY') {
      return { map {$_, [/^(.*)\.PL$/]}
               map $self-&gt;localize_file_path($_),
               @$files };

    } elsif (ref $files eq 'HASH') {
      my %out;
      while (my ($file, $to) = each %$files) {
        $out{ $self-&gt;localize_file_path($file) } = [ map $self-&gt;localize_file_path($_),
                                                     ref $to ? @$to : ($to) ];
      }
      return \%out;

    } else {
      die "'PL_files' must be a hash reference or array reference";
    }
  }

  return unless -d 'lib';
  return {
    map {$_, [/^(.*)\.PL$/i ]}
    @{ $self-&gt;rscan_dir('lib', $self-&gt;file_qr('\.PL$')) }
  };
}

sub find_pm_files  { shift-&gt;_find_file_by_type('pm',  'lib') }
sub find_pod_files { shift-&gt;_find_file_by_type('pod', 'lib') }
sub find_xs_files  { shift-&gt;_find_file_by_type('xs',  'lib') }

sub find_script_files {
  my $self = shift;
  if (my $files = $self-&gt;script_files) {
    # Always given as a Unix file spec.  Values in the hash are
    # meaningless, but we preserve if present.
    return { map {$self-&gt;localize_file_path($_), $files-&gt;{$_}} keys %$files };
  }

  # No default location for script files
  return {};
}

sub find_test_files {
  my $self = shift;
  my $p = $self-&gt;{properties};

  if (my $files = $p-&gt;{test_files}) {
    $files = [sort keys %$files] if ref $files eq 'HASH';
    $files = [map { -d $_ ? $self-&gt;expand_test_dir($_) : $_ }
              map glob,
              $self-&gt;split_like_shell($files)];

    # Always given as a Unix file spec.
    return [ map $self-&gt;localize_file_path($_), @$files ];

  } else {
    # Find all possible tests in t/ or test.pl
    my @tests;
    push @tests, 'test.pl'                          if -e 'test.pl';
    push @tests, $self-&gt;expand_test_dir('t')        if -e 't' and -d _;
    return \@tests;
  }
}

sub _find_file_by_type {
  my ($self, $type, $dir) = @_;

  if (my $files = $self-&gt;{properties}{"${type}_files"}) {
    # Always given as a Unix file spec
    return { map $self-&gt;localize_file_path($_), %$files };
  }

  return {} unless -d $dir;
  return { map {$_, $_}
           map $self-&gt;localize_file_path($_),
           grep !/\.\#/,
           @{ $self-&gt;rscan_dir($dir, $self-&gt;file_qr("\\.$type\$")) } };
}

sub localize_file_path {
  my ($self, $path) = @_;
  return File::Spec-&gt;catfile( split m{/}, $path );
}

sub localize_dir_path {
  my ($self, $path) = @_;
  return File::Spec-&gt;catdir( split m{/}, $path );
}

sub fix_shebang_line { # Adapted from fixin() in ExtUtils::MM_Unix 1.35
  my ($self, @files) = @_;
  my $c = ref($self) ? $self-&gt;{config} : 'Module::Build::Config';

  my ($does_shbang) = $c-&gt;get('sharpbang') =~ /^\s*\#\!/;
  for my $file (@files) {
    open(my $FIXIN, '&lt;', $file) or die "Can't process '$file': $!";
    local $/ = "\n";
    chomp(my $line = &lt;$FIXIN&gt;);
    next unless $line =~ s/^\s*\#!\s*//;     # Not a shebang file.

    my ($cmd, $arg) = (split(' ', $line, 2), '');
    next unless $cmd =~ /perl/i;
    my $interpreter = $self-&gt;{properties}{perl};

    $self-&gt;log_verbose("Changing sharpbang in $file to $interpreter\n");
    my $shb = '';
    $shb .= $c-&gt;get('sharpbang')."$interpreter $arg\n" if $does_shbang;

    open(my $FIXOUT, '&gt;', "$file.new")
      or die "Can't create new $file: $!\n";

    # Print out the new #! line (or equivalent).
    local $\;
    undef $/; # Was localized above
    print $FIXOUT $shb, &lt;$FIXIN&gt;;
    close $FIXIN;
    close $FIXOUT;

    rename($file, "$file.bak")
      or die "Can't rename $file to $file.bak: $!";

    rename("$file.new", $file)
      or die "Can't rename $file.new to $file: $!";

    $self-&gt;delete_filetree("$file.bak")
      or $self-&gt;log_warn("Couldn't clean up $file.bak, leaving it there");

    $self-&gt;do_system($c-&gt;get('eunicefix'), $file) if $c-&gt;get('eunicefix') ne ':';
  }
}


sub ACTION_testpod {
  my $self = shift;
  $self-&gt;depends_on('docs');

  eval q{use Test::Pod 0.95; 1}
    or die "The 'testpod' action requires Test::Pod version 0.95";

  my @files = sort keys %{$self-&gt;_find_pods($self-&gt;libdoc_dirs)},
                   keys %{$self-&gt;_find_pods
                             ($self-&gt;bindoc_dirs,
                              exclude =&gt; [ $self-&gt;file_qr('\.bat$') ])}
    or die "Couldn't find any POD files to test\n";

  { package # hide from PAUSE
      Module::Build::PodTester;  # Don't want to pollute the main namespace
    Test::Pod-&gt;import( tests =&gt; scalar @files );
    pod_file_ok($_) foreach @files;
  }
}

sub ACTION_testpodcoverage {
  my $self = shift;

  $self-&gt;depends_on('docs');

  eval q{use Test::Pod::Coverage 1.00; 1}
    or die "The 'testpodcoverage' action requires ",
           "Test::Pod::Coverage version 1.00";

  # TODO this needs test coverage!

  # XXX work-around a bug in Test::Pod::Coverage previous to v1.09
  # Make sure we test the module in blib/
  local @INC = @INC;
  my $p = $self-&gt;{properties};
  unshift(@INC,
    # XXX any reason to include arch?
    File::Spec-&gt;catdir($p-&gt;{base_dir}, $self-&gt;blib, 'lib'),
    #File::Spec-&gt;catdir($p-&gt;{base_dir}, $self-&gt;blib, 'arch')
  );

  all_pod_coverage_ok();
}

sub ACTION_docs {
  my $self = shift;

  $self-&gt;depends_on('code');
  $self-&gt;depends_on('manpages', 'html');
}

# Given a file type, will return true if the file type would normally
# be installed when neither install-base nor prefix has been set.
# I.e. it will be true only if the path is set from Config.pm or
# set explicitly by the user via install-path.
sub _is_default_installable {
  my $self = shift;
  my $type = shift;
  return ( $self-&gt;install_destination($type) &amp;&amp;
           ( $self-&gt;install_path($type) ||
             $self-&gt;install_sets($self-&gt;installdirs)-&gt;{$type} )
         ) ? 1 : 0;
}

sub _is_ActivePerl {
#  return 0;
  my $self = shift;
  unless (exists($self-&gt;{_is_ActivePerl})) {
    $self-&gt;{_is_ActivePerl} = (eval { require ActivePerl::DocTools; } || 0);
  }
  return $self-&gt;{_is_ActivePerl};
}

sub _is_ActivePPM {
#  return 0;
  my $self = shift;
  unless (exists($self-&gt;{_is_ActivePPM})) {
    $self-&gt;{_is_ActivePPM} = (eval { require ActivePerl::PPM; } || 0);
  }
  return $self-&gt;{_is_ActivePPM};
}

sub ACTION_manpages {
  my $self = shift;

  return unless $self-&gt;_mb_feature('manpage_support');

  $self-&gt;depends_on('code');

  my %extra_manify_args = $self-&gt;{properties}{'extra_manify_args'} ? %{ $self-&gt;{properties}{'extra_manify_args'} } : ();

  foreach my $type ( qw(bin lib) ) {
    next unless ( $self-&gt;invoked_action eq 'manpages' || $self-&gt;_is_default_installable("${type}doc"));
    my $files = $self-&gt;_find_pods( $self-&gt;{properties}{"${type}doc_dirs"},
                                   exclude =&gt; [ $self-&gt;file_qr('\.bat$') ] );
    next unless %$files;

    my $sub = $self-&gt;can("manify_${type}_pods");
    $self-&gt;$sub( %extra_manify_args ) if defined( $sub );
  }
}

sub manify_bin_pods {
  my $self    = shift;
  my %podman_args = (section =&gt;  1, @_); # binaries go in section 1

  my $files   = $self-&gt;_find_pods( $self-&gt;{properties}{bindoc_dirs},
                                   exclude =&gt; [ $self-&gt;file_qr('\.bat$') ] );
  return unless keys %$files;

  my $mandir = File::Spec-&gt;catdir( $self-&gt;blib, 'bindoc' );
  File::Path::mkpath( $mandir, 0, oct(777) );

  require Pod::Man;
  foreach my $file (sort keys %$files) {
    # Pod::Simple based parsers only support one document per instance.
    # This is expected to change in a future version (Pod::Simple &gt; 3.03).
    my $parser  = Pod::Man-&gt;new( %podman_args );
    my $manpage = $self-&gt;man1page_name( $file ) . '.' .
                  $self-&gt;config( 'man1ext' );
    my $outfile = File::Spec-&gt;catfile($mandir, $manpage);
    next if $self-&gt;up_to_date( $file, $outfile );
    $self-&gt;log_verbose("Manifying $file -&gt; $outfile\n");
    eval { $parser-&gt;parse_from_file( $file, $outfile ); 1 }
      or $self-&gt;log_warn("Error creating '$outfile': $@\n");
    $files-&gt;{$file} = $outfile;
  }
}

sub manify_lib_pods {
  my $self    = shift;
  my %podman_args = (section =&gt; 3, @_); # libraries go in section 3

  my $files   = $self-&gt;_find_pods($self-&gt;{properties}{libdoc_dirs});
  return unless keys %$files;

  my $mandir = File::Spec-&gt;catdir( $self-&gt;blib, 'libdoc' );
  File::Path::mkpath( $mandir, 0, oct(777) );

  require Pod::Man;
  foreach my $file (sort keys %$files) {
    # Pod::Simple based parsers only support one document per instance.
    # This is expected to change in a future version (Pod::Simple &gt; 3.03).
    my $parser  = Pod::Man-&gt;new( %podman_args );
    my $manpage = $self-&gt;man3page_name( $files-&gt;{$file} ) . '.' .
                  $self-&gt;config( 'man3ext' );
    my $outfile = File::Spec-&gt;catfile( $mandir, $manpage);
    next if $self-&gt;up_to_date( $file, $outfile );
    $self-&gt;log_verbose("Manifying $file -&gt; $outfile\n");
    eval { $parser-&gt;parse_from_file( $file, $outfile ); 1 }
      or $self-&gt;log_warn("Error creating '$outfile': $@\n");
    $files-&gt;{$file} = $outfile;
  }
}

sub _find_pods {
  my ($self, $dirs, %args) = @_;
  my %files;
  foreach my $spec (@$dirs) {
    my $dir = $self-&gt;localize_dir_path($spec);
    next unless -e $dir;

    FILE: foreach my $file ( @{ $self-&gt;rscan_dir( $dir ) } ) {
      foreach my $regexp ( @{ $args{exclude} } ) {
        next FILE if $file =~ $regexp;
      }
      $file = $self-&gt;localize_file_path($file);
      $files{$file} = File::Spec-&gt;abs2rel($file, $dir) if $self-&gt;contains_pod( $file )
    }
  }
  return \%files;
}

sub contains_pod {
  my ($self, $file) = @_;
  return '' unless -T $file;  # Only look at text files

  open(my $fh, '&lt;', $file ) or die "Can't open $file: $!";
  while (my $line = &lt;$fh&gt;) {
    return 1 if $line =~ /^\=(?:head|pod|item)/;
  }

  return '';
}

sub ACTION_html {
  my $self = shift;

  return unless $self-&gt;_mb_feature('HTML_support');

  $self-&gt;depends_on('code');

  foreach my $type ( qw(bin lib) ) {
    next unless ( $self-&gt;invoked_action eq 'html' || $self-&gt;_is_default_installable("${type}html"));
    $self-&gt;htmlify_pods( $type );
  }
}

# 1) If it's an ActiveState perl install, we need to run
#    ActivePerl::DocTools-&gt;UpdateTOC;
# 2) Links to other modules are not being generated
sub htmlify_pods {
  my $self = shift;
  my $type = shift;
  my $htmldir = shift || File::Spec-&gt;catdir($self-&gt;blib, "${type}html");

  $self-&gt;add_to_cleanup('pod2htm*');

  my $pods = $self-&gt;_find_pods( $self-&gt;{properties}{"${type}doc_dirs"},
                                exclude =&gt; [ $self-&gt;file_qr('\.(?:bat|com|html)$') ] );
  return unless %$pods;  # nothing to do

  unless ( -d $htmldir ) {
    File::Path::mkpath($htmldir, 0, oct(755))
      or die "Couldn't mkdir $htmldir: $!";
  }

  my @rootdirs = ($type eq 'bin') ? qw(bin) :
      $self-&gt;installdirs eq 'core' ? qw(lib) : qw(site lib);
  my $podroot = $ENV{PERL_CORE}
              ? File::Basename::dirname($ENV{PERL_CORE})
              : $self-&gt;original_prefix('core');

  my $htmlroot = $self-&gt;install_sets('core')-&gt;{libhtml};
  my $podpath;
  unless (defined $self-&gt;args('html_links') and !$self-&gt;args('html_links')) {
    my @podpath = ( (map { File::Spec-&gt;abs2rel($_ ,$podroot) } grep { -d  }
                     ( $self-&gt;install_sets('core', 'lib'), # lib
                       $self-&gt;install_sets('core', 'bin'), # bin
                       $self-&gt;install_sets('site', 'lib'), # site/lib
                     ) ), File::Spec-&gt;rel2abs($self-&gt;blib) );

    $podpath = $ENV{PERL_CORE}
      ? File::Spec-&gt;catdir($podroot, 'lib')
        : join(":", map { tr,:\\,|/,; $_ } @podpath);
  }

  my $blibdir = join('/', File::Spec-&gt;splitdir(
    (File::Spec-&gt;splitpath(File::Spec-&gt;rel2abs($htmldir),1))[1]),''
  );

  my ($with_ActiveState, $htmltool);

  if ( $with_ActiveState = $self-&gt;_is_ActivePerl
    &amp;&amp; eval { require ActivePerl::DocTools::Pod; 1 }
  ) {
    my $tool_v = ActiveState::DocTools::Pod-&gt;VERSION;
    $htmltool = "ActiveState::DocTools::Pod";
    $htmltool .= " $tool_v" if $tool_v &amp;&amp; length $tool_v;
  }
  else {
      require Module::Build::PodParser;
      require Pod::Html;
    $htmltool = "Pod::Html " .  Pod::Html-&gt;VERSION;
  }
  $self-&gt;log_verbose("Converting Pod to HTML with $htmltool\n");

  my $errors = 0;

  POD:
  foreach my $pod ( sort keys %$pods ) {

    my ($name, $path) = File::Basename::fileparse($pods-&gt;{$pod},
      $self-&gt;file_qr('\.(?:pm|plx?|pod)$')
    );
    my @dirs = File::Spec-&gt;splitdir( File::Spec-&gt;canonpath( $path ) );
    pop( @dirs ) if scalar(@dirs) &amp;&amp; $dirs[-1] eq File::Spec-&gt;curdir;

    my $fulldir = File::Spec-&gt;catdir($htmldir, @rootdirs, @dirs);
    my $tmpfile = File::Spec-&gt;catfile($fulldir, "${name}.tmp");
    my $outfile = File::Spec-&gt;catfile($fulldir, "${name}.html");
    my $infile  = File::Spec-&gt;abs2rel($pod);

    next if $self-&gt;up_to_date($infile, $outfile);

    unless ( -d $fulldir ){
      File::Path::mkpath($fulldir, 0, oct(755))
        or die "Couldn't mkdir $fulldir: $!";
    }

    $self-&gt;log_verbose("HTMLifying $infile -&gt; $outfile\n");
    if ( $with_ActiveState ) {
      my $depth = @rootdirs + @dirs;
      my %opts = ( infile =&gt; $infile,
        outfile =&gt; $tmpfile,
        ( defined($podpath) ? (podpath =&gt; $podpath) : ()),
        podroot =&gt; $podroot,
        index =&gt; 1,
        depth =&gt; $depth,
      );
      eval {
        ActivePerl::DocTools::Pod::pod2html(map { ($_, $opts{$_}) } sort keys %opts);
        1;
      } or $self-&gt;log_warn("[$htmltool] pod2html (" .
        join(", ", map { "q{$_} =&gt; q{$opts{$_}}" } (sort keys %opts)) . ") failed: $@");
    } else {
      my $path2root = File::Spec-&gt;catdir((File::Spec-&gt;updir) x @dirs);
      open(my $fh, '&lt;', $infile) or die "Can't read $infile: $!";
      my $abstract = Module::Build::PodParser-&gt;new(fh =&gt; $fh)-&gt;get_abstract();

      my $title = join( '::', (@dirs, $name) );
      $title .= " - $abstract" if $abstract;

      my @opts = (
        "--title=$title",
        ( defined($podpath) ? "--podpath=$podpath" : ()),
        "--infile=$infile",
        "--outfile=$tmpfile",
        "--podroot=$podroot",
        ($path2root ? "--htmlroot=$path2root" : ()),
      );

      unless ( eval{Pod::Html-&gt;VERSION(1.12)} ) {
        push( @opts, ('--flush') ); # caching removed in 1.12
      }

      if ( eval{Pod::Html-&gt;VERSION(1.12)} ) {
        push( @opts, ('--header', '--backlink') );
      } elsif ( eval{Pod::Html-&gt;VERSION(1.03)} ) {
        push( @opts, ('--header', '--backlink=Back to Top') );
      }

      $self-&gt;log_verbose("P::H::pod2html @opts\n");
      {
        my $orig = Cwd::getcwd();
        eval { Pod::Html::pod2html(@opts); 1 }
          or $self-&gt;log_warn("[$htmltool] pod2html( " .
          join(", ", map { "q{$_}" } @opts) . ") failed: $@");
        chdir($orig);
      }
    }
    # We now have to cleanup the resulting html file
    if ( ! -r $tmpfile ) {
      $errors++;
      next POD;
    }
    open(my $fh, '&lt;', $tmpfile) or die "Can't read $tmpfile: $!";
    my $html = join('',&lt;$fh&gt;);
    close $fh;
    if (!$self-&gt;_is_ActivePerl) {
      # These fixups are already done by AP::DT:P:pod2html
      # The output from pod2html is NOT XHTML!
      # IE6+ will display content that is not valid for DOCTYPE
      $html =~ s#^&lt;!DOCTYPE .*?&gt;#&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;#im;
      $html =~ s#&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;#&lt;html&gt;#i;

      # IE6+ will not display local HTML files with strict
      # security without this comment
      $html =~ s#&lt;head&gt;#&lt;head&gt;\n&lt;!-- saved from url=(0017)http://localhost/ --&gt;#i;
    }
    # Fixup links that point to our temp blib
    $html =~ s/\Q$blibdir\E//g;

    open($fh, '&gt;', $outfile) or die "Can't write $outfile: $!";
    print $fh $html;
    close $fh;
    unlink($tmpfile);
  }

  return ! $errors;

}

# Adapted from ExtUtils::MM_Unix
sub man1page_name {
  my $self = shift;
  return File::Basename::basename( shift );
}

# Adapted from ExtUtils::MM_Unix and Pod::Man
# Depending on M::B's dependency policy, it might make more sense to refactor
# Pod::Man::begin_pod() to extract a name() methods, and use them...
#    -spurkis
sub man3page_name {
  my $self = shift;
  my ($vol, $dirs, $file) = File::Spec-&gt;splitpath( shift );
  my @dirs = File::Spec-&gt;splitdir( File::Spec-&gt;canonpath($dirs) );

  # Remove known exts from the base name
  $file =~ s/\.p(?:od|m|l)\z//i;

  return join( $self-&gt;manpage_separator, @dirs, $file );
}

sub manpage_separator {
  return '::';
}

# For systems that don't have 'diff' executable, should use Algorithm::Diff
sub ACTION_diff {
  my $self = shift;
  $self-&gt;depends_on('build');
  my $local_lib = File::Spec-&gt;rel2abs('lib');
  my @myINC = grep {$_ ne $local_lib} @INC;

  # The actual install destination might not be in @INC, so check there too.
  push @myINC, map $self-&gt;install_destination($_), qw(lib arch);

  my @flags = @{$self-&gt;{args}{ARGV}};
  @flags = $self-&gt;split_like_shell($self-&gt;{args}{flags} || '') unless @flags;

  my $installmap = $self-&gt;install_map;
  delete $installmap-&gt;{read};
  delete $installmap-&gt;{write};

  my $text_suffix = $self-&gt;file_qr('\.(pm|pod)$');

  foreach my $localdir (sort keys %$installmap) {
    my @localparts = File::Spec-&gt;splitdir($localdir);
    my $files = $self-&gt;rscan_dir($localdir, sub {-f});

    foreach my $file (@$files) {
      my @parts = File::Spec-&gt;splitdir($file);
      @parts = @parts[@localparts .. $#parts]; # Get rid of blib/lib or similar

      my $installed = Module::Metadata-&gt;find_module_by_name(
                        join('::', @parts), \@myINC );
      if (not $installed) {
        print "Only in lib: $file\n";
        next;
      }

      my $status = File::Compare::compare($installed, $file);
      next if $status == 0;  # Files are the same
      die "Can't compare $installed and $file: $!" if $status == -1;

      if ($file =~ $text_suffix) {
        $self-&gt;do_system('diff', @flags, $installed, $file);
      } else {
        print "Binary files $file and $installed differ\n";
      }
    }
  }
}

sub ACTION_pure_install {
  shift()-&gt;depends_on('install');
}

sub ACTION_install {
  my ($self) = @_;
  require ExtUtils::Install;
  $self-&gt;depends_on('build');
  # RT#63003 suggest that odd circumstances that we might wind up
  # in a different directory than we started, so wrap with _do_in_dir to
  # ensure we get back to where we started; hope this fixes it!
  $self-&gt;_do_in_dir( ".", sub {
    ExtUtils::Install::install(
      $self-&gt;install_map, $self-&gt;verbose, 0, $self-&gt;{args}{uninst}||0
    );
  });
  if ($self-&gt;_is_ActivePerl &amp;&amp; $self-&gt;{_completed_actions}{html}) {
    $self-&gt;log_info("Building ActivePerl Table of Contents\n");
    eval { ActivePerl::DocTools::WriteTOC(verbose =&gt; $self-&gt;verbose ? 1 : 0); 1; }
      or $self-&gt;log_warn("AP::DT:: WriteTOC() failed: $@");
  }
  if ($self-&gt;_is_ActivePPM) {
    # We touch 'lib/perllocal.pod'. There is an existing logic in subroutine _init_db()
    # of 'ActivePerl/PPM/InstallArea.pm' that says that if 'lib/perllocal.pod' has a 'date-last-touched'
    # greater than that of the PPM SQLite databases ('etc/ppm-perl-area.db' and/or
    # 'site/etc/ppm-site-area.db') then the PPM SQLite databases are rebuilt from scratch.

    # in the following line, 'perllocal.pod' this is *always* 'lib/perllocal.pod', never 'site/lib/perllocal.pod'
    my $F_perllocal = File::Spec-&gt;catfile($self-&gt;install_sets('core', 'lib'), 'perllocal.pod');
    my $dt_stamp = time;

    $self-&gt;log_info("For ActivePerl's PPM: touch '$F_perllocal'\n");

    open my $perllocal, "&gt;&gt;", $F_perllocal;
    close $perllocal;
    utime($dt_stamp, $dt_stamp, $F_perllocal);
  }
}

sub ACTION_fakeinstall {
  my ($self) = @_;
  require ExtUtils::Install;
  my $eui_version = ExtUtils::Install-&gt;VERSION;
  if ( $eui_version &lt; 1.32 ) {
    $self-&gt;log_warn(
      "The 'fakeinstall' action requires Extutils::Install 1.32 or later.\n"
      . "(You only have version $eui_version)."
    );
    return;
  }
  $self-&gt;depends_on('build');
  ExtUtils::Install::install($self-&gt;install_map, !$self-&gt;quiet, 1, $self-&gt;{args}{uninst}||0);
}

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

  die "You must have only.pm 0.25 or greater installed for this operation: $@\n"
    unless eval { require only; 'only'-&gt;VERSION(0.25); 1 };

  $self-&gt;depends_on('build');

  my %onlyargs = map {exists($self-&gt;{args}{$_}) ? ($_ =&gt; $self-&gt;{args}{$_}) : ()}
    qw(version versionlib);
  only::install::install(%onlyargs);
}

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

  # XXX include feature prerequisites as optional prereqs?

  my $info = $self-&gt;_enum_prereqs;
  if (! $info ) {
    $self-&gt;log_info( "No prerequisites detected\n" );
    return;
  }

  my $failures = $self-&gt;prereq_failures($info);
  if ( ! $failures ) {
    $self-&gt;log_info( "All prerequisites satisfied\n" );
    return;
  }

  my @install;
  foreach my $type (sort keys %$failures) {
    my $prereqs = $failures-&gt;{$type};
    if($type =~ m/^(?:\w+_)?requires$/) {
      push(@install, sort keys %$prereqs);
      next;
    }
    $self-&gt;log_info("Checking optional dependencies:\n");
    foreach my $module (sort keys %$prereqs) {
      push(@install, $module) if($self-&gt;y_n("Install $module?", 'y'));
    }
  }

  return unless @install;

  my ($command, @opts) = $self-&gt;split_like_shell($self-&gt;cpan_client);

  # relative command should be relative to our active Perl
  # so we need to locate that command
  if ( ! File::Spec-&gt;file_name_is_absolute( $command ) ) {
    # prefer site to vendor to core
    my @loc = ( 'site', 'vendor', '' );
    my @bindirs = File::Basename::dirname($self-&gt;perl);
    push @bindirs,
      map {
        ($self-&gt;config-&gt;{"install${_}bin"}, $self-&gt;config-&gt;{"install${_}script"})
      } @loc;
    for my $d ( @bindirs ) {
      my $abs_cmd = $self-&gt;find_command(File::Spec-&gt;catfile( $d, $command ));
      if ( defined $abs_cmd ) {
        $command = $abs_cmd;
        last;
      }
    }
  }

  $self-&gt;do_system($command, @opts, @install);
}

sub ACTION_clean {
  my ($self) = @_;
  $self-&gt;log_info("Cleaning up build files\n");
  foreach my $item (map glob($_), $self-&gt;cleanup) {
    $self-&gt;delete_filetree($item);
  }
}

sub ACTION_realclean {
  my ($self) = @_;
  $self-&gt;depends_on('clean');
  $self-&gt;log_info("Cleaning up configuration files\n");
  $self-&gt;delete_filetree(
    $self-&gt;config_dir, $self-&gt;mymetafile, $self-&gt;mymetafile2, $self-&gt;build_script
  );
}

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

  require Module::Build::PPMMaker;
  my $ppd = Module::Build::PPMMaker-&gt;new();
  my $file = $ppd-&gt;make_ppd(%{$self-&gt;{args}}, build =&gt; $self);
  $self-&gt;add_to_cleanup($file);
}

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

  $self-&gt;depends_on( 'build' );

  my $ppm = $self-&gt;ppm_name;
  $self-&gt;delete_filetree( $ppm );
  $self-&gt;log_info( "Creating $ppm\n" );
  $self-&gt;add_to_cleanup( $ppm, "$ppm.tar.gz" );

  my %types = ( # translate types/dirs to those expected by ppm
    lib     =&gt; 'lib',
    arch    =&gt; 'arch',
    bin     =&gt; 'bin',
    script  =&gt; 'script',
    bindoc  =&gt; 'man1',
    libdoc  =&gt; 'man3',
    binhtml =&gt; undef,
    libhtml =&gt; undef,
  );

  foreach my $type ($self-&gt;install_types) {
    next if exists( $types{$type} ) &amp;&amp; !defined( $types{$type} );

    my $dir = File::Spec-&gt;catdir( $self-&gt;blib, $type );
    next unless -e $dir;

    my $files = $self-&gt;rscan_dir( $dir );
    foreach my $file ( @$files ) {
      next unless -f $file;
      my $rel_file =
        File::Spec-&gt;abs2rel( File::Spec-&gt;rel2abs( $file ),
                             File::Spec-&gt;rel2abs( $dir  ) );
      my $to_file  =
        File::Spec-&gt;catfile( $ppm, 'blib',
                            exists( $types{$type} ) ? $types{$type} : $type,
                            $rel_file );
      $self-&gt;copy_if_modified( from =&gt; $file, to =&gt; $to_file );
    }
  }

  foreach my $type ( qw(bin lib) ) {
    $self-&gt;htmlify_pods( $type, File::Spec-&gt;catdir($ppm, 'blib', 'html') );
  }

  # create a tarball;
  # the directory tar'ed must be blib so we need to do a chdir first
  my $target = File::Spec-&gt;catfile( File::Spec-&gt;updir, $ppm );
  $self-&gt;_do_in_dir( $ppm, sub { $self-&gt;make_tarball( 'blib', $target ) } );

  $self-&gt;depends_on( 'ppd' );

  $self-&gt;delete_filetree( $ppm );
}

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

  # Need PAR::Dist
  if ( not eval { require PAR::Dist; PAR::Dist-&gt;VERSION(0.17) } ) {
    $self-&gt;log_warn(
      "In order to create .par distributions, you need to\n"
      . "install PAR::Dist first."
    );
    return();
  }

  $self-&gt;depends_on( 'build' );

  return PAR::Dist::blib_to_par(
    name =&gt; $self-&gt;dist_name,
    version =&gt; $self-&gt;dist_version,
  );
}

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

  # MUST dispatch() and not depends_ok() so we generate a clean distdir
  $self-&gt;dispatch('distdir');

  my $dist_dir = $self-&gt;dist_dir;

  $self-&gt;make_tarball($dist_dir);
  $self-&gt;delete_filetree($dist_dir);
}

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

  $self-&gt;_check_manifest_skip unless $self-&gt;invoked_action eq 'distclean';

  require ExtUtils::Manifest;
  local $^W; # ExtUtils::Manifest is not warnings clean.
  my ($missing, $extra) = ExtUtils::Manifest::fullcheck();

  return unless @$missing || @$extra;

  my $msg = "MANIFEST appears to be out of sync with the distribution\n";
  if ( $self-&gt;invoked_action eq 'distcheck' ) {
    die $msg;
  } else {
    warn $msg;
  }
}

sub _check_mymeta_skip {
  my $self = shift;
  my $maniskip = shift || 'MANIFEST.SKIP';

  require ExtUtils::Manifest;
  local $^W; # ExtUtils::Manifest is not warnings clean.

  # older ExtUtils::Manifest had a private _maniskip
  my $skip_factory = ExtUtils::Manifest-&gt;can('maniskip')
                  || ExtUtils::Manifest-&gt;can('_maniskip');

  my $mymetafile = $self-&gt;mymetafile;
  # we can't check it, just add it anyway to be safe
  for my $file ( $self-&gt;mymetafile, $self-&gt;mymetafile2 ) {
    unless ( $skip_factory &amp;&amp; $skip_factory-&gt;($maniskip)-&gt;($file) ) {
      $self-&gt;log_warn("File '$maniskip' does not include '$file'. Adding it now.\n");
      my $safe = quotemeta($file);
      $self-&gt;_append_maniskip("^$safe\$", $maniskip);
    }
  }
}

sub _add_to_manifest {
  my ($self, $manifest, $lines) = @_;
  $lines = [$lines] unless ref $lines;

  my $existing_files = $self-&gt;_read_manifest($manifest);
  return unless defined( $existing_files );

  @$lines = grep {!exists $existing_files-&gt;{$_}} @$lines
    or return;

  my $mode = (stat $manifest)[2];
  chmod($mode | oct(222), $manifest) or die "Can't make $manifest writable: $!";

  open(my $fh, '&lt;', $manifest) or die "Can't read $manifest: $!";
  my $last_line = (&lt;$fh&gt;)[-1] || "\n";
  my $has_newline = $last_line =~ /\n$/;
  close $fh;

  open($fh, '&gt;&gt;', $manifest) or die "Can't write to $manifest: $!";
  print $fh "\n" unless $has_newline;
  print $fh map "$_\n", @$lines;
  close $fh;
  chmod($mode, $manifest);

  $self-&gt;log_verbose(map "Added to $manifest: $_\n", @$lines);
}

sub _sign_dir {
  my ($self, $dir) = @_;

  unless (eval { require Module::Signature; 1 }) {
    $self-&gt;log_warn("Couldn't load Module::Signature for 'distsign' action:\n $@\n");
    return;
  }

  # Add SIGNATURE to the MANIFEST
  {
    my $manifest = File::Spec-&gt;catfile($dir, 'MANIFEST');
    die "Signing a distribution requires a MANIFEST file" unless -e $manifest;
    $self-&gt;_add_to_manifest($manifest, "SIGNATURE    Added here by Module::Build");
  }

  # Would be nice if Module::Signature took a directory argument.

  $self-&gt;_do_in_dir($dir, sub {local $Module::Signature::Quiet = 1; Module::Signature::sign()});
}

sub _do_in_dir {
  my ($self, $dir, $do) = @_;

  my $start_dir = File::Spec-&gt;rel2abs($self-&gt;cwd);
  chdir $dir or die "Can't chdir() to $dir: $!";
  eval {$do-&gt;()};
  my @err = $@ ? ($@) : ();
  chdir $start_dir or push @err, "Can't chdir() back to $start_dir: $!";
  die join "\n", @err if @err;
}

sub ACTION_distsign {
  my ($self) = @_;
  {
    local $self-&gt;{properties}{sign} = 0;  # We'll sign it ourselves
    $self-&gt;depends_on('distdir') unless -d $self-&gt;dist_dir;
  }
  $self-&gt;_sign_dir($self-&gt;dist_dir);
}

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

  require ExtUtils::Manifest;
  local $^W; # ExtUtils::Manifest is not warnings clean.
  ExtUtils::Manifest::skipcheck();
}

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

  $self-&gt;depends_on('realclean');
  $self-&gt;depends_on('distcheck');
}

sub do_create_makefile_pl {
  my $self = shift;
  require Module::Build::Compat;
  $self-&gt;log_info("Creating Makefile.PL\n");
  eval { Module::Build::Compat-&gt;create_makefile_pl($self-&gt;create_makefile_pl, $self, @_) };
  if ( $@ ) {
    1 while unlink 'Makefile.PL';
    die "$@\n";
  }
  $self-&gt;_add_to_manifest('MANIFEST', 'Makefile.PL');
}

sub do_create_license {
  my $self = shift;
  $self-&gt;log_info("Creating LICENSE file\n");

  if (  ! $self-&gt;_mb_feature('license_creation') ) {
    $self-&gt;_warn_mb_feature_deps('license_creation');
    die "Aborting.\n";
  }

  my $l = $self-&gt;license
    or die "Can't create LICENSE file: No license specified\n";

  my $license = $self-&gt;_software_license_object
    or die &lt;&lt; "HERE";
Can't create LICENSE file: '$l' is not a valid license key
or Software::License subclass;
HERE

  $self-&gt;delete_filetree('LICENSE');

  open(my $fh, '&gt;', 'LICENSE')
    or die "Can't write LICENSE file: $!";
  print $fh $license-&gt;fulltext;
  close $fh;

  $self-&gt;_add_to_manifest('MANIFEST', 'LICENSE');
}

sub do_create_readme {
  my $self = shift;
  $self-&gt;delete_filetree('README');

  my $docfile = $self-&gt;_main_docfile;
  unless ( $docfile ) {
    $self-&gt;log_warn(&lt;&lt;EOF);
Cannot create README: can't determine which file contains documentation;
Must supply either 'dist_version_from', or 'module_name' parameter.
EOF
    return;
  }

  # work around some odd Pod::Readme-&gt;new() failures in test reports by
  # confirming that new() is available
  if ( eval {require Pod::Readme; Pod::Readme-&gt;can('new') } ) {
    $self-&gt;log_info("Creating README using Pod::Readme\n");

    my $parser = Pod::Readme-&gt;new;
    $parser-&gt;parse_from_file($docfile, 'README', @_);

  } elsif ( eval {require Pod::Text; 1} ) {
    $self-&gt;log_info("Creating README using Pod::Text\n");

    if ( open(my $fh, '&gt;', 'README') ) {
      local $^W = 0;
      no strict "refs";

      # work around bug in Pod::Text 3.01, which expects
      # Pod::Simple::parse_file to take input and output filehandles
      # when it actually only takes an input filehandle

      my $old_parse_file;
      $old_parse_file = \&amp;{"Pod::Simple::parse_file"}
        and
      local *{"Pod::Simple::parse_file"} = sub {
        my $self = shift;
        $self-&gt;output_fh($_[1]) if $_[1];
        $self-&gt;$old_parse_file($_[0]);
      }
        if $Pod::Text::VERSION
          == 3.01; # Split line to avoid evil version-finder

      Pod::Text::pod2text( $docfile, $fh );

      close $fh;
    } else {
      $self-&gt;log_warn(
        "Cannot create 'README' file: Can't open file for writing\n" );
      return;
    }

  } else {
    $self-&gt;log_warn("Can't load Pod::Readme or Pod::Text to create README\n");
    return;
  }

  $self-&gt;_add_to_manifest('MANIFEST', 'README');
}

sub _main_docfile {
  my $self = shift;
  if ( my $pm_file = $self-&gt;dist_version_from ) {
    (my $pod_file = $pm_file) =~ s/.pm$/.pod/;
    return (-e $pod_file ? $pod_file : $pm_file);
  } else {
    return undef;
  }
}

sub do_create_bundle_inc {
  my $self = shift;
  my $dist_inc = File::Spec-&gt;catdir( $self-&gt;dist_dir, 'inc' );
  require inc::latest;
  inc::latest-&gt;write($dist_inc, @{$self-&gt;bundle_inc_preload});
  inc::latest-&gt;bundle_module($_, $dist_inc) for @{$self-&gt;bundle_inc};
  return 1;
}

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

  if ( @{$self-&gt;bundle_inc} &amp;&amp; ! $self-&gt;_mb_feature('inc_bundling_support') ) {
    $self-&gt;_warn_mb_feature_deps('inc_bundling_support');
    die "Aborting.\n";
  }

  $self-&gt;depends_on('distmeta');

  my $dist_files = $self-&gt;_read_manifest('MANIFEST')
    or die "Can't create distdir without a MANIFEST file - run 'manifest' action first.\n";
  delete $dist_files-&gt;{SIGNATURE};  # Don't copy, create a fresh one
  die "No files found in MANIFEST - try running 'manifest' action?\n"
    unless ($dist_files and keys %$dist_files);
  my $metafile = $self-&gt;metafile;
  $self-&gt;log_warn("*** Did you forget to add $metafile to the MANIFEST?\n")
    unless exists $dist_files-&gt;{$metafile};

  my $dist_dir = $self-&gt;dist_dir;
  $self-&gt;delete_filetree($dist_dir);
  $self-&gt;log_info("Creating $dist_dir\n");
  $self-&gt;add_to_cleanup($dist_dir);

  foreach my $file (sort keys %$dist_files) {
    next if $file =~ m{^MYMETA\.}; # Double check that we skip MYMETA.*
    my $new = $self-&gt;copy_if_modified(from =&gt; $file, to_dir =&gt; $dist_dir, verbose =&gt; 0);
  }

  $self-&gt;do_create_bundle_inc if @{$self-&gt;bundle_inc};

  $self-&gt;_sign_dir($dist_dir) if $self-&gt;{properties}{sign};
}

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

  $self-&gt;depends_on('distdir');

  $self-&gt;_do_in_dir
    ( $self-&gt;dist_dir,
      sub {
        local $ENV{AUTHOR_TESTING}  = 1;
        local $ENV{RELEASE_TESTING} = 1;

        # XXX could be different names for scripts

        $self-&gt;run_perl_script('Build.PL') # XXX Should this be run w/ --nouse-rcfile
          or die "Error executing 'Build.PL' in dist directory: $!";
        $self-&gt;run_perl_script($self-&gt;build_script)
          or die "Error executing $self-&gt;build_script in dist directory: $!";
        $self-&gt;run_perl_script($self-&gt;build_script, [], ['test'])
          or die "Error executing 'Build test' in dist directory";
      });
}

sub ACTION_distinstall {
  my ($self, @args) = @_;

  $self-&gt;depends_on('distdir');

  $self-&gt;_do_in_dir ( $self-&gt;dist_dir,
    sub {
      $self-&gt;run_perl_script('Build.PL')
        or die "Error executing 'Build.PL' in dist directory: $!";
      $self-&gt;run_perl_script($self-&gt;build_script)
        or die "Error executing $self-&gt;build_script in dist directory: $!";
      $self-&gt;run_perl_script($self-&gt;build_script, [], ['install'])
        or die "Error executing 'Build install' in dist directory";
    }
  );
}

=begin private

  my $has_include = $build-&gt;_eumanifest_has_include;

Returns true if the installed version of ExtUtils::Manifest supports
#include and #include_default directives.  False otherwise.

=end private

=cut

# #!include and #!include_default were added in 1.50
sub _eumanifest_has_include {
    my $self = shift;

    require ExtUtils::Manifest;
    return eval { ExtUtils::Manifest-&gt;VERSION(1.50); 1 };
}


=begin private

  my $maniskip_file = $build-&gt;_default_maniskip;

Returns the location of the installed MANIFEST.SKIP file used by
default.

=end private

=cut

sub _default_maniskip {
    my $self = shift;

    my $default_maniskip;
    for my $dir (@INC) {
        $default_maniskip = File::Spec-&gt;catfile($dir, "ExtUtils", "MANIFEST.SKIP");
        last if -r $default_maniskip;
    }

    return $default_maniskip;
}


=begin private

  my $content = $build-&gt;_slurp($file);

Reads $file and returns the $content.

=end private

=cut

sub _slurp {
    my $self = shift;
    my $file = shift;
    my $mode = shift || "";
    open my $fh, "&lt;$mode", $file or croak "Can't open $file for reading: $!";
    local $/;
    return &lt;$fh&gt;;
}

sub _spew {
    my $self = shift;
    my $file = shift;
    my $content = shift || "";
    my $mode = shift || "";
    open my $fh, "&gt;$mode", $file or croak "Can't open $file for writing: $!";
    print {$fh} $content;
    close $fh;
}

sub _case_tolerant {
  my $self = shift;
  if ( ref $self ) {
    $self-&gt;{_case_tolerant} = File::Spec-&gt;case_tolerant
      unless defined($self-&gt;{_case_tolerant});
    return $self-&gt;{_case_tolerant};
  }
  else {
    return File::Spec-&gt;case_tolerant;
  }
}

sub _append_maniskip {
  my $self = shift;
  my $skip = shift;
  my $file = shift || 'MANIFEST.SKIP';
  return unless defined $skip &amp;&amp; length $skip;
  open(my $fh, '&gt;&gt;', $file)
    or die "Can't open $file: $!";

  print $fh "$skip\n";
  close $fh;
}

sub _write_default_maniskip {
  my $self = shift;
  my $file = shift || 'MANIFEST.SKIP';
  open(my $fh, '&gt;', $file)
    or die "Can't open $file: $!";

  my $content = $self-&gt;_eumanifest_has_include ? "#!include_default\n"
                                               : $self-&gt;_slurp( $self-&gt;_default_maniskip );

  $content .= &lt;&lt;'EOF';
# Avoid configuration metadata file
^MYMETA\.

# Avoid Module::Build generated and utility files.
\bBuild$
\bBuild.bat$
\b_build
\bBuild.COM$
\bBUILD.COM$
\bbuild.com$
^MANIFEST\.SKIP

# Avoid archives of this distribution
EOF

  # Skip, for example, 'Module-Build-0.27.tar.gz'
  $content .= '\b'.$self-&gt;dist_name.'-[\d\.\_]+'."\n";

  print $fh $content;
  
  close $fh;

  return;
}

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

  my $maniskip = 'MANIFEST.SKIP';

  if ( ! -e $maniskip ) {
    $self-&gt;log_warn("File '$maniskip' does not exist: Creating a temporary '$maniskip'\n");
    $self-&gt;_write_default_maniskip($maniskip);
    $self-&gt;_unlink_on_exit($maniskip);
  }
  else {
    # MYMETA must not be added to MANIFEST, so always confirm the skip
    $self-&gt;_check_mymeta_skip( $maniskip );
  }

  return;
}

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

  $self-&gt;_check_manifest_skip;

  require ExtUtils::Manifest;  # ExtUtils::Manifest is not warnings clean.
  local ($^W, $ExtUtils::Manifest::Quiet) = (0,1);
  ExtUtils::Manifest::mkmanifest();
}

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

  if ( -e 'MANIFEST.SKIP' ) {
    $self-&gt;log_warn("MANIFEST.SKIP already exists.\n");
    return 0;
  }
  $self-&gt;log_info("Creating a new MANIFEST.SKIP file\n");
  return $self-&gt;_write_default_maniskip;
  return -e 'MANIFEST.SKIP'
}

# Case insensitive regex for files
sub file_qr {
    return shift-&gt;{_case_tolerant} ? qr($_[0])i : qr($_[0]);
}

sub dist_dir {
  my ($self) = @_;
  my $dir = join "-", $self-&gt;dist_name, $self-&gt;dist_version;
  $dir .= "-" . $self-&gt;dist_suffix if $self-&gt;dist_suffix;
  return $dir;
}

sub ppm_name {
  my $self = shift;
  return 'PPM-' . $self-&gt;dist_dir;
}

sub _files_in {
  my ($self, $dir) = @_;
  return unless -d $dir;

  local *DH;
  opendir DH, $dir or die "Can't read directory $dir: $!";

  my @files;
  while (defined (my $file = readdir DH)) {
    my $full_path = File::Spec-&gt;catfile($dir, $file);
    next if -d $full_path;
    push @files, $full_path;
  }
  return @files;
}

sub share_dir {
  my $self = shift;
  my $p = $self-&gt;{properties};

  $p-&gt;{share_dir} = shift if @_;

  # Always coerce to proper hash form
  if    ( ! defined $p-&gt;{share_dir} ) {
    return;
  }
  elsif ( ! ref $p-&gt;{share_dir}  ) {
    # scalar -- treat as a single 'dist' directory
    $p-&gt;{share_dir} = { dist =&gt; [ $p-&gt;{share_dir} ] };
  }
  elsif ( ref $p-&gt;{share_dir} eq 'ARRAY' ) {
    # array -- treat as a list of 'dist' directories
    $p-&gt;{share_dir} = { dist =&gt; $p-&gt;{share_dir} };
  }
  elsif ( ref $p-&gt;{share_dir} eq 'HASH' ) {
    # hash -- check structure
    my $share_dir = $p-&gt;{share_dir};
    # check dist key
    if ( defined $share_dir-&gt;{dist} ) {
      if ( ! ref $share_dir-&gt;{dist} ) {
        # scalar, so upgrade to arrayref
        $share_dir-&gt;{dist} = [ $share_dir-&gt;{dist} ];
      }
      elsif ( ref $share_dir-&gt;{dist} ne 'ARRAY' ) {
        die "'dist' key in 'share_dir' must be scalar or arrayref";
      }
    }
    # check module key
    if ( defined $share_dir-&gt;{module} ) {
      my $mod_hash = $share_dir-&gt;{module};
      if ( ref $mod_hash eq 'HASH' ) {
        for my $k ( sort keys %$mod_hash ) {
          if ( ! ref $mod_hash-&gt;{$k} ) {
            $mod_hash-&gt;{$k} = [ $mod_hash-&gt;{$k} ];
          }
          elsif( ref $mod_hash-&gt;{$k} ne 'ARRAY' ) {
            die "modules in 'module' key of 'share_dir' must be scalar or arrayref";
          }
        }
      }
      else {
          die "'module' key in 'share_dir' must be hashref";
      }
    }
  }
  else {
    die "'share_dir' must be hashref, arrayref or string";
  }

  return $p-&gt;{share_dir};
}

sub script_files {
  my $self = shift;

  for ($self-&gt;{properties}{script_files}) {
    $_ = shift if @_;
    next unless $_;

    # Always coerce into a hash
    return $_ if ref $_ eq 'HASH';
    return $_ = { map {$_,1} @$_ } if ref $_ eq 'ARRAY';

    die "'script_files' must be a hashref, arrayref, or string" if ref();

    return $_ = { map {$_,1} $self-&gt;_files_in( $_ ) } if -d $_;
    return $_ = {$_ =&gt; 1};
  }

  my %pl_files = map {
    File::Spec-&gt;canonpath( $_ ) =&gt; 1
  } keys %{ $self-&gt;PL_files || {} };

  my @bin_files = $self-&gt;_files_in('bin');

  my %bin_map = map {
    $_ =&gt; File::Spec-&gt;canonpath( $_ )
  } @bin_files;

  return $_ = { map {$_ =&gt; 1} grep !$pl_files{$bin_map{$_}}, @bin_files };
}
BEGIN { *scripts = \&amp;script_files; }

{
  my %licenses = (
    perl         =&gt; 'Perl_5',
    apache       =&gt; 'Apache_2_0',
    apache_1_1   =&gt; 'Apache_1_1',
    artistic     =&gt; 'Artistic_1',
    artistic_2   =&gt; 'Artistic_2',
    lgpl         =&gt; 'LGPL_2_1',
    lgpl2        =&gt; 'LGPL_2_1',
    lgpl3        =&gt; 'LGPL_3_0',
    bsd          =&gt; 'BSD',
    gpl          =&gt; 'GPL_1',
    gpl2         =&gt; 'GPL_2',
    gpl3         =&gt; 'GPL_3',
    mit          =&gt; 'MIT',
    mozilla      =&gt; 'Mozilla_1_1',
    restrictive  =&gt; 'Restricted',
    open_source  =&gt; undef,
    unrestricted =&gt; undef,
    unknown      =&gt; undef,
  );

  # TODO - would be nice to not have these here, since they're more
  # properly stored only in Software::License
  my %license_urls = (
    perl         =&gt; 'http://dev.perl.org/licenses/',
    apache       =&gt; 'http://apache.org/licenses/LICENSE-2.0',
    apache_1_1   =&gt; 'http://apache.org/licenses/LICENSE-1.1',
    artistic     =&gt; 'http://opensource.org/licenses/artistic-license.php',
    artistic_2   =&gt; 'http://opensource.org/licenses/artistic-license-2.0.php',
    lgpl         =&gt; 'http://opensource.org/licenses/lgpl-license.php',
    lgpl2        =&gt; 'http://opensource.org/licenses/lgpl-2.1.php',
    lgpl3        =&gt; 'http://opensource.org/licenses/lgpl-3.0.html',
    bsd          =&gt; 'http://opensource.org/licenses/bsd-license.php',
    gpl          =&gt; 'http://opensource.org/licenses/gpl-license.php',
    gpl2         =&gt; 'http://opensource.org/licenses/gpl-2.0.php',
    gpl3         =&gt; 'http://opensource.org/licenses/gpl-3.0.html',
    mit          =&gt; 'http://opensource.org/licenses/mit-license.php',
    mozilla      =&gt; 'http://opensource.org/licenses/mozilla1.1.php',
    restrictive  =&gt; undef,
    open_source  =&gt; undef,
    unrestricted =&gt; undef,
    unknown      =&gt; undef,
  );
  sub valid_licenses {
    return \%licenses;
  }
  sub _license_url {
    return $license_urls{$_[1]};
  }
}

sub _software_license_class {
  my ($self, $license) = @_;
  if ($self-&gt;valid_licenses-&gt;{$license} &amp;&amp; eval { require Software::LicenseUtils; Software::LicenseUtils-&gt;VERSION(0.103009) }) {
    my @classes = Software::LicenseUtils-&gt;guess_license_from_meta_key($license, 1);
    if (@classes == 1) {
      eval "require $classes[0]";
      return $classes[0];
    }
  }
  LICENSE: for my $l ( $self-&gt;valid_licenses-&gt;{ $license }, $license ) {
    next unless defined $l;
    my $trial = "Software::License::" . $l;
    if ( eval "require Software::License; Software::License-&gt;VERSION(0.014); require $trial; 1" ) {
      return $trial;
    }
  }
  return;
}

# use mapping or license name directly
sub _software_license_object {
  my ($self) = @_;
  return unless defined( my $license = $self-&gt;license );

  my $class = $self-&gt;_software_license_class($license) or return;

  # Software::License requires a 'holder' argument
  my $author = join( " &amp; ", @{ $self-&gt;dist_author }) || 'unknown';
  my $sl = eval { $class-&gt;new({holder=&gt;$author}) };
  if ( $@ ) {
    $self-&gt;log_warn( "Error getting '$class' object: $@" );
  }

  return $sl;
}

sub _hash_merge {
  my ($self, $h, $k, $v) = @_;
  if (ref $h-&gt;{$k} eq 'ARRAY') {
    push @{$h-&gt;{$k}}, ref $v ? @$v : $v;
  } elsif (ref $h-&gt;{$k} eq 'HASH') {
    $h-&gt;{$k}{$_} = $v-&gt;{$_} foreach keys %$v;
  } else {
    $h-&gt;{$k} = $v;
  }
}

sub ACTION_distmeta {
  my ($self) = @_;
  $self-&gt;do_create_makefile_pl if $self-&gt;create_makefile_pl;
  $self-&gt;do_create_readme if $self-&gt;create_readme;
  $self-&gt;do_create_license if $self-&gt;create_license;
  $self-&gt;do_create_metafile;
}

sub do_create_metafile {
  my $self = shift;
  return if $self-&gt;{wrote_metadata};

  my $p = $self-&gt;{properties};

  unless ($p-&gt;{license}) {
    $self-&gt;log_warn("No license specified, setting license = 'unknown'\n");
    $p-&gt;{license} = 'unknown';
  }

  my @metafiles = ( $self-&gt;metafile, $self-&gt;metafile2 );
  # If we're in the distdir, the metafile may exist and be non-writable.
  $self-&gt;delete_filetree($_) for @metafiles;

  # Since we're building ourself, we have to do some special stuff
  # here: the ConfigData module is found in blib/lib.
  local @INC = @INC;
  if (($self-&gt;module_name || '') eq 'Module::Build') {
    $self-&gt;depends_on('config_data');
    push @INC, File::Spec-&gt;catdir($self-&gt;blib, 'lib');
  }

  my $meta_obj = $self-&gt;_get_meta_object(
    quiet =&gt; 1, fatal =&gt; 1, auto =&gt; 1
  );
  my @created = $self-&gt;_write_meta_files( $meta_obj, 'META' );
  if ( @created ) {
    $self-&gt;{wrote_metadata} = 1;
    $self-&gt;_add_to_manifest('MANIFEST', $_) for @created;
  }
  return 1;
}

sub _write_meta_files {
  my $self = shift;
  my ($meta, $file) = @_;
  $file =~ s{\.(?:yml|json)$}{};

  my @created;
  push @created, "$file\.yml"
    if $meta &amp;&amp; $meta-&gt;save( "$file\.yml", {version =&gt; "1.4"} );
  push @created, "$file\.json"
    if $meta &amp;&amp; $meta-&gt;save( "$file\.json" );

  if ( @created ) {
    $self-&gt;log_info("Created " . join(" and ", @created) . "\n");
  }
  return @created;
}

sub _get_meta_object {
  my $self = shift;
  my %args = @_;
  return unless $self-&gt;try_require("CPAN::Meta", "2.142060");

  my $meta;
  eval {
    my $data = $self-&gt;get_metadata(
      fatal =&gt; $args{fatal},
      auto =&gt; $args{auto},
    );
    $data-&gt;{dynamic_config} = $args{dynamic} if defined $args{dynamic};
    $meta = CPAN::Meta-&gt;create($data);
  };
  if ($@ &amp;&amp; ! $args{quiet}) {
    $self-&gt;log_warn(
      "Could not get valid metadata. Error is: $@\n"
    );
  }

  return $meta;
}

sub read_metafile {
  my $self = shift;
  my ($metafile) = @_;

  return unless $self-&gt;try_require("CPAN::Meta", "2.110420");
  my $meta = CPAN::Meta-&gt;load_file($metafile);
  return $meta-&gt;as_struct( {version =&gt; "2.0"} );
}

sub normalize_version {
  my ($self, $version) = @_;
  $version = 0 unless defined $version and length $version;

  if ( $version =~ /[=&lt;&gt;!,]/ ) { # logic, not just version
    # take as is without modification
  }
  elsif ( ref $version eq 'version') { # version objects
    $version = $version-&gt;is_qv ? $version-&gt;normal : $version-&gt;stringify;
  }
  elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots
    # normalize string tuples without "v": "1.2.3" -&gt; "v1.2.3"
    $version = "v$version";
  }
  else {
    # leave alone
  }
  return $version;
}

my %prereq_map = (
  requires =&gt; [ qw/runtime requires/],
  configure_requires =&gt; [qw/configure requires/],
  build_requires =&gt; [ qw/build requires/ ],
  test_requires =&gt; [ qw/test requires/ ],
  test_recommends =&gt; [ qw/test recommends/ ],
  recommends =&gt; [ qw/runtime recommends/ ],
  conflicts =&gt; [ qw/runtime conflicts/ ],
);

sub _normalize_prereqs {
  my ($self) = @_;
  my $p = $self-&gt;{properties};

  # copy prereq data structures so we can modify them before writing to META
  my %prereq_types;
  for my $type ( 'configure_requires', @{$self-&gt;prereq_action_types} ) {
    if (exists $p-&gt;{$type} and keys %{ $p-&gt;{$type} }) {
      my ($phase, $relation) = @{ $prereq_map{$type} };
      for my $mod ( keys %{ $p-&gt;{$type} } ) {
        $prereq_types{$phase}{$relation}{$mod} = $self-&gt;normalize_version($p-&gt;{$type}{$mod});
      }
    }
  }
  return \%prereq_types;
}

sub _get_license {
  my $self = shift;

  my $license = $self-&gt;license;
  my ($meta_license, $meta_license_url);

  my $valid_licenses = $self-&gt;valid_licenses();
  if ( my $sl = $self-&gt;_software_license_object ) {
    $meta_license = $sl-&gt;meta2_name;
    $meta_license_url = $sl-&gt;url;
  }
  elsif ( exists $valid_licenses-&gt;{$license} ) {
    $meta_license = $valid_licenses-&gt;{$license} ? lc $valid_licenses-&gt;{$license} : $license;
    $meta_license_url = $self-&gt;_license_url( $license );
  }
  else {
    $self-&gt;log_warn( "Can not determine license type for '" . $self-&gt;license
      . "'\nSetting META license field to 'unknown'.\n");
    $meta_license = 'unknown';
  }
  return ($meta_license, $meta_license_url);
}

sub get_metadata {
  my ($self, %args) = @_;

  my $fatal = $args{fatal} || 0;
  my $p = $self-&gt;{properties};

  $self-&gt;auto_config_requires if $args{auto};

  # validate required fields
  foreach my $f (qw(dist_name dist_version dist_author dist_abstract license)) {
    my $field = $self-&gt;$f();
    unless ( defined $field and length $field ) {
      my $err = "ERROR: Missing required field '$f' for metafile\n";
      if ( $fatal ) {
        die $err;
      }
      else {
        $self-&gt;log_warn($err);
      }
    }
  }

  my %metadata = (
    name =&gt; $self-&gt;dist_name,
    version =&gt; $self-&gt;normalize_version($self-&gt;dist_version),
    author =&gt; $self-&gt;dist_author,
    abstract =&gt; $self-&gt;dist_abstract,
    generated_by =&gt; "Module::Build version $Module::Build::VERSION",
    'meta-spec' =&gt; {
      version =&gt; '2',
      url     =&gt; 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
    },
    dynamic_config =&gt; exists $p-&gt;{dynamic_config} ? $p-&gt;{dynamic_config} : 1,
    release_status =&gt; $self-&gt;release_status,
  );

  my ($meta_license, $meta_license_url) = $self-&gt;_get_license;
  $metadata{license} = [ $meta_license ];
  $metadata{resources}{license} = [ $meta_license_url ] if defined $meta_license_url;

  $metadata{prereqs} = $self-&gt;_normalize_prereqs;

  if (exists $p-&gt;{no_index}) {
    $metadata{no_index} = $p-&gt;{no_index};
  } elsif (my $pkgs = eval { $self-&gt;find_dist_packages }) {
    $metadata{provides} = $pkgs if %$pkgs;
  } else {
    $self-&gt;log_warn("$@\nWARNING: Possible missing or corrupt 'MANIFEST' file.\n" .
                    "Nothing to enter for 'provides' field in metafile.\n");
  }

  if (my $add = $self-&gt;meta_add) {
    if (not exists $add-&gt;{'meta-spec'} or $add-&gt;{'meta-spec'}{version} != 2) {
      require CPAN::Meta::Converter;
      if (CPAN::Meta::Converter-&gt;VERSION('2.141170')) {
        $add = CPAN::Meta::Converter-&gt;new($add)-&gt;upgrade_fragment;
        delete $add-&gt;{prereqs}; # XXX this would now overwrite all prereqs
      }
      else {
        $self-&gt;log_warn("Can't meta_add without CPAN::Meta 2.141170");
      }
    }

    while (my($k, $v) = each %{$add}) {
      $metadata{$k} = $v;
    }
  }

  if (my $merge = $self-&gt;meta_merge) {
    if (eval { require CPAN::Meta::Merge }) {
      %metadata = %{ CPAN::Meta::Merge-&gt;new(default_version =&gt; '1.4')-&gt;merge(\%metadata, $merge) };
    }
    else {
      $self-&gt;log_warn("Can't merge without CPAN::Meta::Merge");
    }
  }

  return \%metadata;
}

# To preserve compatibility with old API, $node *must* be a hashref
# passed in to prepare_metadata.  $keys is an arrayref holding a
# list of keys -- it's use is optional and generally no longer needed
# but kept for back compatibility.  $args is an optional parameter to
# support the new 'fatal' toggle

sub prepare_metadata {
  my ($self, $node, $keys, $args) = @_;
  unless ( ref $node eq 'HASH' ) {
    croak "prepare_metadata() requires a hashref argument to hold output\n";
  }
  croak 'Keys argument to prepare_metadata is no longer supported' if $keys;
  %{$node} = %{ $self-&gt;get_meta(%{$args}) };
  return $node;
}

sub _read_manifest {
  my ($self, $file) = @_;
  return undef unless -e $file;

  require ExtUtils::Manifest;  # ExtUtils::Manifest is not warnings clean.
  local ($^W, $ExtUtils::Manifest::Quiet) = (0,1);
  return scalar ExtUtils::Manifest::maniread($file);
}

sub find_dist_packages {
  my $self = shift;

  # Only packages in .pm files are candidates for inclusion here.
  # Only include things in the MANIFEST, not things in developer's
  # private stock.

  my $manifest = $self-&gt;_read_manifest('MANIFEST')
    or die "Can't find dist packages without a MANIFEST file\nRun 'Build manifest' to generate one\n";

  # Localize
  my %dist_files = map { $self-&gt;localize_file_path($_) =&gt; $_ }
                       keys %$manifest;

  my @pm_files = sort grep { $_ !~ m{^t} } # skip things in t/
                   grep {exists $dist_files{$_}}
                     keys %{ $self-&gt;find_pm_files };

  return $self-&gt;find_packages_in_files(\@pm_files, \%dist_files);
}

# XXX Do not document this function; mst wrote it and now says the API is
# stupid and needs to be fixed and it shouldn't become a public API until then
sub find_packages_in_files {
  my ($self, $file_list, $filename_map) = @_;

  # First, we enumerate all packages &amp; versions,
  # separating into primary &amp; alternative candidates
  my( %prime, %alt );
  foreach my $file (@{$file_list}) {
    my $mapped_filename = $filename_map-&gt;{$file};
    my @path = split( /\//, $mapped_filename );
    (my $prime_package = join( '::', @path[1..$#path] )) =~ s/\.pm$//;

    my $pm_info = Module::Metadata-&gt;new_from_file( $file );

    foreach my $package ( $pm_info-&gt;packages_inside ) {
      next if $package eq 'main';  # main can appear numerous times, ignore
      next if $package eq 'DB';    # special debugging package, ignore
      next if grep /^_/, split( /::/, $package ); # private package, ignore

      my $version = $pm_info-&gt;version( $package );

      if ( $package eq $prime_package ) {
        if ( exists( $prime{$package} ) ) {
          # Module::Metadata will handle this conflict
          die "Unexpected conflict in '$package'; multiple versions found.\n";
        } else {
          $prime{$package}{file} = $mapped_filename;
          $prime{$package}{version} = $version if defined( $version );
        }
      } else {
        push( @{$alt{$package}}, {
                                  file    =&gt; $mapped_filename,
                                  version =&gt; $version,
                                 } );
      }
    }
  }

  # Then we iterate over all the packages found above, identifying conflicts
  # and selecting the "best" candidate for recording the file &amp; version
  # for each package.
  foreach my $package ( sort keys( %alt ) ) {
    my $result = $self-&gt;_resolve_module_versions( $alt{$package} );

    if ( exists( $prime{$package} ) ) { # primary package selected

      if ( $result-&gt;{err} ) {
        # Use the selected primary package, but there are conflicting
        # errors among multiple alternative packages that need to be
        # reported
        $self-&gt;log_warn(
          "Found conflicting versions for package '$package'\n" .
          "  $prime{$package}{file} ($prime{$package}{version})\n" .
          $result-&gt;{err}
        );

      } elsif ( defined( $result-&gt;{version} ) ) {
        # There is a primary package selected, and exactly one
        # alternative package

        if ( exists( $prime{$package}{version} ) &amp;&amp;
             defined( $prime{$package}{version} ) ) {
          # Unless the version of the primary package agrees with the
          # version of the alternative package, report a conflict
          if ( $self-&gt;compare_versions( $prime{$package}{version}, '!=',
                                        $result-&gt;{version} ) ) {
            $self-&gt;log_warn(
              "Found conflicting versions for package '$package'\n" .
              "  $prime{$package}{file} ($prime{$package}{version})\n" .
              "  $result-&gt;{file} ($result-&gt;{version})\n"
            );
          }

        } else {
          # The prime package selected has no version so, we choose to
          # use any alternative package that does have a version
          $prime{$package}{file}    = $result-&gt;{file};
          $prime{$package}{version} = $result-&gt;{version};
        }

      } else {
        # no alt package found with a version, but we have a prime
        # package so we use it whether it has a version or not
      }

    } else { # No primary package was selected, use the best alternative

      if ( $result-&gt;{err} ) {
        $self-&gt;log_warn(
          "Found conflicting versions for package '$package'\n" .
          $result-&gt;{err}
        );
      }

      # Despite possible conflicting versions, we choose to record
      # something rather than nothing
      $prime{$package}{file}    = $result-&gt;{file};
      $prime{$package}{version} = $result-&gt;{version}
          if defined( $result-&gt;{version} );
    }
  }

  # Normalize versions or delete them if undef/0
  for my $provides ( values %prime ) {
    if ( $provides-&gt;{version} ) {
      $provides-&gt;{version} = $self-&gt;normalize_version( $provides-&gt;{version} )
    }
    else {
      delete $provides-&gt;{version};
    }
  }

  return \%prime;
}

# separate out some of the conflict resolution logic from
# $self-&gt;find_dist_packages(), above, into a helper function.
#
sub _resolve_module_versions {
  my $self = shift;

  my $packages = shift;

  my( $file, $version );
  my $err = '';
    foreach my $p ( @$packages ) {
      if ( defined( $p-&gt;{version} ) ) {
        if ( defined( $version ) ) {
          if ( $self-&gt;compare_versions( $version, '!=', $p-&gt;{version} ) ) {
            $err .= "  $p-&gt;{file} ($p-&gt;{version})\n";
          } else {
            # same version declared multiple times, ignore
          }
        } else {
          $file    = $p-&gt;{file};
          $version = $p-&gt;{version};
        }
      }
      $file ||= $p-&gt;{file} if defined( $p-&gt;{file} );
    }

  if ( $err ) {
    $err = "  $file ($version)\n" . $err;
  }

  my %result = (
    file    =&gt; $file,
    version =&gt; $version,
    err     =&gt; $err
  );

  return \%result;
}

sub make_tarball {
  my ($self, $dir, $file) = @_;
  $file ||= $dir;

  $self-&gt;log_info("Creating $file.tar.gz\n");

  if ($self-&gt;{args}{tar}) {
    my $tar_flags = $self-&gt;verbose ? 'cvf' : 'cf';
    $self-&gt;do_system($self-&gt;split_like_shell($self-&gt;{args}{tar}), $tar_flags, "$file.tar", $dir);
    $self-&gt;do_system($self-&gt;split_like_shell($self-&gt;{args}{gzip}), "$file.tar") if $self-&gt;{args}{gzip};
  } else {
    eval { require Archive::Tar &amp;&amp; Archive::Tar-&gt;VERSION(1.09); 1 }
      or die "You must install Archive::Tar 1.09+ to make a distribution tarball\n".
             "or specify a binary tar program with the '--tar' option.\n".
             "See the documentation for the 'dist' action.\n";

    my $files = $self-&gt;rscan_dir($dir);

    # Archive::Tar versions &gt;= 1.09 use the following to enable a compatibility
    # hack so that the resulting archive is compatible with older clients.
    # If no file path is 100 chars or longer, we disable the prefix field
    # for maximum compatibility.  If there are any long file paths then we
    # need the prefix field after all.
    $Archive::Tar::DO_NOT_USE_PREFIX =
      (grep { length($_) &gt;= 100 } @$files) ? 0 : 1;

    my $tar   = Archive::Tar-&gt;new;
    $tar-&gt;add_files(@$files);
    for my $f ($tar-&gt;get_files) {
      $f-&gt;mode($f-&gt;mode &amp; ~022); # chmod go-w
    }
    $tar-&gt;write("$file.tar.gz", 1);
  }
}

sub install_path {
  my $self = shift;
  my( $type, $value ) = ( @_, '&lt;empty&gt;' );

  Carp::croak( 'Type argument missing' )
    unless defined( $type );

  my $map = $self-&gt;{properties}{install_path};
  return $map unless @_;

  # delete existing value if $value is literal undef()
  unless ( defined( $value ) ) {
    delete( $map-&gt;{$type} );
    return undef;
  }

  # return existing value if no new $value is given
  if ( $value eq '&lt;empty&gt;' ) {
    return undef unless exists $map-&gt;{$type};
    return $map-&gt;{$type};
  }

  # set value if $value is a valid relative path
  return $map-&gt;{$type} = $value;
}

sub install_sets {
  # Usage: install_sets('site'), install_sets('site', 'lib'),
  #   or install_sets('site', 'lib' =&gt; $value);
  my ($self, $dirs, $key, $value) = @_;
  $dirs = $self-&gt;installdirs unless defined $dirs;
  # update property before merging with defaults
  if ( @_ == 4 &amp;&amp; defined $dirs &amp;&amp; defined $key) {
    # $value can be undef; will mask default
    $self-&gt;{properties}{install_sets}{$dirs}{$key} = $value;
  }
  my $map = { $self-&gt;_merge_arglist(
    $self-&gt;{properties}{install_sets},
    $self-&gt;_default_install_paths-&gt;{install_sets}
  )};
  if ( defined $dirs &amp;&amp; defined $key ) {
    return $map-&gt;{$dirs}{$key};
  }
  elsif ( defined $dirs ) {
    return $map-&gt;{$dirs};
  }
  else {
    croak "Can't determine installdirs for install_sets()";
  }
}

sub original_prefix {
  # Usage: original_prefix(), original_prefix('lib'),
  #   or original_prefix('lib' =&gt; $value);
  my ($self, $key, $value) = @_;
  # update property before merging with defaults
  if ( @_ == 3 &amp;&amp; defined $key) {
    # $value can be undef; will mask default
    $self-&gt;{properties}{original_prefix}{$key} = $value;
  }
  my $map = { $self-&gt;_merge_arglist(
    $self-&gt;{properties}{original_prefix},
    $self-&gt;_default_install_paths-&gt;{original_prefix}
  )};
  return $map unless defined $key;
  return $map-&gt;{$key}
}

sub install_base_relpaths {
  # Usage: install_base_relpaths(), install_base_relpaths('lib'),
  #   or install_base_relpaths('lib' =&gt; $value);
  my $self = shift;
  if ( @_ &gt; 1 ) { # change values before merge
    $self-&gt;_set_relpaths($self-&gt;{properties}{install_base_relpaths}, @_);
  }
  my $map = { $self-&gt;_merge_arglist(
    $self-&gt;{properties}{install_base_relpaths},
    $self-&gt;_default_install_paths-&gt;{install_base_relpaths}
  )};
  return $map unless @_;
  my $relpath = $map-&gt;{$_[0]};
  return defined $relpath ? File::Spec-&gt;catdir( @$relpath ) : undef;
}

# Defaults to use in case the config install paths cannot be prefixified.
sub prefix_relpaths {
  # Usage: prefix_relpaths('site'), prefix_relpaths('site', 'lib'),
  #   or prefix_relpaths('site', 'lib' =&gt; $value);
  my $self = shift;
  my $installdirs = shift || $self-&gt;installdirs
    or croak "Can't determine installdirs for prefix_relpaths()";
  if ( @_ &gt; 1 ) { # change values before merge
    $self-&gt;{properties}{prefix_relpaths}{$installdirs} ||= {};
    $self-&gt;_set_relpaths($self-&gt;{properties}{prefix_relpaths}{$installdirs}, @_);
  }
  my $map = {$self-&gt;_merge_arglist(
    $self-&gt;{properties}{prefix_relpaths}{$installdirs},
    $self-&gt;_default_install_paths-&gt;{prefix_relpaths}{$installdirs}
  )};
  return $map unless @_;
  my $relpath = $map-&gt;{$_[0]};
  return defined $relpath ? File::Spec-&gt;catdir( @$relpath ) : undef;
}

sub _set_relpaths {
  my $self = shift;
  my( $map, $type, $value ) = @_;

  Carp::croak( 'Type argument missing' )
    unless defined( $type );

  # set undef if $value is literal undef()
  if ( ! defined( $value ) ) {
    $map-&gt;{$type} = undef;
    return;
  }
  # set value if $value is a valid relative path
  else {
    Carp::croak( "Value must be a relative path" )
      if File::Spec::Unix-&gt;file_name_is_absolute($value);

    my @value = split( /\//, $value );
    $map-&gt;{$type} = \@value;
  }
}

# Translated from ExtUtils::MM_Any::init_INSTALL_from_PREFIX
sub prefix_relative {
  my ($self, $type) = @_;
  my $installdirs = $self-&gt;installdirs;

  my $relpath = $self-&gt;install_sets($installdirs)-&gt;{$type};

  return $self-&gt;_prefixify($relpath,
                           $self-&gt;original_prefix($installdirs),
                           $type,
                          );
}

# Translated from ExtUtils::MM_Unix::prefixify()
sub _prefixify {
  my($self, $path, $sprefix, $type) = @_;

  my $rprefix = $self-&gt;prefix;
  $rprefix .= '/' if $sprefix =~ m|/$|;

  $self-&gt;log_verbose("  prefixify $path from $sprefix to $rprefix\n")
    if defined( $path ) &amp;&amp; length( $path );

  if( !defined( $path ) || ( length( $path ) == 0 ) ) {
    $self-&gt;log_verbose("  no path to prefixify, falling back to default.\n");
    return $self-&gt;_prefixify_default( $type, $rprefix );
  } elsif( !File::Spec-&gt;file_name_is_absolute($path) ) {
    $self-&gt;log_verbose("    path is relative, not prefixifying.\n");
  } elsif( $path !~ s{^\Q$sprefix\E\b}{}s ) {
    $self-&gt;log_verbose("    cannot prefixify, falling back to default.\n");
    return $self-&gt;_prefixify_default( $type, $rprefix );
  }

  $self-&gt;log_verbose("    now $path in $rprefix\n");

  return $path;
}

sub _prefixify_default {
  my $self = shift;
  my $type = shift;
  my $rprefix = shift;

  my $default = $self-&gt;prefix_relpaths($self-&gt;installdirs, $type);
  if( !$default ) {
    $self-&gt;log_verbose("    no default install location for type '$type', using prefix '$rprefix'.\n");
    return $rprefix;
  } else {
    return $default;
  }
}

sub install_destination {
  my ($self, $type) = @_;

  return $self-&gt;install_path($type) if $self-&gt;install_path($type);

  if ( $self-&gt;install_base ) {
    my $relpath = $self-&gt;install_base_relpaths($type);
    return $relpath ? File::Spec-&gt;catdir($self-&gt;install_base, $relpath) : undef;
  }

  if ( $self-&gt;prefix ) {
    my $relpath = $self-&gt;prefix_relative($type);
    return $relpath ? File::Spec-&gt;catdir($self-&gt;prefix, $relpath) : undef;
  }

  return $self-&gt;install_sets($self-&gt;installdirs)-&gt;{$type};
}

sub install_types {
  my $self = shift;

  my %types;
  if ( $self-&gt;install_base ) {
    %types = %{$self-&gt;install_base_relpaths};
  } elsif ( $self-&gt;prefix ) {
    %types = %{$self-&gt;prefix_relpaths};
  } else {
    %types = %{$self-&gt;install_sets($self-&gt;installdirs)};
  }

  %types = (%types, %{$self-&gt;install_path});

  return sort keys %types;
}

sub install_map {
  my ($self, $blib) = @_;
  $blib ||= $self-&gt;blib;

  my( %map, @skipping );
  foreach my $type ($self-&gt;install_types) {
    my $localdir = File::Spec-&gt;catdir( $blib, $type );
    next unless -e $localdir;

    # the line "...next if (($type eq 'bindoc'..." was one of many changes introduced for
    # improving HTML generation on ActivePerl, see https://rt.cpan.org/Public/Bug/Display.html?id=53478
    # Most changes were ok, but this particular line caused test failures in t/manifypods.t on windows,
    # therefore it is commented out.

    # ********* next if (($type eq 'bindoc' || $type eq 'libdoc') &amp;&amp; not $self-&gt;is_unixish);

    if (my $dest = $self-&gt;install_destination($type)) {
      $map{$localdir} = $dest;
    } else {
      push( @skipping, $type );
    }
  }

  $self-&gt;log_warn(
    "WARNING: Can't figure out install path for types: @skipping\n" .
    "Files will not be installed.\n"
  ) if @skipping;

  # Write the packlist into the same place as ExtUtils::MakeMaker.
  if ($self-&gt;create_packlist and my $module_name = $self-&gt;module_name) {
    my $archdir = $self-&gt;install_destination('arch');
    my @ext = split /::/, $module_name;
    $map{write} = File::Spec-&gt;catfile($archdir, 'auto', @ext, '.packlist');
  }

  # Handle destdir
  if (length(my $destdir = $self-&gt;destdir || '')) {
    foreach (keys %map) {
      # Need to remove volume from $map{$_} using splitpath, or else
      # we'll create something crazy like C:\Foo\Bar\E:\Baz\Quux
      # VMS will always have the file separate than the path.
      my ($volume, $path, $file) = File::Spec-&gt;splitpath( $map{$_}, 0 );

      # catdir needs a list of directories, or it will create something
      # crazy like volume:[Foo.Bar.volume.Baz.Quux]
      my @dirs = File::Spec-&gt;splitdir($path);

      # First merge the directories
      $path = File::Spec-&gt;catdir($destdir, @dirs);

      # Then put the file back on if there is one.
      if ($file ne '') {
          $map{$_} = File::Spec-&gt;catfile($path, $file)
      } else {
          $map{$_} = $path;
      }
    }
  }

  $map{read} = '';  # To keep ExtUtils::Install quiet

  return \%map;
}

sub depends_on {
  my $self = shift;
  foreach my $action (@_) {
    $self-&gt;_call_action($action);
  }
}

sub rscan_dir {
  my ($self, $dir, $pattern) = @_;
  my @result;
  local $_; # find() can overwrite $_, so protect ourselves
  my $subr = !$pattern ? sub {push @result, $File::Find::name} :
             !ref($pattern) || (ref $pattern eq 'Regexp') ? sub {push @result, $File::Find::name if /$pattern/} :
             ref($pattern) eq 'CODE' ? sub {push @result, $File::Find::name if $pattern-&gt;()} :
             die "Unknown pattern type";

  File::Find::find({wanted =&gt; $subr, no_chdir =&gt; 1, preprocess =&gt; sub { sort @_ } }, $dir);
  return \@result;
}

sub delete_filetree {
  my $self = shift;
  my $deleted = 0;
  foreach (@_) {
    next unless -e $_;
    $self-&gt;log_verbose("Deleting $_\n");
    File::Path::rmtree($_, 0, 0);
    die "Couldn't remove '$_': $!\n" if -e $_;
    $deleted++;
  }
  return $deleted;
}

sub autosplit_file {
  my ($self, $file, $to) = @_;
  require AutoSplit;
  my $dir = File::Spec-&gt;catdir($to, 'lib', 'auto');
  AutoSplit::autosplit($file, $dir);
}

sub cbuilder {
  # Returns a CBuilder object

  my $self = shift;
  my $s = $self-&gt;{stash};
  return $s-&gt;{_cbuilder} if $s-&gt;{_cbuilder};

  require ExtUtils::CBuilder;
  return $s-&gt;{_cbuilder} = ExtUtils::CBuilder-&gt;new(
    config =&gt; $self-&gt;config,
    ($self-&gt;quiet ? (quiet =&gt; 1 ) : ()),
  );
}

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

  my $p = $self-&gt;{properties};
  return $p-&gt;{_have_c_compiler} if defined $p-&gt;{_have_c_compiler};

  $self-&gt;log_verbose("Checking if compiler tools configured... ");
  my $b = $self-&gt;cbuilder;
  my $have = $b &amp;&amp; eval { $b-&gt;have_compiler };
  $self-&gt;log_verbose($have ? "ok.\n" : "failed.\n");
  return $p-&gt;{_have_c_compiler} = $have;
}

sub compile_c {
  my ($self, $file, %args) = @_;

  if ( ! $self-&gt;have_c_compiler ) {
    die "Error: no compiler detected to compile '$file'.  Aborting\n";
  }

  my $b = $self-&gt;cbuilder;
  my $obj_file = $b-&gt;object_file($file);
  $self-&gt;add_to_cleanup($obj_file);
  return $obj_file if $self-&gt;up_to_date($file, $obj_file);

  $b-&gt;compile(source =&gt; $file,
              defines =&gt; $args{defines},
              object_file =&gt; $obj_file,
              include_dirs =&gt; $self-&gt;include_dirs,
              extra_compiler_flags =&gt; $self-&gt;extra_compiler_flags,
             );

  return $obj_file;
}

sub link_c {
  my ($self, $spec) = @_;
  my $p = $self-&gt;{properties}; # For convenience

  $self-&gt;add_to_cleanup($spec-&gt;{lib_file});

  my $objects = $p-&gt;{objects} || [];

  return $spec-&gt;{lib_file}
    if $self-&gt;up_to_date([$spec-&gt;{obj_file}, @$objects],
                         $spec-&gt;{lib_file});

  my $module_name = $spec-&gt;{module_name} || $self-&gt;module_name;

  $self-&gt;cbuilder-&gt;link(
    module_name =&gt; $module_name,
    objects     =&gt; [$spec-&gt;{obj_file}, @$objects],
    lib_file    =&gt; $spec-&gt;{lib_file},
    extra_linker_flags =&gt; $self-&gt;extra_linker_flags );

  return $spec-&gt;{lib_file};
}

sub compile_xs {
  my ($self, $file, %args) = @_;

  $self-&gt;log_verbose("$file -&gt; $args{outfile}\n");

  if (eval {require ExtUtils::ParseXS; 1}) {

    ExtUtils::ParseXS::process_file(
                                    filename =&gt; $file,
                                    prototypes =&gt; 0,
                                    output =&gt; $args{outfile},
                                   );
  } else {
    # Ok, I give up.  Just use backticks.

    my $xsubpp = Module::Metadata-&gt;find_module_by_name('ExtUtils::xsubpp')
      or die "Can't find ExtUtils::xsubpp in INC (@INC)";

    my @typemaps;
    push @typemaps, Module::Metadata-&gt;find_module_by_name(
        'ExtUtils::typemap', \@INC
    );
    my $lib_typemap = Module::Metadata-&gt;find_module_by_name(
        'typemap', [File::Basename::dirname($file), File::Spec-&gt;rel2abs('.')]
    );
    push @typemaps, $lib_typemap if $lib_typemap;
    @typemaps = map {+'-typemap', $_} @typemaps;

    my $cf = $self-&gt;{config};
    my $perl = $self-&gt;{properties}{perl};

    my @command = ($perl, "-I".$cf-&gt;get('installarchlib'), "-I".$cf-&gt;get('installprivlib'), $xsubpp, '-noprototypes',
                   @typemaps, $file);

    $self-&gt;log_info("@command\n");
    open(my $fh, '&gt;', $args{outfile}) or die "Couldn't write $args{outfile}: $!";
    print {$fh} $self-&gt;_backticks(@command);
    close $fh;
  }
}

sub split_like_shell {
  my ($self, $string) = @_;

  return () unless defined($string);
  return @$string if ref $string eq 'ARRAY';
  $string =~ s/^\s+|\s+$//g;
  return () unless length($string);

  return Text::ParseWords::shellwords($string);
}

sub oneliner {
  # Returns a string that the shell can evaluate as a perl command.
  # This should be avoided whenever possible, since "the shell" really
  # means zillions of shells on zillions of platforms and it's really
  # hard to get it right all the time.

  # Some of this code is stolen with permission from ExtUtils::MakeMaker.

  my($self, $cmd, $switches, $args) = @_;
  $switches = [] unless defined $switches;
  $args = [] unless defined $args;

  # Strip leading and trailing newlines
  $cmd =~ s{^\n+}{};
  $cmd =~ s{\n+$}{};

  my $perl = ref($self) ? $self-&gt;perl : $self-&gt;find_perl_interpreter;
  return $self-&gt;_quote_args($perl, @$switches, '-e', $cmd, @$args);
}

sub run_perl_script {
  my ($self, $script, $preargs, $postargs) = @_;
  foreach ($preargs, $postargs) {
    $_ = [ $self-&gt;split_like_shell($_) ] unless ref();
  }
  return $self-&gt;run_perl_command([@$preargs, $script, @$postargs]);
}

sub run_perl_command {
  # XXX Maybe we should accept @args instead of $args?  Must resolve
  # this before documenting.
  my ($self, $args) = @_;
  $args = [ $self-&gt;split_like_shell($args) ] unless ref($args);
  my $perl = ref($self) ? $self-&gt;perl : $self-&gt;find_perl_interpreter;

  # Make sure our local additions to @INC are propagated to the subprocess
  local $ENV{PERL5LIB} = join $self-&gt;config('path_sep'), $self-&gt;_added_to_INC;

  return $self-&gt;do_system($perl, @$args);
}

# Infer various data from the path of the input filename
# that is needed to create output files.
# The input filename is expected to be of the form:
#   lib/Module/Name.ext or Module/Name.ext
sub _infer_xs_spec {
  my $self = shift;
  my $file = shift;

  my $cf = $self-&gt;{config};

  my %spec;

  my( $v, $d, $f ) = File::Spec-&gt;splitpath( $file );
  my @d = File::Spec-&gt;splitdir( $d );
  (my $file_base = $f) =~ s/\.[^.]+$//i;

  $spec{base_name} = $file_base;

  $spec{src_dir} = File::Spec-&gt;catpath( $v, $d, '' );

  # the module name
  shift( @d ) while @d &amp;&amp; ($d[0] eq 'lib' || $d[0] eq '');
  pop( @d ) while @d &amp;&amp; $d[-1] eq '';
  $spec{module_name} = join( '::', (@d, $file_base) );

  $spec{archdir} = File::Spec-&gt;catdir($self-&gt;blib, 'arch', 'auto',
                                      @d, $file_base);

  $spec{c_file} = File::Spec-&gt;catfile( $spec{src_dir},
                                       "${file_base}.c" );

  $spec{obj_file} = File::Spec-&gt;catfile( $spec{src_dir},
                                         "${file_base}".$cf-&gt;get('obj_ext') );

  require DynaLoader;
  my $modfname = defined &amp;DynaLoader::mod2fname ? DynaLoader::mod2fname([@d, $file_base]) : $file_base;

  $spec{bs_file} = File::Spec-&gt;catfile($spec{archdir}, "$modfname.bs");

  $spec{lib_file} = File::Spec-&gt;catfile($spec{archdir}, "$modfname.".$cf-&gt;get('dlext'));

  return \%spec;
}

sub process_xs {
  my ($self, $file) = @_;

  my $spec = $self-&gt;_infer_xs_spec($file);

  # File name, minus the suffix
  (my $file_base = $file) =~ s/\.[^.]+$//;

  # .xs -&gt; .c
  $self-&gt;add_to_cleanup($spec-&gt;{c_file});

  unless ($self-&gt;up_to_date($file, $spec-&gt;{c_file})) {
    $self-&gt;compile_xs($file, outfile =&gt; $spec-&gt;{c_file});
  }

  # .c -&gt; .o
  my $v = $self-&gt;dist_version;
  $self-&gt;compile_c($spec-&gt;{c_file},
                   defines =&gt; {VERSION =&gt; qq{"$v"}, XS_VERSION =&gt; qq{"$v"}});

  # archdir
  File::Path::mkpath($spec-&gt;{archdir}, 0, oct(777)) unless -d $spec-&gt;{archdir};

  # .xs -&gt; .bs
  $self-&gt;add_to_cleanup($spec-&gt;{bs_file});
  unless ($self-&gt;up_to_date($file, $spec-&gt;{bs_file})) {
    require ExtUtils::Mkbootstrap;
    $self-&gt;log_info("ExtUtils::Mkbootstrap::Mkbootstrap('$spec-&gt;{bs_file}')\n");
    ExtUtils::Mkbootstrap::Mkbootstrap($spec-&gt;{bs_file});  # Original had $BSLOADLIBS - what's that?
    open(my $fh, '&gt;&gt;', $spec-&gt;{bs_file});  # create
    utime((time)x2, $spec-&gt;{bs_file});  # touch
  }

  # .o -&gt; .(a|bundle)
  $self-&gt;link_c($spec);
}

sub do_system {
  my ($self, @cmd) = @_;
  $self-&gt;log_verbose("@cmd\n");

  # Some systems proliferate huge PERL5LIBs, try to ameliorate:
  my %seen;
  my $sep = $self-&gt;config('path_sep');
  local $ENV{PERL5LIB} =
    ( !exists($ENV{PERL5LIB}) ? '' :
      length($ENV{PERL5LIB}) &lt; 500
      ? $ENV{PERL5LIB}
      : join $sep, grep { ! $seen{$_}++ and -d $_ } split($sep, $ENV{PERL5LIB})
    );

  my $status = system(@cmd);
  if ($status and $! =~ /Argument list too long/i) {
    my $env_entries = '';
    foreach (sort keys %ENV) { $env_entries .= "$_=&gt;".length($ENV{$_})."; " }
    warn "'Argument list' was 'too long', env lengths are $env_entries";
  }
  return !$status;
}

sub copy_if_modified {
  my $self = shift;
  my %args = (@_ &gt; 3
              ? ( @_ )
              : ( from =&gt; shift, to_dir =&gt; shift, flatten =&gt; shift )
             );
  $args{verbose} = !$self-&gt;quiet
    unless exists $args{verbose};

  my $file = $args{from};
  unless (defined $file and length $file) {
    die "No 'from' parameter given to copy_if_modified";
  }

  # makes no sense to replicate an absolute path, so assume flatten
  $args{flatten} = 1 if File::Spec-&gt;file_name_is_absolute( $file );

  my $to_path;
  if (defined $args{to} and length $args{to}) {
    $to_path = $args{to};
  } elsif (defined $args{to_dir} and length $args{to_dir}) {
    $to_path = File::Spec-&gt;catfile( $args{to_dir}, $args{flatten}
                                    ? File::Basename::basename($file)
                                    : $file );
  } else {
    die "No 'to' or 'to_dir' parameter given to copy_if_modified";
  }

  return if $self-&gt;up_to_date($file, $to_path); # Already fresh

  {
    local $self-&gt;{properties}{quiet} = 1;
    $self-&gt;delete_filetree($to_path); # delete destination if exists
  }

  # Create parent directories
  File::Path::mkpath(File::Basename::dirname($to_path), 0, oct(777));

  $self-&gt;log_verbose("Copying $file -&gt; $to_path\n");

  if ($^O eq 'os2') {# copy will not overwrite; 0x1 = overwrite
    chmod 0666, $to_path;
    File::Copy::syscopy($file, $to_path, 0x1) or die "Can't copy('$file', '$to_path'): $!";
  } else {
    File::Copy::copy($file, $to_path) or die "Can't copy('$file', '$to_path'): $!";
  }

  # mode is read-only + (executable if source is executable)
  my $mode = oct(444) | ( $self-&gt;is_executable($file) ? oct(111) : 0 );
  chmod( $mode, $to_path );

  return $to_path;
}

sub up_to_date {
  my ($self, $source, $derived) = @_;
  $source  = [$source]  unless ref $source;
  $derived = [$derived] unless ref $derived;

  # empty $derived means $source should always run
  return 0 if @$source &amp;&amp; !@$derived || grep {not -e} @$derived;

  my $most_recent_source = time / (24*60*60);
  foreach my $file (@$source) {
    unless (-e $file) {
      $self-&gt;log_warn("Can't find source file $file for up-to-date check");
      next;
    }
    $most_recent_source = -M _ if -M _ &lt; $most_recent_source;
  }

  foreach my $derived (@$derived) {
    return 0 if -M $derived &gt; $most_recent_source;
  }
  return 1;
}

sub dir_contains {
  my ($self, $first, $second) = @_;
  # File::Spec doesn't have an easy way to check whether one directory
  # is inside another, unfortunately.

  ($first, $second) = map File::Spec-&gt;canonpath($_), ($first, $second);
  my @first_dirs = File::Spec-&gt;splitdir($first);
  my @second_dirs = File::Spec-&gt;splitdir($second);

  return 0 if @second_dirs &lt; @first_dirs;

  my $is_same = ( $self-&gt;_case_tolerant
                  ? sub {lc(shift()) eq lc(shift())}
                  : sub {shift() eq shift()} );

  while (@first_dirs) {
    return 0 unless $is_same-&gt;(shift @first_dirs, shift @second_dirs);
  }

  return 1;
}

1;
__END__


=head1 NAME

Module::Build::Base - Default methods for Module::Build

=head1 SYNOPSIS

  Please see the Module::Build documentation.

=head1 DESCRIPTION

The C&lt;Module::Build::Base&gt; module defines the core functionality of
C&lt;Module::Build&gt;.  Its methods may be overridden by any of the
platform-dependent modules in the C&lt;Module::Build::Platform::&gt;
namespace, but the intention here is to make this base module as
platform-neutral as possible.  Nicely enough, Perl has several core
tools available in the C&lt;File::&gt; namespace for doing this, so the task
isn't very difficult.

Please see the C&lt;Module::Build&gt; documentation for more details.

=head1 AUTHOR

Ken Williams &lt;kwilliams@cpan.org&gt;

=head1 COPYRIGHT

Copyright (c) 2001-2006 Ken Williams.  All rights reserved.

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

=head1 SEE ALSO

perl(1), Module::Build(3)

=cut
</pre></body></html>