How can I get the version and location of the installed Perl module?

Is there any reasonable way to determine if a specific Perl module is installed on your system? My old sutpid way to write a Perl script in which the only thing I do is just use a module. If nothing is dug up when running the script discovery, I know that the module is installed, although I still donโ€™t know which version and where the module was installed.

early.

+5
module perl
Dec 17 '09 at 7:27
source share
9 answers

Something like:

perl -MModule -e 'print "$Module::VERSION\n"' 2>/dev/null || echo "Not installed" 

will provide you with a version of this module or inform you that it is not installed. Usage will look like this:

 perl -MXML::Parser -e 'print "$XML::Parser::VERSION\n"' 2>/dev/null || echo "Not installed" 

To find the path to the module, you can examine @INC to find possible locations, or you could take a look at perlwhich . There is also pmpath from pmtools .

+9
Dec 17 '09 at 7:38
source share

The shortest thing I know about this does not include a script or shell alias:

 $ perl -MFoo::Bar\ 99 Foo::Bar version 99 required--this is only version 1.234. 

(or the usual message that it is not in @INC if it is not installed)

For the curious, this is the same as perl -e 'use Foo::Bar 99' .

+5
Dec 18 '09 at 15:50
source share

instmodsh

 NAME instmodsh - A shell to examine installed modules SYNOPSIS instmodsh DESCRIPTION A little interface to ExtUtils::Installed to examine installed modules, validate your packlists and even create a tarball from an installed module. SEE ALSO ExtUtils::Installed 
+3
Dec 17 '09 at 7:45
source share

Here is the program that does this:

 #!/usr/bin/perl # testmod - test to see if a module is available use strict; use warnings; my $mod = (shift @ARGV) || die "usage: $0 module\n"; # convert module-name to path my $file = $mod; $file =~ s{::}{/}gsmx; $file .= '.pm'; # Pull in the module, if it exists eval { require $file } or die "can't find module $mod\n"; # Get the version from the module, if defined my $ver; { no strict 'refs'; $ver = ${$mod . "::VERSION"} || 'UNKNOWN'; } # And its location my $from = $INC{$file}; print "module $mod is version $ver loaded from $from\n"; 
+3
Mar 22 '10 at 14:12
source share

Use pmvers . Like the name, it shows the version of the installed module. If the module is not installed, it crashes with a known error message: Can't locate โ€ฆ in @INC (@INC contains: โ€ฆ)

Use pmpath from the same distribution to find the installation path of the module.

+2
Dec 17 '09 at 9:30 a.m.
source share

I donโ€™t know if there is any smart way for this. But what I usually do is use the '-l' or '-m' perldoc option. For example:

%perldoc -l XML::Simple

and the output is something like below, this is the full path to the module file

 .../lib/XML/Simple.pm 

code> The advantage of this approach compared to yours is that if the module is installed, the output contains a path for the location of the module. However, when the module is not installed
or if it does not have perldoc, then the error message says "Documentation not found for ..." ,
which makes it impossible to distinguish whether the error is due to a lack of a module or missing documentation. In this case, the -m option becomes convenient, since it prints the entire file the contents of the file along with the path.

+1
Dec 17 '09 at 7:47
source share

I use these bash / Perl oneliners functions to find the version number and location of Perl modules:

 # equivalent to perldoc -l <module> perlwhere() { perl -wle'eval "require $ARGV[0]" or die; ($mod = $ARGV[0]) =~ s|::|/|g; print $INC{"${mod}.pm"}' $1 } perlversion() { perl -M$1 -wle'print $ARGV[0]->VERSION' $1 } : [ether ~].2$; perlwhere Test::More /usr/lib/perl5/5.8.8/Test/More.pm : [ether ~].2$; perlversion Test::More 0.94 
+1
Dec 17 '09 at 17:37
source share

pmvers , and other pmtools will do what you need. Otherwise, this is a single line file to find the module version:

 perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Some::Module 
+1
Dec 18 '09 at 14:38
source share

If you are looking for a cross-platform CLI (Linux, OSX, Windows), consider my whichpm utility ; eg:.

 # Locate the Data::Dumper module, and also print # version information and core-module status. $ whichpm -v Data::Dumper Data::Dumper 2.145 core>=5.005 /usr/lib/perl/5.18/Data/Dumper.pm 

It can also detect random duplicates and list all installed modules.

If you have Node.js / io.js installed, you can install it from the npm registry:

 [sudo] npm install whichpm -g 

Manual installation instructions and more see repo ; here is a direct link to the link the latest version (will remain relevant).

0
Sep 02 '15 at 14:38
source share



All Articles