Re: Finding version of a Perl module
by b10m (Vicar) on Sep 09, 2005 at 12:39 UTC
|
perl -MCGI -e'print $CGI::VERSION';
--
b10m
All code is usually tested, but rarely trusted.
| [reply] [d/l] |
|
perldoc -m CGI
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
| [reply] [d/l] [select] |
Re: Finding version of a Perl module
by merlyn (Sage) on Sep 09, 2005 at 13:25 UTC
|
% perl -MCGI\ 9999999
CGI version 9999999 required--this is only version 3.11.
BEGIN failed--compilation aborted.
%
Dunno where I got that trick, but it's really easy.
| [reply] [d/l] |
|
Caveat: merlyn's trick only works is the module uses Exporter or immitates Exporter's version checks (Added for clarity:) by writting an import which calls UNIVERSAL::VERSION.
Update: Apparently, perl will call UNIVERSAL::VERSION for you if the version is passed as a number, not a string.
| [reply] [d/l] [select] |
|
I don't think so. The version check is done by UNIVERSAL::VERSION , which is called by use when you specify a version number when using a module.
From "perldoc -f use":
If the VERSION argument is present between Module and LIST,
then the "use" will call the VERSION method in class Module
with the given version as an argument. The default VERSION
method, inherited from the UNIVERSAL class, croaks if the given
version is larger than the value of the variable
$Module::VERSION.
| [reply] [d/l] [select] |
|
|
|
Re: Finding version of a Perl module
by Fletch (Bishop) on Sep 09, 2005 at 12:51 UTC
|
I have this shell function (zsh, but it should work for most Korn-ish shells):
pmver () {
perl -le "eval { require ${1} }; if( \$@ =~ /locate (\S+)\.pm/ ) { p
+rint qq{${1} not installed}; exit 1; } print qq{${1}: },\$${1}::VERSI
+ON||q{undefined}"
}
It's used like this:
$ pmver CGI
CGI: 3.05
$
| [reply] [d/l] [select] |
Re: Finding version of a Perl module
by jmcnamara (Monsignor) on Sep 09, 2005 at 13:19 UTC
|
perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Some::M
+odule
--
John.
| [reply] [d/l] |
|
| [reply] [d/l] |
Re: Finding version of a Perl module
by lachoy (Parson) on Sep 09, 2005 at 13:24 UTC
|
Just to add another version -- one of my first tasks when using a new machine is to scp the following script somewhere on the path as 'pmv':
#!/usr/bin/perl
for my $module ( @ARGV ) {
eval "require $module";
printf( "%-20s: %s\n", $module, $module->VERSION ) unless ( $@ );
}
A sample use:
cwinters@www ~ $ pmv CGI Template DBI
CGI : 3.05
Template : 2.14
DBI : 1.48
| [reply] [d/l] [select] |
Re: Finding version of a Perl module
by blazar (Canon) on Sep 09, 2005 at 12:51 UTC
|
How 'bout inspecting $That::Particular::Module::VERSION? | [reply] [d/l] |
Re: Finding version of a Perl module
by ybiC (Prior) on Sep 09, 2005 at 14:04 UTC
|
It looks like The Fine Monks have already addressed your particular situation. But since a particular module hasn't yet been mentioned above, see below for mention of a potentially relevant module worth mentioning:
Module::Versions::Report
SYNOPSIS
use Module::Versions::Report;
...and any code you want...
This will run all your code normally, but then as the Perl interpreter
+ is about to exit, it will print something like:
Perl v5.6.1 under MSWin32.
Modules in memory:
attributes;
AutoLoader v5.58;
Carp;
Config;
DynaLoader v1.04;
Exporter v5.562;
Module::Versions::Report v1.01;
HTML::Entities v1.22;
HTML::HeadParser v2.15;
HTML::Parser v3.25;
[... and whatever other modules were loaded that session...]
Consider its use from the command line:
% perl -MModule::Versions::Report -MLWP -e 1
Perl v5.6.1 under MSWin32.
Modules in memory:
attributes;
AutoLoader v5.58;
[...]
cheers,
ybiC
striving toward Perl Adept
(it's pronounced "why-bick")
| [reply] [d/l] |