http://www.perlmonks.org?node_id=11114713


in reply to Re^5: $VERSION in module files
in thread $VERSION in module files

"provides" isn't the only place versions are used. CPAN clients do a "static" parse (really a single line execution) to check the installed version of a module. If you specify versions in this way, the CPAN clients won't be able to check for upgrades or resolve dependencies on these modules correctly, and install tools like ExtUtils::MakeMaker will complain about missing dependencies.

Replies are listed 'Best First'.
Re^7: $VERSION in module files
by hippo (Chancellor) on Mar 27, 2020 at 11:00 UTC
    CPAN clients do a "static" parse (really a single line execution) to check the installed version of a module.

    That's interesting and certainly news to me (++). I take it you mean that they do something like a grep for '\$VERSION\s*=' and then execute that line/statement in isolation? It's obvious how that would fail for anything but the simplest cases. Is this documented anywhere?

    With your knowledge of these clients, is there any solution to maintaining a uniform version number across multiple modules in a single dist other than just brute-force updates of static scalar values?

    Update: To answer my own question, see https://metacpan.org/pod/distribution/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker/FAQ.pod#Generating-*.pm-files-with-substitutions-eg-of-$VERSION which has a solid-looking answer, if not perhaps the most elegant. I will have a play with this but it looks like it might be a winner.

      I take it you mean that they do something like a grep for '\$VERSION\s*=' and then execute that line/statement in isolation?

      I just checked, cpanm uses Parse::PMFile, its _parse_version is fairly complex*, and its code apparently borrows from PAUSE::pmfile, the latter of course being the indexer for pause.perl.org. Then there's Module::Info's version, which borrows its code from ExtUtils::MM_Unix... I suspect there's probably a couple more variations on this kind of code out there.

      * Its comments also show some very interesting ways some modules set their versions: my $version = atan2(1,1) * 4; $Acme::Pi::VERSION = substr("$version", 0, 16); :-)