Re: how to determine whether a module is installed or not?
by tilly (Archbishop) on Dec 28, 2010 at 05:46 UTC
|
Something like this (untested and I am rusty):
eval {require Text::LevenshteinXS};
if ($@) {
eval {require Text::Levenshtein};
else {
require "Levenshtein.lib";
}
}
| [reply] [d/l] |
|
|
| [reply] |
Re: how to determine whether a module is installed or not?
by GrandFather (Saint) on Dec 28, 2010 at 06:01 UTC
|
if (eval {require 'Text/LevenshteinXS.pm'}) {
Text::LevenshteinXS::import('distance');
} elsif (eval {require 'Text/Levenshtein.pm'}) {
Text::Levenshtein::import('distance');
} else {
*distance = \&myDistanceSub;
}
True laziness is hard work
| [reply] [d/l] |
|
|
perl -MFile::Find=find -MFile::Spec::Functions -Tlwe 'find { wanted =>
+ sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'
| [reply] [d/l] |
|
|
That is an extremely inefficient solution.
| [reply] |
Re: how to determine whether a module is installed or not?
by planetscape (Chancellor) on Dec 28, 2010 at 09:40 UTC
|
| [reply] |
|
|
I really liked your list! This is ActiveState specific for their ppm utility, but for those who have ActiveState, it is handy:
$prompt>ppm profile save [my_config_file] (with no file, ouput goes to stdout)
$prompt>ppm profile restore my_config_file
The save option makes an XML file with lines like this:
<SOFTPKG NAME="Text-LevenshteinXS" VERSION="0.03"/>
This file also contains the ppm repositories that I have configured - not everything is at the main ActiveState repository. So if I want to "clone" my installation on another computer or for some reason do a complete re-installation on my own computer, I use the "save" command to a file. Then uninstall Perl, wipe out my Perl directory, re-install ActiveState Perl and then run the "restore" option to get all the packages re-installed. I just walked a friend through this last week and he said that it worked fine.
I think the OP wanted to know what is going on at run time on some other "unknown system", but if we are talking about utilities, I think this is a good one for AS users and I have recent experience that it does indeed "work as advertised".
| [reply] |
|
|
| [reply] |
Re: how to determine whether a module is installed or not?
by samarzone (Pilgrim) on Dec 28, 2010 at 08:30 UTC
|
evaluating (as given in above solutions) is the correct solution at run time but if you want a list of installed modules for a quick reference in future, there is a perl script 'instmodsh' which is shipped with Perl. (At least I have it installed with perl-5.8.8-18.el5 :) ). In my system it is installed at path
/usr/bin/instmodsh so I can run it directly as a shell command.
| [reply] [d/l] [select] |
Re: how to determine whether a module is installed or not?
by k_manimuthu (Monk) on Dec 28, 2010 at 08:50 UTC
|
perl -MModule::Name -e l
If the "Module::Name" installed it doesn't show the error. Otherwise it shows the error.
| [reply] [d/l] |
Re: how to determine whether a module is installed or not?
by ajguitarmaniac (Sexton) on Dec 28, 2010 at 14:26 UTC
|
Checking for similar posts before posting really paid off! I was just about to post the exact same question (but I was looking to find the availability of another module).
Thank you monks!
| [reply] |
Re: how to determine whether a module is installed or not?
by JavaFan (Canon) on Dec 28, 2010 at 16:36 UTC
|
eval {require "Text::LevenshteinXS"; Text::LevenshteinXS->import; 1} o
+r
eval {require "Text::Levenshtein"; Text::Levenshtein->import; 1} or
do {require "Levenshtein.lib"; Levenshtein->import};
| [reply] [d/l] |