redhotpenguin has asked for the wisdom of the Perl Monks concerning the following question:

This is my latest attempt at a Makefile.PL section that invokes Apache::Bootstrap or exits with exit code 255. The intent is that if Apache::Bootstrap is not installed, the Makefile.PL dies with code 255, the same error number returned to the shell as if 'use 5.8.8;' failed in Makefile.PL.

I'm mainly looking for feedback on this code. The reasons that I need to do what I'm doing may not be all that clear, but I need to use either ExtUtils::MakeMaker or ModPerl::Build::MM, and that depends on the versions of mod_perl (if any) that are installed.

#!/usr/bin/perl use strict; use warnings; ################################### # minimum version of A::B required my $ab = 0.06; eval { require Apache::Bootstrap }; ($@ or ($Apache::Bootstrap::VERSION < $ab)) && do { $! = 255; die("Apache::Bootstrap $ab required"); }; # make sure we have at least one minimum version of mod_perl my $bs = eval { Apache::Bootstrap->new({ mod_perl2 => 1.99022, mod_perl => 1.30 }) }; do { $! = 255; die($@); } if $@; ################################################# # use $bs to determine whether ExtUtils::MakeMaker # or ModPerl::Build::MM should be used to write # the Makefile

Replies are listed 'Best First'.
Re: Bootstrapping Makefile.PL with Apache::Bootstrap
by Anonymous Monk on Apr 28, 2009 at 06:33 UTC
    Only a non-zero exit code is necessary, so I would write
    my $ab = 0.06; eval { require Apache::Bootstrap; Apache::Bootstrap->VERSION($ab); 1 } or die "Apache::Bootstrap $ab required"; my $bs = Apache::Bootstrap->new({ mod_perl2 => 1.99022, mod_perl => 1.30 });
    Actually I would just write use Apache::Bootstrap 0.06;?

      I started with 'use Apache::Bootstrap 0.06;', but that caused an UNKNOWN cpan testers failure, with the error "Can't locate Apache::Bootstrap...". So I checked the error number passed back to the shell for that failure and it was 1.

      I checked the error number passed to the shell for 'use 5.8.6;' pragma in a Makefile.PL that didn't have that version of perl, and the error number was 255. My theory is that Test::Harness or something is picking up that error code differently, since these occurrences are represented in CPAN tester reports as NA.

        I think that is not recommended:
        "Why am I getting a FAIL/UNKNOWN/NA report when prerequisites are not met?"

        Some early versions of CPAN Testers tools had bugs that did not properly catch when prerequisites were specified but not met. Please just ignore these reports.