CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Get version of all installed modules

 



mmcw2201
User

Dec 29, 2002, 11:30 AM

Post #1 of 13 (1958 views)
Get version of all installed modules Can't Post

How to get all the modules versions of the instaled modules?

I tried the following:


Code
 find(\&wanted,@INC);foreach $mod (@foundmods) { 
chomp $mod;
# Get module version
my $version = module_version($mod);

print "$mod $version\n";
}###################################################################

# subroutine wanted #
###################################################################sub wanted { use File::Find;

if ($File::Find::name =~ /\.pm$/) {
open(MODFILE,$File::Find::name) || return;
while(<MODFILE>) {
if (/^ *package +(\S+);/) {
push (@foundmods, $1);
last;
}
}
}

return @foundmods;
}

##################################################################
# subroutine module_version #
##################################################################

sub module_version {

my $module = shift;
my $output_version;

eval("require $module");

if ($@) {
$output_version = "(Error loading)";
}
else {
# Grap the variable from the symbol table.
# To get something from the sumbol table, you can use a string...
my $version = ${"$module\::VERSION"};
$output_version = "($version)" if (defined $version);
}

return $output_version;
}




When using that code I get an Out of memory! error.

How to get the version numbers of all the installed modules?


davorg
Thaumaturge / Moderator

Dec 29, 2002, 11:39 AM

Post #2 of 13 (1949 views)
Re: [mmcw2201] Get version of all installed modules [In reply to] Can't Post


In Reply To
How to get all the modules versions of the instaled modules?


Try "perldoc perllocal".

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


mmcw2201
User

Dec 30, 2002, 9:35 AM

Post #3 of 13 (1938 views)
Re: [davorg] Get version of all installed modules [In reply to] Can't Post

Could you help me a little bit more?

I do not knw what you mean?


davorg
Thaumaturge / Moderator

Dec 30, 2002, 10:56 AM

Post #4 of 13 (1937 views)
Re: [mmcw2201] Get version of all installed modules [In reply to] Can't Post

If you type "perldoc perllocal" at your command line, you'll get a list of all of the installed CPAN modules together with their version numbers.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


ScriptSolutions
Novice

Dec 30, 2002, 3:49 PM

Post #5 of 13 (1933 views)
Re: [mmcw2201] Get version of all installed modules [In reply to] Can't Post

You can also use the Module::Info module.

