Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

$VERSION in module files

by bliako (Prior)
on Mar 26, 2020 at 10:09 UTC ( #11114663=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks,

I wonder what is the good practice with the $VERSION string in module files.

I assumed that each module file should have an our $VERSION = '1.2.3'; in it. Please correct me if this is not the correct format.

I also assumed that my Makefile maker ExtUtils::MakeMaker reads version from just one of those files using the key VERSION_FROM in its config.

I also assumed that the Version in the pod section of each module file must be set manually and cannot be read automatically from the $VERSION of that file.

My question is how do I go about and changing all those $VERSION strings and pod Version strings automatically when I create a new version of this module. I can create a script to change $VERSION and, with some risk, pod Versions but I wonder if there is a better way.

bw, bliako

Replies are listed 'Best First'.
Re: $VERSION in module files
by haukex (Bishop) on Mar 26, 2020 at 10:24 UTC

    See my reply in the thread What basic things should I know about versioning modules? that a 1.23 style versioning should provide maximum compatibility, specified in a format of our $VERSION = "1.23";. Of course, TIMTOWTDI, and you'll see some modules use interesting versioning schemes and some modules use code to determine $VERSION like parsing it out of a VCS $Revision$ string. See the documentation in ExtUtils::MakeMaker's VERSION_FROM and ExtUtils::MM_Unix's parse_version, but note that those are probably not the only tools that parse version strings out of module files, so I'd really only recommend our $VERSION = string;.

      OK thanks. So, I must have a $VERSION var in EACH (package) file in the module. I must change those $VERSION strings manually each time. And I must change POD versions manually too. Right?

        Not necessarily. If you maintain a version number for the dist which applies also to all the modules then you can pick one master module which all the others use and have them set their versions from that one. eg.

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

        I never bother specifying version numbers in POD so you're on your own there. :-) Doubtless there's a way in Dist::Zilla but then you'd have $problems++

        In Win32::Mechanize::NotepadPlusPlus, I added a rule in my Makefile.PL postamble, so that make populateversion will take the VERSION that the Makefile sees (which it grabs from the "primary" module in the dist, thanks to $mm_args{VERSION_FROM} ), and uses perl to do an in-place edit of the our $VERSION =... from the related modules.

        # auto-populate the VERSION in the submodules from $(VERSION), which c +omes from main module populateversion :: lib/Win32/Mechanize/NotepadPlusPlus.pm $(NOECHO) $(ECHO) want to auto-populate VERSION in all sub-modules +: $(VERSION) $(PERL) -pi -e "s/^(\s*our\s+.VERSION\s*=).*?;.*?$$/\1 '$(VERSION) +'; # auto-populated from W::M::NPP/" lib/Win32/Mechanize/NotepadPlusP +lus/Notepad.pm lib/Win32/Mechanize/NotepadPlusPlus/Editor.pm

        So I just have to change the version in one master location, and then make populateversion (or, since I have other rules that depend on that rule, run one of those other rules for doing other documentation updates) to get the version in sync across the modules.

Re: $VERSION in module files
by choroba (Archbishop) on Mar 28, 2020 at 12:42 UTC
Re: $VERSION in module files
by BillKSmith (Prior) on Mar 27, 2020 at 03:35 UTC
    I know that it is off-topic, but I recommend that you read the section "Version Numbers" in the book "Perl Best Practices". When you are working with versions numbers, it helps to know the options.
    Bill

      I know that it is off-topic, but I recommend that you read the section "Version Numbers" in the book "Perl Best Practices". When you are working with versions numbers, it helps to know the options. Bill

      *yawn* Module version numbers best practice

Re: $VERSION in module files
by syphilis (Bishop) on Mar 27, 2020 at 12:29 UTC
    Ummm ... what's with the "pod Version strings" ?
    I've never assigned versions to pod.
    I've only ever assigned version numbers in the .pm files.
    Have I missed something ? (I'm not assuming that the correct answer is not "yes".)

    Cheers,
    Rob

      I thought I was cargo culting but just confirmed that module-starter does it (and use it to start a module):

      > module-starter --module=Foo::Bar,Foo::Bat --author="XYZ" --email=abc +@xyz.com > cat Foo-Bar/lib/Foo/Bar.pm ... =head1 NAME Foo::Bar - The great new Foo::Bar! =head1 VERSION Version 0.01 =cut our $VERSION = '0.01';
        I thought I was cargo culting but just confirmed that module-starter does it (and use it to start a module)

        Yeah, fair enough ... but that sort of begs 2 additional questions:
        1) What happens if you don't put a =head1 VERSION section in your pod;
        2) Why has the absence of such a pod heading in any of my modules not caused me any problems - not to mention unbearable embarrassment and humiliation ?

        Sorry ... I'm being a bit of a halfsmartarse in posing it that way.
        Nothing against you, bliako, I'm really just wondering if there's some point in going to such lengths.

        Cheers,
        Rob

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2020-08-06 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (39 votes). Check out past polls.

    Notices?