Get the damned version

Module versions can be found using several ways. I know two.

You can use the module in a one liner and print the module's $VERSION variable:
perl -MSVG -le'print $SVG::VERSION'

This gets annoying when the module name gets long:
perl -MWWW::Mechanize -le'print $WWW::Mechanize::VERSION'

Or the insane:
perl -MPOE::Component::WWW::Pastebin::Bot::Pastebot::Create -le'print $POE::Component::WWW::Pastebin::Bot::Pastebot::Create::VERSION'

Another method I've seen people use is to actually cause an error. Try to load the module in a high version that doesn't exist. The error will show what version it is:
perl -MWWW::Mechanize\ 9999
perl -MPOE::Component::WWW::PasteBin::Bot::Pastebot::Create\ 9999

This is pretty good, since it's short to write and most likely you won't find many versions above 9999 (except perhaps, File::Slurp - last version 9999.13). However, this is a bit confusing to newbies, trying to cause an error on purpose to simply find the version.

Moreover, since it causes a compilation error, you can't easily check multiple versions.

I like this new way better:
$ module-version WWW::Mechanize
1.60
$ module-version --full WWW::Mechanize SVG Moose
WWW::Mechanize 1.60
Warning: module 'SVG' does not seem to be installed.
Moose 0.99

And so on.

If you like it too, you can install Module::Version and have it. There's a few more options there like input from files and no warnings (--quiet).

EDIT: I've renamed the program to mversion.

6 Comments

There are a dozen such tools for reporting the version. Mine is called 'pmq' and also reports the filename.

Why not App::Module::Version? This is about 'module-version' application, not about setting version in module.

Using 9999 would also be a problem for modules that use date-style versions, such as those by Abigail, e.g., 2010041101.

V.pm rocks:

perl -MV=WWW::Mechanize

Leave a comment

About Sawyer X

user-pic Gots to do the bloggingz