perlmakemaker

perl MakeMaker's version_from not used by prereq_pm


Edit

I've prefixed the explanation here, for the benefit of anyone else confused by this issue. As @Ikegami explained,

Often a distribution, with a version number, consists of several modules, each of which comes with its own version number, not the same as the distribution's number.

On the other end of the spectrum, a distribution consisting of a single module in a single file will not need to take advantage of VERSION_FROM.

However, for the middle case:

then, the hack described below may be of use to you.

Hope that helps somebody!

Original Question

Practically the first thing I see in ExtUtils::MakeMaker's POD is VERSION_FROM, which suggests that could, or maybe even should use it. However, even MakeMaker itself doesn't see the version of prerequisites (listed with PREREQ_PM) unless it is in the top-level module. That is, if I setup another module Bar that requires a particular version of Foo, where Foo defines its version somewhere other than Foo.pm, MakeMaker will reports the version of Foo as unknown.

Seems like such an obvious, and longstanding, bug that makes me wonder if I'm just misunderstanding or misusing it?

EDIT The question is: Why does MakeMaker encourage VERSION_FROM when it does not use it to get the version?

EDIT The following is a possibly questionable workaround, not the main question:

OTOH, the code in ExtUtils::MM_Unix that checks the version in no way looks anywhere that VERSION_FROM would have indicated. However, it does indicate an interesting workaround.

If Module Foo has in Makefile.PM:

WriteMakefile(
  NAME=>'Foo',
  VERSION_FROM => 'lib/Foo/Version.pm',
  ...

lib/Foo/Version.pm obviously has

use vars qw($VERSION);
$VERSION = '0.1';

and then in Foo.pm, you put:

$Foo::VERSION = do { use Foo::Version; $Foo::Version::VERSION; };

and everything works..... For now!

So, is it a bug in MakeMaker? and/or is my workaround tolerably sane (by Perl standards)?

thanks


Solution

  • "Works", in this context, would be that when trying to build the hypothetical package "Bar", that MakeMaker would realize that Foo has version 0.1.

    VERSION_FROM specifies where to obtain the distribution's version. It doesn't set any module's version.

    PREREQ_PM defines the list of modules and (in terms of their name and version) the distribution requires.

    A module's version may be different than the version of the distribution in which it resides. The module Foo has no version, which is why requiring version 0.1 of module Foo is (correctly) failing.