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

Hi Monks,

Long time listener, first time caller.

Is it possible to declare an either/or relationship on CPAN? i.e. a PREREQ_PM on Module::A OR Module::B? It doesn't have to be EU:MM; I'd happily switch to M:I or M:B for this functionality.

The context: I've recently uploaded Net::HTTPS::Any. It depends on Net::SSLeay OR Crypt::SSLeay, but I have no way of declaring this to CPAN, resulting in a pile of test failures.

Thanks for your wisdom.

  • Comment on CPAN module dependencies: possible to depend on A OR B

Replies are listed 'Best First'.
Re: CPAN module dependencies: possible to depend on A OR B
by Corion (Patriarch) on May 24, 2010 at 20:10 UTC

    When writing your prerequisites (for example in your Makefile.PL), check whether one of the two alternatives is installed, and if so, output the prerequisite information for that alternative. If none is installed, choose/specify a default.

      I'm sorry Corion, I should have said that I'm aware of such workarounds and don't feel they are appropriate. The sort of hack you are suggesting does not declare to CPAN tools that e.g. parse META.yml that there are two alternatives available.

      "Choose/specify a default" very much defeats the purpose of an Any module in the first place. Net::HTTPS::Any is unlike Any::Moose, for example - one of the two alternatives is not smaller/lighter-weight than the other and neither is an appropriate default.

      So I'm interested in whether or not there is an actual solution. A definitive "there is no way to declare a dependency on A or B" is certainly useful information as well!

      Thanks again monks for any wisdom you have to offer.

        "Choose/specify a default" very much defeats the purpose

        Nonsense. You already default to using Net::SSLeay over Crypt::SSLeay, Moose over Mouse.

        The installer could always ask which one to install if the install is interactive.

Re: CPAN module dependencies: possible to depend on A OR B
by Khen1950fx (Canon) on May 25, 2010 at 05:52 UTC
    FWIW, I downloaded Net::HTTPS::Any, and all the tests passed, but that's because I have OpenSSL, Net::SSLeay, and Crypt::SSLeay.

    A couple of questions: What version of OpenSSL did you test this against? What versions of Net::SSLeay and Crypt::SSLeay did you use to build the module?

    Instead of using OR, I would use CONFIGURE_REQUIRES in your Makefile.PL. That way, it'll stop the installation. and your users won't have to go through all tests just to fail. I revamped your Makefile.PL:

    use inc::Module::Install; WriteMakefile( NAME => 'Net::HTTPS::Any', AUTHOR => 'Ivan Kohler <ivan-net-https-any@freeside.bi +z>', VERSION_FROM => 'lib/Net/HTTPS/Any.pm', ABSTRACT_FROM => 'lib/Net/HTTPS/Any.pm', PL_FILES => {}, CONFIGURE_REQUIRES => { 'Net::SSLeay' => 0, 'Crypt::SSLeay' => 0, }, PREREQ_PM => { 'Test::More' => 0, 'URI::Escape' => 0, 'Tie::IxHash' => 0, 'Net::SSLeay' => 0, 'Crypt::SSLeay' => 0, 'LWP' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => '.gz', }, clean => { FILES => 'Net-HTTPS-Any-*', }, );
      That will make it fail is they don't have both. It should only fail if neither is installed.
Re: CPAN module dependencies: possible to depend on A OR B
by ikegami (Patriarch) on May 24, 2010 at 23:57 UTC

    No. You'll need to check whether the environment is suitable during the makefile generation stage.

    You could list them as recommendations, though.

Re: CPAN module dependencies: possible to depend on A OR B
by Marshall (Canon) on May 25, 2010 at 02:05 UTC
    This SSLeay is a weird critter. When I first needed this, I couldn't download it from a USA site and had to get it from Canada.... There are some very strange and hard to understand USA export regulations regarding encryption software. Net::SSLeay vs Crypt::SSLeay: I would download both. From my understanding nowadays, they should be the same, but I have heard that Net:: version is the "way to go".
Re: CPAN module dependencies: possible to depend on A OR B
by doug (Pilgrim) on May 25, 2010 at 22:32 UTC

    ivan,

    I've never done the anything releated to CPAN installation other than using it. Could you do a simple check to see what was already installed before building your list?

    my $match; foreach my $candidate ( @ORDERED_LIST_OF_POSSIBLE_MODULES ) { eval "use $candidate;"; next if ( $@ ); $match = $candidate; last; }

    If  $match is true, then you use that module, otherwise you are going to need to install something. Would this get you where you need to be?

    - doug

Re: CPAN module dependencies: possible to depend on A OR B
by ambrus (Abbot) on May 26, 2010 at 19:52 UTC

    I don't think so, but I'd like to see that feature in a future version of CPAN too. Note that Module::Build itself can't implement this, it needs to be supported by the CPAN module because it's what fetches the dependencies. See Re: Upgrading CPAN - Yes We Can.