Module::Path(3)
π Module::Path(3) π
okay so you're looking at the Module::Path page from the User Contributed Perl Documentation β yes, that one. buckle up bestie π
β¨ NAME β¨
Module::Path β literally just gets you the full path to a locally installed module. that's it. that's the whole gig π
πΈ SYNOPSIS πΈ
like, here's the vibe:
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";
}
the Danger Will Robinson! branch is doing a LOT of emotional labor and honestly? iconic π
π¦ DESCRIPTION π¦
so this module gives you exactly one function, module_path(), and what it does is: you hand it a module name, it goes digging through your @INC path and finds the first directory where that module is installed locally. then it hands you the full path to that file, symlinks all resolved and everything. it's portable, and it only depends on core modules β lowkey a flex ngl π«Ά
how does the magic happen? it's just vibing through all the directories in @INC looking for a file with the right name:
Foo::Barbecomes"Foo/Bar.pm", and it uses the correct directory path separator for whatever OS you're on. cross-platform princess behavior β¨- it iterates over
@INC, and it ignores any references it finds in there. (if you're like "wait, references in@INC??" β go read"require"in"perlfunc", it's a whole thing.) - for every directory in
@INC, it appends the partial path ("Foo/Bar.pm"), again with the correct directory path separator. if that resulting file exists β boom, it returns that path π₯ - if a directory in
@INCis a symlink, it resolves the path and gives you back a path containing the linked-to directory. no fake paths here π§ - if literally nothing was found? it returns
undef. sad girl hours π
so why does this module even exist, you ask? the author wrote it because they couldn't find an alternative that dealt with all the points listed above and didn't drag in what felt like way too many dependencies. relatable. minimal queen behavior π
the Module::Path distribution also ships the mpath script, so you can get a module's path straight from the command line:
% mpath Module::Path
and plot twist β module_path() also copes if your module name already includes .pm. which means you can pass a partial path, like the ones used as the keys in %INC:
module_path('Test/More.pm') eq $INC{'Test/More.pm'}
bestie that line above is literally the basis for one of the tests. we love a self-aware king π«Ά
π BUGS π (the caveats, not the haters)
- obviously this only works when the module you're after has its own
.pmfile. if one file defines multiple packages, this approach will not work. it's giving "structural limitation", periodt. - it also will not find any modules that get loaded in some special way β for example using a code reference in
@INC, as described in"require"in"perlfunc". no cap, that's just not what this does π
π SEE ALSO π
there are like a BUNCH of other CPAN modules doing the same or similar thing, and we're listing every single one because thoroughness is the moment: 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. go wild π
the author also wrote a whole review of every such module they're aware of:
<http://neilb.org/reviews/module-path.html>
Module::Path was written to be fast, portable, and to have a low number of core-only runtime dependencies. so if all you want is to look up the path to a module β it's a good choice. simple as that β¨
but if you want more info, like the module's version, what functions it provides, etc., then start by looking at Module::Info, Module::Metadata, and Class::Inspector. those are the girlies for the deep lore π
also, these scripts can give you the path too: perldoc, and whichpm <https://www.metacpan.org/module/whichpm>. two more tools in the toolbox, we love to see it π
π§ REPOSITORY π§
<https://github.com/neilbowers/Module-Path> β go star it, tell 'em I sent you β
π AUTHOR π
Neil Bowers <neilb@cpan.org> β legend behavior, honestly π«Ά
π 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. fr fr, go off π
okay bestie that's the whole page, you're officially a Module::Path expert now π
β¨
this lil recap comes to you courtesy of perl v5.42.0, dated 2015-04-13 β and that's the Module::Path(3) tea, served fresh πΈπ¦π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Module-Path 0.19-bp160.1.12 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms