Config-AutoConf

 view release on metacpan or  search on metacpan

lib/Config/AutoConf.pm  view on Meta::CPAN

package Config::AutoConf;

use warnings;
use strict;

use base 'Exporter';

our @EXPORT = ('$LIBEXT', '$EXEEXT');

use constant QUOTE => do { $^O eq "MSWin32" ? q["] : q['] };

use Config;
use Carp qw/croak/;

use File::Temp qw/tempfile/;
use File::Basename;
use File::Spec;
use Text::ParseWords qw//;

use Capture::Tiny qw/capture/;

# in core since 5.7.3
eval "use Scalar::Util qw/looks_like_number/;";
__PACKAGE__->can("looks_like_number") or eval <<'EOP';
=begin private

=head2 looks_like_number

=end private

=cut

# from PP part of Params::Util
sub looks_like_number {
    local $_ = shift;

    # checks from perlfaq4
    return 0 if !defined($_);
    if (ref($_)) {
        return overload::Overloaded($_) ? defined(0 + $_) : 0;
    }
    return 1 if (/^[+-]?[0-9]+$/); # is a +/- integer
    return 1 if (/^([+-]?)(?=[0-9]|\.[0-9])[0-9]*(\.[0-9]*)?([Ee]([+-]?[0-9]+))?$/); # a C float
    return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006001 and /^Inf$/i);

    0;
}
EOP

eval "use File::Slurper qw/read_binary/;";
__PACKAGE__->can("read_binary") or eval <<'EOP';
=begin private

=head2 read_file

=end private

=cut

sub read_binary {
  my $fn = shift;
  local $@ = "";
  open( my $fh, "<", $fn ) or croak "Error opening $fn: $!";
  my $fc = <$fh>;
  close($fh) or croak "I/O error closing $fn: $!";
  return $fc;
}
EOP

# PA-RISC1.1-thread-multi
my %special_dlext = (
    darwin  => ".dylib",
    MSWin32 => ".dll",
    ($Config{archname} =~ m/PA-RISC/i ? ("hpux" => ".sl") : ()),
);

our ($LIBEXT, $EXEEXT);

defined $LIBEXT
  or $LIBEXT =
    defined $Config{so}         ? "." . $Config{so}
  : defined $special_dlext{$^O} ? $special_dlext{$^O}
  :                               ".so";
defined $EXEEXT
  or $EXEEXT = ($^O eq "MSWin32") ? ".exe" : "";

=encoding UTF-8

=head1 NAME

Config::AutoConf - A module to implement some of AutoConf macros in pure perl.

=cut

our $VERSION = '0.320';
$VERSION = eval $VERSION;

=head1 ABSTRACT

With this module I pretend to simulate some of the tasks AutoConf
macros do. To detect a command, to detect a library, etc.

=head1 SYNOPSIS



( run in 1.367 second using v1.01-cache-2.11-cpan-39bf76dae61 )