Finding a module's $VERSION programmatically

Discussion in 'Perl Misc' started by Brian Greenfield, Oct 30, 2004.

  1. 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?
     
    Brian Greenfield, Oct 30, 2004
    #1
    1. Advertising

  2. Brian Greenfield

    Anno Siegel Guest

    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
     
    Anno Siegel, Oct 30, 2004
    #2
    1. Advertising

  3. On 30 Oct 2004 15:15:34 GMT, -berlin.de (Anno
    Siegel) wrote:

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


    Noted.

    [Script snipped]

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


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

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


    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.
     
    Brian Greenfield, Oct 30, 2004
    #3
  4. Brian Greenfield

    Paul Lalli Guest

    "Anno Siegel" <-berlin.de> wrote in message
    news:cm0b6m$89m$-Berlin.DE...
    > 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.
    >


    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
     
    Paul Lalli, Oct 30, 2004
    #4
  5. Also sprach Paul Lalli:
    > "Anno Siegel" <-berlin.de> wrote in message
    > news:cm0b6m$89m$-Berlin.DE...
    >> 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.
    >>

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


    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{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
     
    Tassilo v. Parseval, Oct 31, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. V Green
    Replies:
    0
    Views:
    885
    V Green
    Feb 5, 2008
  2. PA Bear [MS MVP]
    Replies:
    0
    Views:
    1,000
    PA Bear [MS MVP]
    Feb 5, 2008
  3. MowGreen [MVP]
    Replies:
    5
    Views:
    2,045
    PA Bear [MS MVP]
    Feb 9, 2008
  4. W. eWatson
    Replies:
    12
    Views:
    839
    W. eWatson
    Aug 7, 2010
  5. mdev
    Replies:
    0
    Views:
    1,730
Loading...

Share This Page