views:

169

answers:

5

Having volunteered to maintain a stagnant CPAN package (GnuPG) I'd like improve the install files such that they exit gracefully if the gpg binary (which GnuPG is a wrapper for) cannot be found. After a bit of seeking inspiration from other packages, I've come up with adding this to Makefile.PL:

my @paths = grep { -x "$_/gpg" } split /:/, $ENV{PATH}, $ENV{PGP_PATH};

unless ( scalar @paths ) {
    print <<EOD;
I can't find the gpg binary on your system. If it's not installed in your usual PATH, set $ENV{PGP_PATH} to include where it can be found and try installing again.
EOD

    exit(0);
}

WriteMakefile(
    'NAME'        => 'GnuPG',
    'VERSION_FROM' => 'GnuPG.pm',
    'EXE_FILES'    => [ gpgmailtunl ],
    'LICENSE'      => 'GPL',
    'LIBS'         => [ @paths ],
);

Does that look sane?

+1  A: 

Wouldn't it make more sense to just print a warning? Is gpg necessary for the installation itself?

The code itself looks fine by me. But perhaps there's a built-in 'which' functionality. :).

reto
That's true. I'll need to make the tests skip as well if gpg can't be found.
robbiebow
+1  A: 

For better accuracy you should look at File::Which or at least use File::Spec->path().

Shlomi Fish
+3  A: 

If you're using Module::Install or part of that family, you can use do

requires_external_bin 'gpg';

See Module::Install::External for details.

No good reason to reinvent the wheel.

Kent Fredric
Thanks. It's based on ExtUtils::MakeMaker atm but that can change.
robbiebow
And if you need to test if certain libraries and header files (not just a binary) are available you can use Devel::CheckLib.
mpeters
+1  A: 

The general concept is fine - if what you need to work is not present, don't create the makefile. The CPAN Testers have rules about exiting with a zero status on failure (which annoys me a lot, but never mind; I hate failing with a success status!).

Question: do you keep a record of where PGP was found at install time, so that if somebody else uses the Perl module without the location on their path, the module can still run?

For DBD::Informix, I have rigid dependencies without which the module cannot be compiled; the Makefile.PL is a major production in its own right because of that. It also tries to handle versions of the software covering over 15 years; that complicates its life, too. If the pre-requisites (some Perl modules; some non-Perl software) is not available, it won't install.

Jonathan Leffler
No record kept atm. I'm not keen on refactoring too much, given that I am not prepared to spend too much time on it, so it's not likely to be kept in the near future. GnuPG cannot work without the gpg binary so, whilst it could install without it, it would be useless without it.
robbiebow
+1  A: 

File::Which would be a crossplatform solution. You will need to either bundle it into inc/ directory or require it to be installed with configure_requires. For EU::MM it can be done with

 META_MERGE => {
  configure_requires => {
   'File::Which' => 0,

Module::Install is also a good solution, but you will need to release new version of distribution each time new version of Module::Install is released and changes are important.

Alexandr Ciornii