B
Brian Greenfield
I'm trying to find the version number of the CPAN modules I've
installed so I can keep my modules up to date. The following script
shows the technique I've tried:
#!/usr/bin/perl
use strict;
use warnings FATAL=>'all';
for (qw/Text::Table Class:BI::Loader::GraphViz/)
{
print "$_: /", fetch_installed_version($_), "/\n";
}
sub fetch_installed_version
{
my $pkg = shift;
eval "require $pkg";
my $iver = eval '$'."${pkg}::VERSION";
die "VERSION is not defined in $pkg\n"
unless $iver;
return $iver;
}
The script gets the version for Text::Table but not for
Class:BI::Loader::GraphViz:
Text::Table: /1.107/
VERSION is not defined in Class:BI::Loader::GraphViz
This isn't a one off, about a third of the packages produce the same
error.
If I try to get the version from the command line, I get:
zippy:~/scripts$ perl -MClass:BI::Loader::GraphViz -we \
'print $Class:BI::Loader::GraphViz::VERSION'
Base class package "GraphViz:BI" is empty.
(Perhaps you need to 'use' the module which defines that
package first.)
at /usr/share/perl5/Class/DBI/Loader/GraphViz.pm line 3
BEGIN failed--compilation aborted at
/usr/share/perl5/Class/DBI/Loader/GraphViz.pm line 3.
Compilation failed in require.
BEGIN failed--compilation aborted.
ISTM that my technique is flawed, so what is the best way to find a
module's $VERSION programmatically?
installed so I can keep my modules up to date. The following script
shows the technique I've tried:
#!/usr/bin/perl
use strict;
use warnings FATAL=>'all';
for (qw/Text::Table Class:BI::Loader::GraphViz/)
{
print "$_: /", fetch_installed_version($_), "/\n";
}
sub fetch_installed_version
{
my $pkg = shift;
eval "require $pkg";
my $iver = eval '$'."${pkg}::VERSION";
die "VERSION is not defined in $pkg\n"
unless $iver;
return $iver;
}
The script gets the version for Text::Table but not for
Class:BI::Loader::GraphViz:
Text::Table: /1.107/
VERSION is not defined in Class:BI::Loader::GraphViz
This isn't a one off, about a third of the packages produce the same
error.
If I try to get the version from the command line, I get:
zippy:~/scripts$ perl -MClass:BI::Loader::GraphViz -we \
'print $Class:BI::Loader::GraphViz::VERSION'
Base class package "GraphViz:BI" is empty.
(Perhaps you need to 'use' the module which defines that
package first.)
at /usr/share/perl5/Class/DBI/Loader/GraphViz.pm line 3
BEGIN failed--compilation aborted at
/usr/share/perl5/Class/DBI/Loader/GraphViz.pm line 3.
Compilation failed in require.
BEGIN failed--compilation aborted.
ISTM that my technique is flawed, so what is the best way to find a
module's $VERSION programmatically?