Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Retrieve list of used modules and their version numbers

by GrandFather (Sage)
on Sep 07, 2006 at 11:43 UTC ( #571662=snippet: print w/replies, xml ) Need Help??
Description: The first part of the snippet goes at the top of your script.

The second part goes where you want to list the modules and versions. Sample output looks like:

Tk 804.027 Tk::Event 4.015 Tk::Event::IO 4.008 AutoLoader 5.60 DynaLoader 1.05 Tk::Submethods 4.004 Encode::Unicode 1.40
use strict;
use warnings;

BEGIN {our @usedModules; unshift @INC, sub {push @usedModules, [@_]; r
+eturn undef;}}

our @usedModules;

...

my $versions = '';
for (@usedModules) {
   my $name = $_->[1];

   $name =~ s/\..*//;
   $name =~ s|[\\/]|::|g;
   
   my $version = eval{eval "\$$name\::VERSION"};
   $versions .= "$name \t$version\n" if defined $version;
}

print $versions;
Replies are listed 'Best First'.
Re: Retrieve list of used modules and their version numbers
by jmcnamara (Monsignor) on Sep 07, 2006 at 11:54 UTC

    Here is a similar one that runs from the command line.
    #!/usr/bin/perl -w use strict; for my $module (@ARGV) { my $version; eval "require $module"; if (not $@) { $version = $module->VERSION; $version = '(unknown)' if not defined $version; } else { $version = '(not installed)'; } printf " %-24s\t%s\n", $module, $version; } __END__ # Sample output. $ perl modver.pl Encode Foo strict Error::Simple Encode 2.10 Foo (not installed) strict 1.03 Error::Simple (unknown)

    --
    John.

Re: Retrieve list of used modules and their version numbers
by Fletch (Chancellor) on Sep 07, 2006 at 12:39 UTC
Re: Retrieve list of used modules and their version numbers
by b10m (Vicar) on Sep 07, 2006 at 12:03 UTC

    And why not give credit to the module authors? See: Acme::Module::Authors (thanks Tatsuhiko ;-)

    --
    b10m

    All code is usually tested, but rarely trusted.
Re: Retrieve list of used modules and their version numbers
by cog (Parson) on Sep 07, 2006 at 16:05 UTC
Re: Retrieve list of used modules and their version numbers
by CardinalNumber (Prior) on Sep 08, 2006 at 15:57 UTC
    Don't forget about perl -d:Modlist script.pl
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://571662]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2016-12-06 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (117 votes). Check out past polls.