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