lib_file#

Say under which path this interpreter sees a library file.

Synopsis#

use Config;
my $path = Config::lib_file("strict.pm");
my $path = Config::lib_file("ExtUtils/typemap");
my $path = Config::lib_file("Foo/Bar.pm", \@dirs);

What you get back#

The path of the file a require of that name would load, or undef when there is none. The name is a path below a library directory, with / between the parts, as in %INC. The path can be opened.

A file that is part of the pperl binary is found first and reported under $Config{privlibexp}, the directory that holds the binary’s library: nothing elsewhere can take its place. Any other file is looked for in each directory of @INC in turn, and the first one that exists and is not a directory is reported.

With a second argument, a reference to an array of directories, those are searched in place of @INC. The pperl binary’s own files count only when $Config{privlibexp} is among them.

A built-in module written in Rust has no Perl source. Opened under the path reported here it reads as three lines: its package, its $VERSION and a true value.

Why it exists#

Perl’s own way of asking is to walk @INC with -e or -r and take the first hit. That walk works on pperl too, but the first file test of the binary’s library writes it to disk, and a walk cannot see that a built-in module wins over a copy in an earlier directory. A tool that must know where a module is, or which version would be loaded, asks here, and nothing is written.

Examples#

use Config;
use ExtUtils::MakeMaker ();
my $file = Config::lib_file("List/Util.pm");
print MM->parse_version($file), "\n" if defined $file;