GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MODULE::PATH (3)

.ds Aq ’

NAME

Module::Path - get the full path to a locally installed module

CONTENTS

SYNOPSIS



 use Module::Path module_path;

 $path = module_path(Test::More);
 if (defined($path)) {
   print "Test::More found at $path\n";
 } else {
   print "Danger Will Robinson!\n";
 }



DESCRIPTION

This module provides a single function, module_path(), which takes a module name and finds the first directory in your @INC path where the module is installed locally. It returns the full path to that file, resolving any symlinks. It is portable and only depends on core modules.

It works by looking in all the directories in @INC for an appropriately named file:
o Foo::Bar becomes Foo/Bar.pm, using the correct directory path separator for your operating system.
o Iterate over @INC, ignoring any references (see require in perlfunc if you’re surprised to hear that you might find references in @INC).
o For each directory in @INC, append the partial path (Foo/Bar.pm), again using the correct directory path separator. If the resulting file exists, return this path.
o If a directory in @INC is a symlink, then we resolve the path, and return a path containing the linked-to directory.
o If no file was found, return undef.
I wrote this module because I couldn’t find an alternative which dealt with the points listed above, and didn’t pull in what seemed like too many dependencies to me.

The distribution for Module::Path includes the mpath script, which lets you get the path for a module from the command-line:



 % mpath Module::Path



The module_path() function will also cope if the module name includes .pm; this means you can pass a partial path, such as used as the keys in %INC:



  module_path(Test/More.pm) eq $INC{Test/More.pm}



The above is the basis for one of the tests.

BUGS

Obviously this only works where the module you’re after has its own .pm file. If a file defines multiple packages, this won’t work.

This also won’t find any modules that are being loaded in some special way, for example using a code reference in @INC, as described in require in perlfunc.

SEE ALSO

There are a number of other modules on CPAN which provide the same or similar functionality: App::whichpm, Class::Inspector, Module::Data, Module::Filename, Module::Finder, Module::Info, Module::Locate, Module::Mapper, Module::Metadata, Module::Runtime, Module::Util, and Path::ScanINC.

I’ve written a review of all such modules that I’m aware of:

<http://neilb.org/reviews/module-path.html>

Module::Path was written to be fast, portable, and have a low number of core-only runtime dependencies. It you only want to look up the path to a module, it’s a good choice.

If you want more information, such as the module’s version, what functions are provided, etc, then start by looking at Module::Info, Module::Metadata, and Class::Inspector.

The following scripts can also give you the path: perldoc, whichpm <https://www.metacpan.org/module/whichpm>.

REPOSITORY

<https://github.com/neilbowers/Module-Path>

AUTHOR

Neil Bowers <neilb@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Neil Bowers <neilb@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MODULE::PATH (3) 2015-03-16

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.