Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Finding a module's $VERSION programmatically
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::DBI::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::DBI::Loader::GraphViz:

Text::Table: /1.107/
VERSION is not defined in Class::DBI::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::DBI::Loader::GraphViz -we \
'print $Class::DBI::Loader::GraphViz::VERSION'
Base class package "GraphViz::DBI" 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?

Report this thread to moderator Post Follow-up to this message
Old Post
Brian Greenfield
10-30-04 01:55 PM


Re: Finding a module's $VERSION programmatically
Brian Greenfield  <$news\200101$@zombie.org.uk> wrote in comp.lang.perl.misc:
> I'm trying to find the version number of the CPAN modules I've
> installed so I can keep my modules up to date.

You get this functionality from CPANPLUS (not sure if the predecessor
CPAN already had it).  It compares versions of installed modules with
current versions on CPAN.

>                                                The following script
> shows the technique I've tried:
>
>     #!/usr/bin/perl
>
>     use strict;
>     use warnings FATAL=>'all';
>
>     for (qw/Text::Table Class::DBI::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::DBI::Loader::GraphViz:
>
>     Text::Table: /1.107/
>     VERSION is not defined in Class::DBI::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::DBI::Loader::GraphViz -we \
>                      'print $Class::DBI::Loader::GraphViz::VERSION'
>     Base class package "GraphViz::DBI" 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?

There is no formal requirement for a CPAN module to have a version.
Modules that are part of a larger distribution often don't have a
version of their own.  Class::DBI::Loader::GraphViz could be one
of those.

For an alternative (but not fundamentally different) approach to
version reading look at base.pm.

Anno

Report this thread to moderator Post Follow-up to this message
Old Post
Anno Siegel
10-30-04 08:56 PM


Re: Finding a module's $VERSION programmatically
On 30 Oct 2004 15:15:34 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

>Brian Greenfield  <$news\200101$@zombie.org.uk> wrote in comp.lang.perl.mis
c: 
>
>You get this functionality from CPANPLUS (not sure if the predecessor
>CPAN already had it).  It compares versions of installed modules with
>current versions on CPAN.

Noted.

[Script snipped]
 
------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^[col
or=darkred] 

I should have read the error message more carefully. Doh!
 

ISTM that my brain is flawed:(

After a couple of hours away from the problem, the solution became
clear: make sure I have all the module dependencies installed

>For an alternative (but not fundamentally different) approach to
>version reading look at base.pm.

Will do. Thanks.

Report this thread to moderator Post Follow-up to this message
Old Post
Brian Greenfield
10-30-04 08:56 PM


Re: Finding a module's $VERSION programmatically
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:cm0b6m$89m$1@mamenchi.zrz.TU-Berlin.DE...
> Brian Greenfield  <$news\200101$@zombie.org.uk> wrote in
comp.lang.perl.misc: 
>
> You get this functionality from CPANPLUS (not sure if the predecessor
> CPAN already had it).  It compares versions of installed modules with
> current versions on CPAN.
>

CPAN.pm does indeed offer this functionality, with the 'r' command from the
CPAN shell.  It will give a list of your currently installed modules that
are less up-to-date than the versions currently available on the CPAN.
(Note that - I believe unlike CPANPLUS - there is no functionality to
automatically download and install the newer versions based on this list).

Paul Lalli



Report this thread to moderator Post Follow-up to this message
Old Post
Paul Lalli
10-31-04 01:55 AM


Re: Finding a module's $VERSION programmatically
Also sprach Paul Lalli:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:cm0b6m$89m$1@mamenchi.zrz.TU-Berlin.DE... 
> comp.lang.perl.misc: 
>
> CPAN.pm does indeed offer this functionality, with the 'r' command from th
e
> CPAN shell.  It will give a list of your currently installed modules that
> are less up-to-date than the versions currently available on the CPAN.
> (Note that - I believe unlike CPANPLUS - there is no functionality to
> automatically download and install the newer versions based on this list).

There is, although no obvious way: You create a bundle with
'autobundle', make sure the newly created file is in @INC and then do a
'install Bundle::Snapshot_<DATE>.pm'

That works best if you have the latest perl installed, otherwise it will
try to grab and compile a new perl.

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
 pam{rekcahbus})(rekcah{lrePbus})(lreP{re
htonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval

Report this thread to moderator Post Follow-up to this message
Old Post
Tassilo v. Parseval
10-31-04 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:06 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.