ExtUtils-InferConfig
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/ExtUtils/InferConfig.pm view on Meta::CPAN
use IPC::Cmd qw//;
use vars qw/$VERSION/;
BEGIN {
$VERSION = '1.04';
}
#use constant ISWIN32 => ($^O =~ /win32/i ? 1 : 0);
=head1 NAME
ExtUtils::InferConfig - Infer Perl Configuration for non-running interpreters
=head1 SYNOPSIS
use ExtUtils::InferConfig;
my $eic = ExtUtils::InferConfig->new(
perl => '/path/to/a/perl'
);
# Get that interpreters %Config as hash ref
my $Config = $eic->get_config;
# Get that interpreters @INC as array ref
my $INC = $eic->get_inc;
=head1 DESCRIPTION
This module can determine the configuration and C<@INC> of a perl
interpreter given its path and that it is runnable by the current
user.
It runs the interpreter with a one-liner and grabs the C<%Config>
hash via STDOUT capturing. Getting the module load paths, C<@INC>,
works the same way for C<@INC> entries that are plain paths.
=head1 METHODS
=head2 new
Requires one named parameter: C<perl>, the path to the perl
interpreter to query for information.
Optional parameter: C<debug =E<gt> 1> enables the debugging mode.
=cut
sub new {
my $class = shift;
$class = ref($class) || $class;
my %args = @_;
my $self = {
perl => undef,
config => undef,
inc => undef,
($args{debug} ? (debug => 1) : ()),
};
bless $self => $class;
# get interpreter, check that we have access
my $perl = $args{perl} || $^X;
$perl = $self->_perl_to_file($perl);
if (not defined $perl) {
croak(
"Invalid perl interpreter specified. "
."It was either not found or it is not executable."
);
}
warn "Using perl '$perl'" if $self->{debug};
$self->{perl} = $perl;
return $self;
}
sub _perl_to_file {
# see perldoc perlvar about this. Look for $^X
my $self = shift;
my $perl = shift;
return() if not defined $perl;
return $perl if -f $perl and -x _;
# Build up a set of file names (not command names).
if ($^O ne 'VMS') {
$perl .= $Config{_exe}
unless $perl =~ m/\Q$Config{_exe}$/i;
}
return $perl if -f $perl and -x _;
return();
}
=head2 get_config
Returns a copy of the C<%Config::Config> hash of the
intepreter which was specified as a parameter to the
constructor.
The first time this method (or the get_inc method below)
is called, the perl binary is run. For subsequent calls
of this method, the information is cached.
=cut
sub get_config {
my $self = shift;
return $self->{config} if defined $self->{config};
$self->{config} = $self->_infer_config($self->{perl});
return $self->{config};
}
sub _infer_config {
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.979 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )