<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package ExtUtils::InstallPaths;
{
  $ExtUtils::InstallPaths::VERSION = '0.010';
}

use 5.008001;
use strict;
use warnings;

use File::Spec ();
use Carp ();
use ExtUtils::Config 0.002;

my %complex_accessors = map { $_ =&gt; 1 } qw/prefix_relpaths install_sets/;
my %hash_accessors = map { $_ =&gt; 1 } qw/install_path install_base_relpaths original_prefix /;

my %defaults = (
	installdirs     =&gt; 'site',
	install_base    =&gt; undef,
	prefix          =&gt; undef,
	verbose         =&gt; 0,
	blib            =&gt; 'blib',
	create_packlist =&gt; 1,
	dist_name       =&gt; undef,
	module_name     =&gt; undef,
	destdir         =&gt; undef,
	install_path    =&gt; sub { {} },
	install_sets    =&gt; \&amp;_default_install_sets,
	original_prefix =&gt; \&amp;_default_original_prefix,
	install_base_relpaths =&gt; \&amp;_default_base_relpaths,
	prefix_relpaths =&gt; \&amp;_default_prefix_relpaths,
);

sub _merge_shallow {
	my ($name, $filter) = @_;
	return sub {
		my ($override, $config) = @_;
		my $defaults = $defaults{$name}-&gt;($config);
		$filter-&gt;($_) for grep $filter, values %$override;
		return { %$defaults, %$override };
	}
}

sub _merge_deep {
	my ($name, $filter) = @_;
	return sub {
		my ($override, $config) = @_;
		my $defaults = $defaults{$name}-&gt;($config);
		my $pair_for = sub {
			my $key = shift;
			my %override = %{ $override-&gt;{$key} || {} };
			$filter &amp;&amp; $filter-&gt;($_) for values %override;
			return $key =&gt; { %{ $defaults-&gt;{$key} }, %override };
		};
		return { map { $pair_for-&gt;($_) } keys %$defaults };
	}
}

my %allowed_installdir = map { $_ =&gt; 1 } qw/core site vendor/;
my $must_be_relative = sub { Carp::croak('Value must be a relative path') if File::Spec-&gt;file_name_is_absolute($_[0]) };
my %deep_filter = map { $_ =&gt; $must_be_relative } qw/install_base_relpaths prefix_relpaths/;
my %filter = (
	installdirs =&gt; sub {
		my $value = shift;
		$value = 'core', Carp::carp('Perhaps you meant installdirs to be "core" rather than "perl"?') if $value eq 'perl';
		Carp::croak('installdirs must be one of "core", "site", or "vendor"') if not $allowed_installdir{$value};
		return $value;
	},
	(map { $_ =&gt; _merge_shallow($_, $deep_filter{$_}) } qw/original_prefix install_base_relpaths/),
	(map { $_ =&gt; _merge_deep($_, $deep_filter{$_}) } qw/install_sets prefix_relpaths/),
);

for my $attribute (keys %defaults) {
	no strict qw/refs/;
	*{$attribute} = $hash_accessors{$attribute} ? 
	sub {
		my ($self, $key) = @_;
		Carp::confess("$attribute needs key") if not defined $key;
		return $self-&gt;{$attribute}{$key};
	} :
	$complex_accessors{$attribute} ?
	sub {
		my ($self, $installdirs, $key) = @_;
		Carp::confess("$attribute needs installdir") if not defined $installdirs;
		Carp::confess("$attribute needs key") if not defined $key;
		return $self-&gt;{$attribute}{$installdirs}{$key};
	} :
	sub {
		my $self = shift;
		return $self-&gt;{$attribute};
	};
}

sub new {
	my ($class, %args) = @_;
	my $config = $args{config} || ExtUtils::Config-&gt;new;
	my %self = (
		config =&gt; $config,
		map { $_ =&gt; exists $args{$_} ? $filter{$_} ? $filter{$_}-&gt;($args{$_}, $config) : $args{$_} : ref $defaults{$_} ? $defaults{$_}-&gt;($config) : $defaults{$_} } keys %defaults,
	);
	$self{module_name} ||= do { my $module_name = $self{dist_name}; $module_name =~ s/-/::/g; $module_name } if defined $self{dist_name};
	return bless \%self, $class;
}

my @install_sets_keys = qw/lib arch bin script bindoc libdoc binhtml libhtml/;
my @install_sets_tail = qw/bin script man1dir man3dir html1dir html3dir/;
my %install_sets_values = (
	core   =&gt; [ qw/privlib archlib /, @install_sets_tail ],
	site   =&gt; [ map { "site$_" } qw/lib arch/, @install_sets_tail ],
	vendor =&gt; [ map { "vendor$_" } qw/lib arch/, @install_sets_tail ],
);