Or, you can use [url=http://www.scriptsolutions.com/programs/free/perldiver/index.html]PerlDiver. You can view a list of all modules installed on your server, each linked to details on the module (including version, location, pod, subroutines, dependencies, etc.)

Demo at http://www.scriptsolutions.com/programs/free/perldiver/perldiver.cgi


davorg
Thaumaturge / Moderator

Dec 31, 2002, 2:33 AM

Post #6 of 13 (1927 views)
Re: [ScriptSolutions] Get version of all installed modules [In reply to] Can't Post


In Reply To
You can also use the Module::Info module.

From what I see in the docs, Module::Info needs you to give it a module name - so you still have the problem of finding all of the installed modules first.


In Reply To
Or, you can use [url=http://www.scriptsolutions.com/programs/free/perldiver/index.html]PerlDiver. You can view a list of all modules installed on your server, each linked to details on the module (including version, location, pod, subroutines, dependencies, etc.)

Demo at http://www.scriptsolutions.com/programs/free/perldiver/perldiver.cgi


Isn't Perldiver a CGI app? That means that it's great if what you're talking about is a web server, but there's nothing so far in this thread which indicates that is the case.

(Hmmm.... how about this as an idea for Perldiver - separate the part that gets all of the information about the modules from the part that displays that information. It would then be possible to display the info in various different ways - on a web page, on the console, in a Windows (or X Windows) app, even as a PDF document. What do you think?)

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


mmcw2201
User

Dec 31, 2002, 6:45 AM

Post #7 of 13 (1924 views)
Re: [ScriptSolutions] Get version of all installed modules [In reply to] Can't Post

I tried the link you gave. Works fine but I get an error when clicking the links to the module information!

After clicking: Installed Modules I get an list of all installed modules. Strange is the path list contains d:/apache/home/perldiver/www also?? It is a path on my server!

When cklicking one of the module names it should give the module information. That is where I get an error 500. I the eror log file the following is added:


Code
 Useless use of a constant in void context at Pod2/Html.pm line 858.  
locate: not found
locate: not found
Use of uninitialized value in hash element at perldiver.conf line 225.
Use of uninitialized value in hash element at perldiver.conf line 225.
Use of uninitialized value in join or string at (eval 17) line 16.
perldiver.cgi: no title for /usr/lib/perl5/site_perl/5.6.1/URI/file/Base.pm at Pod2/Html.pm line 225.
perldiver.cgi: error changing to directory /cgi-bin/perldiver: No such file or directory
Useless use of a constant in void context at Pod2/Html.pm line 858.
locate: not found
locate: not found
Use of uninitialized value in hash element at perldiver.conf line 225.
Use of uninitialized value in hash element at perldiver.conf line 225.
Can't stat d:/apache/home/perldiver/www: No such file or directory
Use of uninitialized value in concatenation (.) or string at perldiver.cgi line 218, line 7933.
Use of uninitialized value in join or string at (eval 13) line 16, line 7933.
Use of uninitialized value in concatenation (.) or string at perldiver.cgi line 218, line 7933.
Use of uninitialized value in join or string at (eval 13) line 16, line 7933.
Useless use of a constant in void context at Pod2/Html.pm line 858.
locate: not found
locate: not found
Use of uninitialized value in hash element at perldiver.conf line 225.
Use of uninitialized value in hash element at perldiver.conf line 225.
perldiver.cgi: error changing to directory /cgi-bin/perldiver: No such file or directory


What is wrong?


(This post was edited by mmcw2201 on Dec 31, 2002, 6:45 AM)


mmcw2201
User

Dec 31, 2002, 6:49 AM

Post #8 of 13 (1922 views)
Re: [davorg] Get version of all installed modules [In reply to] Can't Post

This code will give me the list of all the modules installed.


Code
   

find(\&wanted,@INC);

sub wanted {

use File::Find;

if ($File::Find::name =~ /\.pm$/) {
open(MODFILE,$File::Find::name) || return;
while(<MODFILE>) {
if (/^ *package +(\S+);/) {
push (@foundmods, $1);
last;
}
}
}

return @foundmods;
}



But how to use the module::Info module to get the module version information. I played around a little bit but did not got it to work! Coudl zou help me?


ScriptSolutions
Novice

Dec 31, 2002, 8:15 AM

Post #9 of 13 (1918 views)
Re: [davorg] Get version of all installed modules [In reply to] Can't Post


Quote
Isn't Perldiver a CGI app? That means that it's great if what you're talking about is a web server, but there's nothing so far in this thread which indicates that is the case.

Yes, PerlDiver is a CGI app. I didn't know where he needed to use the code -- at the very least I thought he could look at PerlDiver's code and grab what he needed to look at the module info.


Quote
separate the part that gets all of the information about the modules from the part that displays that information

Sounds like a winner. What do you think about just creating a module that handles the module details? Then Perldiver and any other program can use it.


ScriptSolutions
Novice

Dec 31, 2002, 8:22 AM

Post #10 of 13 (1917 views)
Re: [mmcw2201] Get version of all installed modules [In reply to] Can't Post


Quote
Strange is the path list contains d:/apache/home/perldiver/www

I don't see how that happened. I tested it on WinXP and use'd lib, but removed that line before creating the distribution. I just double-checked and the file in the distribution doesn't contain any reference (other than a comment) to that path. Could you please make sure that you downloaded perldiver.zip and perhaps not an older version?

Can you please email [url=mailto:programmer@scriptsolutions.com ]programmer@scriptsolutions.com so we can figure out what's wrong? (Please attach a copy of your perldiver.cgi and perldiver.conf). It looks like that odd reference to a Win path is throwing it off.


ScriptSolutions
Novice

Dec 31, 2002, 8:25 AM

Post #11 of 13 (1916 views)
Re: [mmcw2201] Get version of all installed modules [In reply to] Can't Post

After running that code, all modules are in @found.

From there, you can do something like:


Code
 foreach my $module ( @found ){ 

my $mod = Module::Info->new_from_module( $module );

print "Name: $module Version: " . $mod->version;

}



mmcw2201
User

Dec 31, 2002, 11:54 PM

Post #12 of 13 (1911 views)
Re: [ScriptSolutions] Get version of all installed modules [In reply to] Can't Post

The part: d:/apache/home/perldiver/www is not found in perldiver.cgi or perldiver.conf but in the directory Module in the file Info.pm


ScriptSolutions
Novice

Jan 1, 2003, 10:07 AM

Post #13 of 13 (1904 views)
Re: [mmcw2201] Get version of all installed modules [In reply to] Can't Post

Thanks -- I missed that one. Removed from the distribution.

I just replied to your email...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives