PDA

View Full Version : programmed checking if a module is installed


oesxyl
06-15-2008, 03:40 PM
hi,

I want to check if a module is installed. This is the sub I use:


sub checkinstalled {
my $m = shift;
my $v = `$^X -M$m -e 1`;
return 'installed' if $v eq '';
return 'not installed';
}


the problem is that if $v is not '' it produce a server error 500 and stop execution for the rest of the script.
I want to avoid to install other modules from CPAN to do that therefor I need a simple solution using a standard perl installation on a server.
the question is how I can avoid server error 500?

regards

FishMonger
06-15-2008, 06:06 PM
Try wrapping it in an eval block.

Another option would be to use File::Find and search the @INC directories.

oesxyl
06-15-2008, 06:28 PM
Try wrapping it in an eval block.
I will try eval, probably I must use a BEGIN block to eval at compile. I will post results of the tests.

Another option would be to use File::Find and search the @INC directories.
two of this modules are perls binding using swig and maintained by somebody else. I prefere to avoid a situation when I have a pm file installed but not a shared library used by it.

thank you and regards

oesxyl
06-15-2008, 09:10 PM
solved this way for perl modules and work correctly this time:


sub checkinstalled {
my $m = shift;
my $v = `$^X -M$m -e '1;'`;
return 'installed' if $? eq 0';
return 'not installed';
}


I still have a problem with checking shared library but is obvious that is wrong to check this way because is not a perl module.


print checkinstalled('XML::LibXML'),"<br/>"; # ok, this work
print checkinstalled('libxml2'),"<br/>"; # wrong


Any idea how to check if libxml2 is installed? XML::LibXML depends on libxml2.

regards