2

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
  • 1
    You should never split on ":", but rather on $Config{path_sep}. Or, for this purpose, use something like IPC::Cmd::can_run('gpg')
    – xdg
    May 11, 2009 at 22:43

5 Answers 5

3

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.

2
  • Thanks. It's based on ExtUtils::MakeMaker atm but that can change.
    – robbiebow
    May 10, 2009 at 15:37
  • 2
    And if you need to test if certain libraries and header files (not just a binary) are available you can use Devel::CheckLib.
    – mpeters
    May 11, 2009 at 13:04
1

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.

1
  • 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
    May 10, 2009 at 15:40
1

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. :).

1
  • That's true. I'll need to make the tests skip as well if gpg can't be found.
    – robbiebow
    May 10, 2009 at 14:34
1

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

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.