Apache-Test

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

use ExtUtils::MakeMaker;
use Symbol;
use File::Find qw(finddepth);

use Apache::TestMM qw(test clean); #enable 'make test and make clean'
use Apache::TestRun;
use Apache::TestTrace;
use Apache::TestReport;
use Apache::TestConfig ();
use Apache::TestRunPerl;

my $VERSION;
set_version();

Apache::TestMM::filter_args();

my @scripts = qw(t/TEST);

finddepth(sub {
    return if $_ eq 'Apache-TestItSelf';
    return unless /(.*?\.pl)\.PL$/;
    push @scripts, "$File::Find::dir/$1";
}, '.');

for (@scripts) {
    Apache::TestMM::generate_script($_);
}
Apache::TestReport->generate_script;

my @clean_files =
    qw(.mypacklist
       t/TEST
       t/REPORT
       Makefile.old
      );

my %prereq = (
    'File::Spec' => '0.8',
    'Cwd'        => '2.06',
);

# Apache::TestServer uses Win32::Process on Windows.
if ($^O =~ /MSWin32/i) {
    $prereq{'Win32::Process'} = '0'
}

# Apache-Test/META.yml is excluded from mp2 distro to make PAUSE
# indexer happy, but then perl Makefile.PL complains about a missing
# META.yml, so autogenerate it if it wasn't in the distro
my $no_meta = TOP_LEVEL ? 1 : 0;

WriteMakefile(
    NAME      => 'Apache::Test',
    VERSION   => $VERSION,
    PREREQ_PM => \%prereq,
    NO_META   => $no_meta,
    dist      => {
        COMPRESS => 'gzip -9f', SUFFIX => 'gz',
        PREOP   => 'find $(DISTVNAME) -type d -print|xargs chmod 0755 && ' .
                   'find $(DISTVNAME) -type f -print|xargs chmod 0644',
        TO_UNIX => 'find $(DISTVNAME) -type f -print|xargs dos2unix'
    },
    clean     => {
        FILES => "@clean_files",
    },
);

# after CPAN/CPANPLUS had a chance to satisfy the requirements,
# enforce those (for those who run things manually)
check_prereqs();

sub check_prereqs {
    my %fail = ();
    for (sort keys %prereq) {
        unless (chk_version($_, $prereq{$_})) {
            $fail{$_} = $prereq{$_};
        }
    }
    if (%fail) {
        error "\nThe following Apache-Test dependencies aren't satisfied:",
            map { "\t$_: $fail{$_}" } sort keys %fail;
        error "Install those from http://search.cpan.org and try again";
        exit 0;
    }
}

sub chk_version {
    my($pkg, $wanted) = @_;

    no strict 'refs';
    local $| = 1;

    print "Checking for $pkg...";
    (my $p = $pkg . ".pm") =~ s#::#/#g;
    eval { require $p;};
    print("not ok\n$@"), return if $@;

    my $vstr = ${"${pkg}::VERSION"} ? "found v" . ${"${pkg}::VERSION"}
        : "not found";
    my $vnum = eval(${"${pkg}::VERSION"}) || 0;

    print $vnum >= $wanted ? "ok\n" : " " . $vstr . "\n";

    $vnum >= $wanted;
}

sub set_version {
    $VERSION = $Apache::Test::VERSION;

    my $fh = Symbol::gensym();
    open $fh, 'Changes' or die "Can't open Changes: $!";
    while (<$fh>) {
        if(/^=item.*-(dev|rc\d+)/) {
            $VERSION .= "-$1";
            last;
        }
        last if /^=item/;
    }
    close $fh;
}



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