Day 10: Finding module's path and more (Module::Path::More)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

NEILB's Module::Path is a handy little module (that comes with a handy little utility mpath to find the filesystem path to a locally installed module. It works by iterating @INC, pretty much like require() except it doesn't do coderefs like require().

You can use Module::Path to test whether a certain module is installed, for example. In my case, I'm using it to provide shell tab completion of Perl modules (will be covered in subsequent entry). However, I find it lacking some features. And after waiting for a while (not) getting my patches submitted/rejected, I launched a fork which, after several iterations, eventually called Module::Path::More.

The one thing that I need is the ability to find module prefix in addition to module files. That is, if we have Foo/Bar.pm I want module_path(module=>"Foo", find_prefix=>1) to still return path to Foo/, even though there is no Foo.pm. This is so tab completion still works whether user Fo or Foo or Foo/B.

Module::Path::More can also be used from the command-line, via pmpath.

Another feature that might be useful is to find all modules intead of just returning the first found. Sometimes multiple versions of a module got installed to the same installation, and different ordering of items in @INC can cause an application to see different versions of the module. This I experienced recently: during a Dist::Zilla build Perl::PrereqScanner complained that CPAN::Meta::Requirements' version is too old (2.122, 2.124 needed). But when I checked with pmversion (or mversion) that module is already at 2.130. And cpanm confirmed it when I tried to update it. Turned out there are two copies of the module (because the module is dual-life module, it is bundled with perl but also released separately to CPAN). pmpath -a CPAN::Meta::Requirements shows the problem.

There are also other features that I currently do not use, but nevertheless feel that they should be there (comparing with Module::List), like finding .pmc in addition to .pm files (although I haven't seen anyone using .pmc these days, or ever) and finding .pod.

Leave a comment

About perlancar

user-pic #perl #indonesia