sub _default_install_sets {
	my $c = shift;

	my %ret;
	for my $installdir (qw/core site vendor/) {
		@{$ret{$installdir}}{@install_sets_keys} = map { $c-&gt;get("install$_") } @{ $install_sets_values{$installdir} };
	}
	return \%ret;
}

sub _default_base_relpaths {
	my $config = shift;
	return {
		lib     =&gt; ['lib', 'perl5'],
		arch    =&gt; ['lib', 'perl5', $config-&gt;get('archname')],
		bin     =&gt; ['bin'],
		script  =&gt; ['bin'],
		bindoc  =&gt; ['man', 'man1'],
		libdoc  =&gt; ['man', 'man3'],
		binhtml =&gt; ['html'],
		libhtml =&gt; ['html'],
	};
}

my %common_prefix_relpaths = (
	bin        =&gt; ['bin'],
	script     =&gt; ['bin'],
	bindoc     =&gt; ['man', 'man1'],
	libdoc     =&gt; ['man', 'man3'],
	binhtml    =&gt; ['html'],
	libhtml    =&gt; ['html'],
);

sub _default_prefix_relpaths {
	my $c = shift;

	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');

	return {
		core =&gt; {
			lib        =&gt; [@libstyle],
			arch       =&gt; [@libstyle, $version, $arch],
			%common_prefix_relpaths,
		},
		vendor =&gt; {
			lib        =&gt; [@libstyle],
			arch       =&gt; [@libstyle, $version, $arch],
			%common_prefix_relpaths,
		},
		site =&gt; {
			lib        =&gt; [@libstyle, 'site_perl'],
			arch       =&gt; [@libstyle, 'site_perl', $version, $arch],
			%common_prefix_relpaths,
		},
	};
}

sub _default_original_prefix {
	my $c = shift;

	my %ret = (
		core   =&gt; $c-&gt;get('installprefixexp'),
		site   =&gt; $c-&gt;get('siteprefixexp'),
		vendor =&gt; $c-&gt;get('usevendorprefix') ? $c-&gt;get('vendorprefixexp') : '',
	);

	return \%ret;
}

sub _log_verbose {
	my $self = shift;
	print @_ if $self-&gt;verbose;
	return;
}

# 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;
	my $installable = $self-&gt;install_destination($type) &amp;&amp; ( $self-&gt;install_path($type) || $self-&gt;install_sets($self-&gt;installdirs, $type));
	return $installable ? 1 : 0;
}

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 File::Spec-&gt;catdir(@{$default});
	}
}

