Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^5: $VERSION in module files

by hippo (Chancellor)
on Mar 26, 2020 at 13:34 UTC ( #11114677=note: print w/replies, xml ) Need Help??


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

For the static parse I rely on the "provides" list in the metadata. For the above example the Makefile.PL includes something like this:

my $release = '1.01'; my %MF = ( META_MERGE => { 'meta-spec' => { version => 2 }, provides => { 'Foo' => { file => 'lib/Foo.pm', version => $release }, 'Foo::Bar' => { file => 'lib/Foo/Bar.pm', version => $release }, }, }, # ... }; WriteMakefile (%MF);

So the version is specified explicitly twice: once in the Makefile.PL and once in the master module. If there's a reliable way to specify it explicitly only once that would be good to know.

Replies are listed 'Best First'.
Re^6: $VERSION in module files
by Haarg (Curate) on Mar 27, 2020 at 10:35 UTC
    "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.
      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); :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114677]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2020-07-12 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?