CPAN-RPM

 view release on metacpan or  search on metacpan

cpan2rpm  view on Meta::CPAN

    $info->{evaldir} = dirname($info->{evaldir})
        unless -d $info->{evaldir};

    chdir $info->{evaldir} || die "get_meta(): $!";

    $_ = "$info->{evaldir}/Build.PL";
    $_ = "$info->{evaldir}/Makefile.PL" unless -e;
    die qq/No PL file [$_] in tarball/ unless -e;
    die qq/Cannot read PL file [$_]/ unless -r;

    ($info->{PL} = $_) =~ s|.*/||;

    #   we want to protect us from exit()ing but without modifying the
    #   actual Makefile.PL since we may be operating in a source directory

    my $PL = readfile();
    $PL =~ s/\bexit\b/return/gs;
    $PL =~ s/\bexec\b/system/gs;
    my $t = "$info->{evaldir}/PL.$$";
    writefile($t, $PL);

    #   now we get the arguments passed to the method that creates
    #   the make script (WriteMakefile || create_build_script)

    {
    no warnings;

    #   dynamically load the module (so when the PL file loads it
    #   we already own it and have hijacked the appropriate method

    my $PLMOD = "ExtUtils::MakeMaker";
    if ($info->{PL} =~ /^Build/) {
        $PLMOD = "Module::Build"; 
        # Module::Build builds itself using itself
        # but we don't have $info->{name} yet, so we use the tarball name
        unshift @INC, 'lib' if $info->{tarball} =~ /^Module-Build/;
        }
    $@ = ""; eval "use $PLMOD"; die "$PLMOD unloadable\n $@" if $@;

    # grab parameters to function e.g. WriteMakefile()

    my $PLFN = "ExtUtils::MakeMaker::WriteMakefile";
    $PLFN = "Module::Build::new" if $info->{PL} =~ /^Build/;

    eval qq/*${PLFN}_orig = \\&$PLFN/;
    eval qq/*$PLFN = sub {
        die "SAFETY ABORT!" if \$ENV{_DEEP_RECURSION}++ > 10;

        # when the function is called as a method e.g.
        # Module::Build->new(), first arg iis module name

        shift \@_ if \@_ % 2;
        
        # collect parameters and call original

        %meta = \@_ unless %meta;
        *$PLFN = \\&${PLFN}_orig;
        goto &$PLFN;
        };/;

    local @ARGV = ();
    local $0 = $t;
	my @listargs = split(' ', $info->{"make-maker"});
    push @ARGV, @listargs if @listargs;
    # execute the makefile
    my $ok = 0;
    eval {
        do $t; $ok++;
        };
    my $err = $@;
    unlink $t || die "get_meta(): rm[$t] - $!";
    if (!$ok) {
        $err =~ s/$t/$info->{PL}/g;
        die "FATAL CRASH! Could not load $info->{PL}:\n$err";
        }

    #   map Build.PL hash keys to MakeMaker's

    if ($info->{PL} =~ /^Build/) {
        my %b2m = qw/
            requires PREREQ_PM
            module_name NAME
            dist_author AUTHOR
            dist_version VERSION
            dist_version_from VERSION_FROM
            /;
        $meta{$b2m{$_}} = $meta{$_} for keys %b2m;
        }
    }

    #   make sure dependencies are installed

    my @deps;
    my $deps = $meta{PREREQ_PM};
    for (grep { $_ ne "perl" } keys %$deps) {
        my $use = "use $_";
        $use .= " $deps->{$_}" if $deps->{$_};

        local $^W = 0;
        $@ = ""; eval $use;

        push @deps, "$_ >= $deps->{$_}" if $@;
        }
    my $msg = "Unable to build module, the following dependencies have failed:";
    die "$msg\n  " . join("\n  ", @deps) . "\nStopped"
        if @deps && !$info->{"no-depchk"};
    print "Dependency check skipped (--make-no-test implied)\n"
        if $info->{"no-depchk"};

    #   figure out package name

    $info->{module} ||= $meta{DISTNAME} || $meta{NAME};
    if (!$info->{module}) {
        #   for directories, guess at the tarball name
        if (-d $info->{dist}) {
            ($info->{tarball} = $info->{dist}) =~ s|.*/||;
            # a source directory may include a version #
            $info->{tarver} = $info->{tarball} =~ s/-(\d+\.?\d*)$// ? $1 : "";
            }
        $info->{module} = $info->{tarball};
        $info->{module} =~ s/-(\d+\.?\d*)$tarRE$//i;



( run in 1.957 second using v1.01-cache-2.11-cpan-97f6503c9c8 )