# Translated from ExtUtils::MM_Unix::prefixify()
sub _prefixify_novms {
	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 (not defined $path or 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 _catprefix_vms {
	my ($self, $rprefix, $default) = @_;

	my ($rvol, $rdirs) = File::Spec-&gt;splitpath($rprefix);
	if ($rvol) {
		return File::Spec-&gt;catpath($rvol, File::Spec-&gt;catdir($rdirs, $default), '');
	}
	else {
		return File::Spec-&gt;catdir($rdirs, $default);
	}
}
sub _prefixify_vms {
	my($self, $path, $sprefix, $type) = @_;
	my $rprefix = $self-&gt;prefix;

	return '' unless defined $path;

	$self-&gt;_log_verbose("  prefixify $path from $sprefix to $rprefix\n");

	require VMS::Filespec;
	# Translate $(PERLPREFIX) to a real path.
	$rprefix = VMS::Filespec::vmspath($rprefix) if $rprefix;
	$sprefix = VMS::Filespec::vmspath($sprefix) if $sprefix;

	$self-&gt;_log_verbose("  rprefix translated to $rprefix\n  sprefix translated to $sprefix\n");

	if (length($path) == 0 ) {
		$self-&gt;_log_verbose("  no path to prefixify.\n")
	}
	elsif (!File::Spec-&gt;file_name_is_absolute($path)) {
		$self-&gt;_log_verbose("	path is relative, not prefixifying.\n");
	}
	elsif ($sprefix eq $rprefix) {
		$self-&gt;_log_verbose("  no new prefix.\n");
	}
	else {
		my ($path_vol, $path_dirs) = File::Spec-&gt;splitpath( $path );
		my $vms_prefix = $self-&gt;config-&gt;get('vms_prefix');
		if ($path_vol eq $vms_prefix.':') {
			$self-&gt;_log_verbose("  $vms_prefix: seen\n");

			$path_dirs =~ s{^\[}{\[.} unless $path_dirs =~ m{^\[\.};
			$path = $self-&gt;_catprefix_vms($rprefix, $path_dirs);
		}
		else {
			$self-&gt;_log_verbose("	cannot prefixify.\n");
			return File::Spec-&gt;catdir($self-&gt;prefix_relpaths($self-&gt;installdirs, $type));
		}
	}

	$self-&gt;_log_verbose("	now $path\n");

	return $path;
}

BEGIN { *_prefixify = $^O eq 'VMS' ? \&amp;_prefixify_vms : \&amp;_prefixify_novms }

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

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

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

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($self-&gt;installdirs, $type);
		return $relpath ? File::Spec-&gt;catdir($self-&gt;prefix, $relpath) : undef;
	}
	return $self-&gt;install_sets($self-&gt;installdirs, $type);
}

sub install_types {
	my $self = shift;

	my %types = ( %{ $self-&gt;{install_path} }, 
		  $self-&gt;install_base ?  %{ $self-&gt;{install_base_relpaths} }
		: $self-&gt;prefix ? %{ $self-&gt;{prefix_relpaths}{ $self-&gt;installdirs } }
		: %{ $self-&gt;{install_sets}{ $self-&gt;installdirs } });

	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;
		}
	}

	warn "WARNING: Can't figure out install path for types: @skipping\nFiles 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;
}

1;

# ABSTRACT: Build.PL install path logic made easy

__END__

=pod

=head1 NAME

ExtUtils::InstallPaths - Build.PL install path logic made easy

=head1 VERSION

version 0.010

=head1 SYNOPSIS

 use ExtUtils::InstallPaths;
 use ExtUtils::Install 'install';
 GetOptions(\my %opt, 'install_base=s', 'install_path=s%', 'installdirs=s', 'destdir=s', 'prefix=s', 'uninst:1', 'verbose:1');
 my $paths = ExtUtils::InstallPaths-&gt;new(%opt, dist_name =&gt; $dist_name);
 install($paths-&gt;install_map, $opt{verbose}, 0, $opt{uninst});

=head1 DESCRIPTION

This module tries to make install path resolution as easy as possible.

When you want to install a module, it needs to figure out where to install things. The nutshell version of how this works is that default installation locations are determined from L&lt;ExtUtils::Config&gt;, and they may be individually overridden by using the C&lt;install_path&gt; attribute. An C&lt;install_base&gt; attribute lets you specify an alternative installation root like F&lt;/home/foo&gt; and C&lt;prefix&gt; does something similar in a rather different (and more complicated) way. C&lt;destdir&gt; lets you specify a temporary installation directory like F&lt;/tmp/install&gt; in case you want to create bundled-up installable packages.

The following types are supported by default.

=over 4

=item * lib

Usually pure-Perl module files ending in F&lt;.pm&gt; or F&lt;.pod&gt;.

=item * arch

"Architecture-dependent" module files, usually produced by compiling XS, L&lt;Inline&gt;, or similar code.

=item * script

Programs written in pure Perl.  In order to improve reuse, you may want to make these as small as possible - put the code into modules whenever possible.

=item * bin

"Architecture-dependent" executable programs, i.e. compiled C code or something.  Pretty rare to see this in a perl distribution, but it happens.

=item * bindoc

Documentation for the stuff in C&lt;script&gt; and C&lt;bin&gt;.  Usually generated from the POD in those files.  Under Unix, these are manual pages belonging to the 'man1' category. Unless explicitly set, this is only available on platforms supporting manpages.

=item * libdoc

Documentation for the stuff in C&lt;lib&gt; and C&lt;arch&gt;.  This is usually generated from the POD in F&lt;.pm&gt; and F&lt;.pod&gt; files.  Under Unix, these are manual pages belonging to the 'man3' category. Unless explicitly set, this is only available on platforms supporting manpages.

=item * binhtml

This is the same as C&lt;bindoc&gt; above, but applies to HTML documents. Unless explicitly set, this is only available when perl was configured to do so.

=item * libhtml

This is the same as C&lt;libdoc&gt; above, but applies to HTML documents. Unless explicitly set, this is only available when perl was configured to do so.

=back

=head1 ATTRIBUTES

=head2 installdirs

The default destinations for these installable things come from entries in your system's configuration. You can select from three different sets of default locations by setting the C&lt;installdirs&gt; parameter as follows:

                          'installdirs' set to:
                   core          site                vendor

              uses the following defaults from ExtUtils::Config:

  lib     =&gt; installprivlib  installsitelib      installvendorlib
  arch    =&gt; installarchlib  installsitearch     installvendorarch
  script  =&gt; installscript   installsitescript   installvendorscript
  bin     =&gt; installbin      installsitebin      installvendorbin
  bindoc  =&gt; installman1dir  installsiteman1dir  installvendorman1dir
  libdoc  =&gt; installman3dir  installsiteman3dir  installvendorman3dir
  binhtml =&gt; installhtml1dir installsitehtml1dir installvendorhtml1dir [*]
  libhtml =&gt; installhtml3dir installsitehtml3dir installvendorhtml3dir [*]

  * Under some OS (eg. MSWin32) the destination for HTML documents is determined by the C&lt;Config.pm&gt; entry C&lt;installhtmldir&gt;.

The default value of C&lt;installdirs&gt; is "site".

=head2 install_base

You can also set the whole bunch of installation paths by supplying the C&lt;install_base&gt; parameter to point to a directory on your system.  For instance, if you set C&lt;install_base&gt; to "/home/ken" on a Linux system, you'll install as follows:

  lib     =&gt; /home/ken/lib/perl5
  arch    =&gt; /home/ken/lib/perl5/i386-linux
  script  =&gt; /home/ken/bin
  bin     =&gt; /home/ken/bin
  bindoc  =&gt; /home/ken/man/man1
  libdoc  =&gt; /home/ken/man/man3
  binhtml =&gt; /home/ken/html
  libhtml =&gt; /home/ken/html

=head2 prefix

This sets a prefix, identical to ExtUtils::MakeMaker's PREFIX option. This does something similar to C&lt;install_base&gt; in a much more complicated way.

=head2 config()

The L&lt;ExtUtils::Config|ExtUtils::Config&gt; object used for this object.

=head2 verbose

The verbosity of ExtUtils::InstallPaths. It defaults to 0

=head2 blib

The location of the blib directory, it defaults to 'blib'.

=head2 create_packlist

Together with C&lt;module_name&gt; this controls whether a packlist will be added; it defaults to 1.

=head2 dist_name

The name of the current module.

=head2 module_name

The name of the main module of the package. This is required for packlist creation, but in the future it may be replaced by dist_name. It defaults to C&lt;dist_name =~ s/-/::/gr&gt; if dist_name is set.

=head2 destdir

If you want to install everything into a temporary directory first (for instance, if you want to create a directory tree that a package manager like C&lt;rpm&gt; or C&lt;dpkg&gt; could create a package from), you can use the C&lt;destdir&gt; parameter. E.g. Setting C&lt;destdir&gt; to C&lt;"/tmp/foo"&gt; will effectively install to "/tmp/foo/$sitelib", "/tmp/foo/$sitearch", and the like, except that it will use C&lt;File::Spec&gt; to make the pathnames work correctly on whatever platform you're installing on.

=head1 METHODS

=head2 new

Create a new ExtUtils::InstallPaths object. B&lt;All attributes are valid arguments&gt; to the constructor, as well as this:

=over 4

=item * install_path

This must be a hashref with the type as keys and the destination as values.

=item * install_base_relpaths

This must be a hashref with types as keys and a path relative to the install_base as value.

=item * prefix_relpaths

This must be a hashref any of these three keys: core, vendor, site. Each of the values mush be a hashref with types as keys and a path relative to the prefix as value. You probably want to make these three hashrefs identical.

=item * original_prefix

This must be a hashref with the legal installdirs values as keys and the prefix directories as values.

=item * install_sets

This mush be a hashref with the legal installdirs are keys, and the values being hashrefs with types as keys and locations as values.

=back

=head2 install_map()

Return a map suitable for use with L&lt;ExtUtils::Install&gt;. B&lt;In most cases, this is the only method you'll need&gt;.

=head2 install_destination($type)

Returns the destination of a certain type.

=head2 install_types()

Return a list of all supported install types in the current configuration.

=head2 is_default_installable($type)

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 the configuration object or set explicitly by the user via install_path.

=head2 install_path($type)

Gets the install path for a certain type.

=head2 install_sets($installdirs, $type)

Get the path for a certain C&lt;$type&gt; with a certain C&lt;$installdirs&gt;.

=head2 install_base_relpaths($type, $relpath)

Get the relative paths for use with install_base for a certain type.

=head2 prefix_relative($installdirs, $type)

Gets the path of a certain C&lt;$type&gt; and C&lt;$installdirs&gt; relative to the prefix.

=head2 prefix_relpaths($install_dirs, $type)

Get the default relative path to use in case the config install paths cannot be prefixified. You do not want to use this to get any relative path, but may require it to set it for custom types.

=head2 original_prefix($installdirs)

Get the original prefix for a certain type of $installdirs.

=head1 SEE ALSO

=over 4

=item * L&lt;Build.PL spec|http://github.com/dagolden/cpan-api-buildpl/blob/master/lib/CPAN/API/BuildPL.pm&gt;

=back

=head1 AUTHORS

=over 4

=item *

Ken Williams &lt;kwilliams@cpan.org&gt;

=item *

Leon Timmermans &lt;leont@cpan.org&gt;

=back

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Ken Williams, Leon Timmermans.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
</pre></body></html>