Module::Locate - locate modules in the same fashion as
use Module::Locate qw/ locate get_source /; add_plugin( locate "This::Module" ); eval 'use strict; ' . get_source('legacy_code.plx');
locate(), return the path that
require would find for a given module or filename (it can also return a filehandle if a reference in
@INC has been used). This means you can test for the existence, or find the path for, modules without having to evaluate the code they contain.
This module also comes with accompanying utility functions that are used within the module itself (except for
get_source) and are available for import.
Given function names, the appropriate functions will be exported into the caller's package.
:all is passed then all subroutines are exported.
The Global and Cache options are no longer supported. See the BUGS section below.
Given a module name as a string (in standard perl bareword format) locate the path of the module. If called in a scalar context the first path found will be returned, if called in a list context a list of paths where the module was found. Also, if references have been placed in
@INC then a filehandle will be returned, as defined in the
require documentation. An empty
return is used if the module couldn't be located.
As of version
1.7 a filename can also be provided to further mimic the lookup behaviour of
When provided with a package name, gets the path using
locate() returned a path, then the contents of that file are returned by
get_source() in a scalar.
Given a scalar, check if it behaves like a filehandle. Firstly it checks if it is a bareword filehandle, then if it inherits from
IO::Handle and lastly if it overloads the
<> operator. If this is missing any other standard filehandle behaviour, please send me an e-mail.
Given a module name, converts it to a relative path e.g
Foo::Bar would become
Note that this path will always use '/' for the directory separator, even on Windows, as that's the format used in
Given a module name, return true if the module has been loaded (i.e exists in the
Given a package name (like
locate()), check if the package has an existing symbol table loaded (checks by walking the
A review of modules that can be used to get the path (and often other information) for one or more modules: http://neilb.org/reviews/module-path.html.
In previous versions of this module, if you specified
Global => 1 when use'ing this module, then looking up a module's path would update
%INC, even if the module hadn't actually been loaded (yet). This meant that if you subsequently tried to load the module, it would wrongly not be loaded.
Bugs are tracked using RT (bug you can also raise Github issues if you prefer):
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.