How can I find out where a Perl module is installed?
Mostly I use perldoc
to get a location:
$ perldoc -l Module
You can also get module details with the cpan
tool that comes with Perl:
$ cpan -D Time::HiRes
Time::HiRes
-------------------------------------------------------------------------
High resolution time, sleep, and alarm
J/JH/JHI/Time-HiRes-1.9719.tar.gz
/usr/local/perls/perl-5.10.0/lib/5.10.0/darwin-2level/Time/HiRes.pm
Installed: 1.9711
CPAN: 1.9719 Not up to date
Andrew Main (Zefram) (ZEFRAM)
[email protected]
It even works on modules that you haven't installed:
$ cpan -D Win32::Process
Win32::Process
-------------------------------------------------------------------------
Interface to Win32 Process functions
J/JD/JDB/Win32-Process-0.14.tar.gz
Installed:
CPAN: 0.14 Not up to date
Jan Dubois (JDB)
[email protected]
I think maybe I need an XML option like svn.
perl -MTime::HiRes -e 'print $INC{"Time/HiRes.pm"}'
or perldoc -l Time::HiRes
Note: This solution proposes use of a (self-authored) utility that you must download. While it offers what I believe to be helpful features, installing a third-party solution first is not an option for everyone.
I've created whichpm
, a cross-platform CLI (Linux, macOS, Window) that locates installed Perl modules by module (package) name, and optionally reports information about them, including detection of accidental duplicates.
Examples
# Locate the Data::Dumper module.
$ whichpm Data::Dumper
/usr/lib/perl/5.18/Data/Dumper.pm
# 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
# Locate the Data::Dumper module and open it in your system's default text
# editor.
$ whichpm -e Data::Dumper
# Look for accidental duplicates of the Foo::Bar module.
# Normally, only 1 path should be returned.
$ whichpm -a Foo::Bar
/usr/lib/perl/5.18/Foo/Bar.pm
./Foo/Bar.pm
# Print the paths of all installed modules.
$ whichpm -a
Installation
Prerequisites: Linux, macOS, or Windows, with Perl v5.4.50 or higher installed.
Installation from the npm registry
With Node.js or io.js installed, install the package as follows:
[sudo] npm install whichpm -g
Manual installation (macOS and Linux)
- Download the CLI as
whichpm
. - Make it executable with
chmod +x whichpm
. - Move it or symlink it to a folder in your
$PATH
, such as/usr/local/bin
(OSX) or/usr/bin
(Linux).