Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: What does use vars qw{$VERSION}; do?

by davido (Cardinal)
on Oct 31, 2016 at 05:15 UTC ( [id://1174990]=note: print w/replies, xml ) Need Help??


in reply to Re^2: What does use vars qw{$VERSION}; do?
in thread What does use vars qw{$VERSION}; do?

All CPAN modules should (and many other non-CPAN modules also do) declare a $VERSION. This allows the caller to do this:

use Foo; if (Foo->VERSION() < 1.56) { # do something... } # or if ($Foo::VERSION < 1.56) { # do something... }

(Take your pick.)... or...

use Foo 1.56 # Die during compiletime if the minimum version is not me +t.

In most cases the module that declares a version doesn't use it for anything itself. The package global is set up for external consumption. This is one of the benefits of package globals: Anyone from any other package can reach right in and have a look.

Here's another example:

perl -MList::Util -E 'say List::Util->VERSION()'

The BEGIN block, once again, is used to assure that the variable is given a value early enough in the compile process that it will be available to the caller when the caller invokes use. It also turns out that use can be used to enforce minimum versions, so the variable MUST have a value early in the process. See use for additional explanation of version checking, and perlmod and perlmodstyle for discussion of version numbers.


Dave

Replies are listed 'Best First'.
Re^4: What does use vars qw{$VERSION}; do?
by alwynpan (Acolyte) on Oct 31, 2016 at 05:25 UTC
    Hi Dave, crystal clear. Thank you so much for your detailed explanation.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-16 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found