Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: $VERSION in module files

by haukex (Bishop)
on Mar 26, 2020 at 12:25 UTC ( #11114669=note: print w/replies, xml ) Need Help??


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

package Foo; our $VERSION = '1.01'; # ... package Foo::Bar; use Foo; our $VERSION = $Foo::VERSION;

If that's in a single file that may work, I'm not sure, however, I suspect at least some of the tools that rely on a static parse won't be able to handle that.

Replies are listed 'Best First'.
Re^5: $VERSION in module files
by hippo (Bishop) on Mar 26, 2020 at 13:34 UTC

    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.

      "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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2021-12-08 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (36 votes). Check out past polls.

    Notices?