Fork me on GitHub

Project Notes

#457 Show Perl Libraries

All about how Perl finds library files, and a simple script to report on include paths and installed modules.

Notes

Perl looks for library files in the paths included in the @INC array.

In addition to default Perl library location, it includes paths added by:

The ExtUtils::Installed module provides a standard way to find out what core and module files have been installed.

Example Script

The show-perl-libs.pl script reports on include paths and installed modules.

#!/usr/bin/env perl
# Show the Perl library paths and installed modules
# Usage: show-perl-libs.pl [-v]
use ExtUtils::Installed;

my $verbose = grep { $_ eq '-v' } @ARGV;

print "PERL5LIB: ", $ENV{'PERL5LIB'};

print "\n\nLIBRARY PATH:\n";
printf "%d %s\n", $i++, $_ for @INC;

print "\nINSTALLED MODULES\n";

# find all the installed modules
my $installed = ExtUtils::Installed->new();

# list modules
foreach my $module ($installed->modules()) {
  my $version = $installed->version($module) || "???";
  print("Found module $module Version $version\n");
  if (!$verbose) {
    next;
  }
  print("  Files:\n");
  foreach my $file ($installed->files($module)) {
    print("    - $file\n");
  }
  print("  Directories:\n");
  foreach my $dir ($installed->directories($module)) {
    print("    - $dir\n");
  }
}

Example Results

Running show-perl-libs.pl:

$ ./show-perl-libs.pl
PERL5LIB:

LIBRARY PATH:
0 /opt/homebrew/opt/perl/lib/perl5/site_perl/5.42/darwin-thread-multi-2level
1 /opt/homebrew/opt/perl/lib/perl5/site_perl/5.42
2 /opt/homebrew/lib/perl5/vendor_perl/5.42/darwin-thread-multi-2level
3 /opt/homebrew/lib/perl5/vendor_perl/5.42
4 /opt/homebrew/opt/perl/lib/perl5/5.42/darwin-thread-multi-2level
5 /opt/homebrew/opt/perl/lib/perl5/5.42
6 /opt/homebrew/lib/perl5/site_perl/5.42

INSTALLED MODULES
Found module Canary::Stability Version 2013
Found module JSON Version 4.11
Found module JSON::XS Version 4.04
Found module Perl Version 5.42.2
Found module Sub::Uplevel Version 0.2800
Found module Test::Simple Version 1.302219
Found module Test::Warn Version 0.37
Found module Types::Serialiser Version 1.01
Found module common::sense Version 3.75

If given a -v parameter, it will print verbose results (with all file and folder details), e.g. ./show-perl-libs.pl -v > verbose-output.txt

A truncated example of verbose-output.txt is as follows:

PERL5LIB:

LIBRARY PATH:
0 /opt/homebrew/opt/perl/lib/perl5/site_perl/5.42/darwin-thread-multi-2level
1 /opt/homebrew/opt/perl/lib/perl5/site_perl/5.42
2 /opt/homebrew/lib/perl5/vendor_perl/5.42/darwin-thread-multi-2level
3 /opt/homebrew/lib/perl5/vendor_perl/5.42
4 /opt/homebrew/opt/perl/lib/perl5/5.42/darwin-thread-multi-2level
5 /opt/homebrew/opt/perl/lib/perl5/5.42
6 /opt/homebrew/lib/perl5/site_perl/5.42

INSTALLED MODULES
Found module Canary::Stability Version 2013
  Files:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Canary/Stability.pm
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3/Canary::Stability.3
  Directories:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Canary
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3
Found module JSON Version 4.11
  Files:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/JSON/backportPP/Compat5005.pm
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/JSON/backportPP/Boolean.pm
    ...
  Directories:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/JSON
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/JSON/backportPP
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3
Found module JSON::XS Version 4.04
  Files:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/darwin-thread-multi-2level/JSON/XS/Boolean.pm
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/darwin-thread-multi-2level/JSON/XS.pm
    ...
  Directories:
    - /opt/homebrew/Cellar/perl/5.42.2/bin
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/darwin-thread-multi-2level/JSON
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/darwin-thread-multi-2level/JSON/XS
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/darwin-thread-multi-2level/auto/JSON/XS
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man1
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3
Found module Perl Version 5.42.2
  Files:
  Directories:
Found module Sub::Uplevel Version 0.2800
  Files:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Sub/Uplevel.pm
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3/Sub::Uplevel.3
  Directories:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Sub
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3
Found module Test::Simple Version 1.302219
  Files:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Test/Tutorial.pod
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3/Test2::EventFacet::Render.3
    ...
  Directories:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Test
    ...
Found module Test::Warn Version 0.37
  Files:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Test/Warn.pm
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3/Test::Warn.3
  Directories:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Test
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3
Found module Types::Serialiser Version 1.01
  Files:
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3/Types::Serialiser::Error.3
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3/Types::Serialiser.3
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Types/Serialiser.pm
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Types/Serialiser/Error.pm
  Directories:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Types
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/Types/Serialiser
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3
Found module common::sense Version 3.75
  Files:
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3/common::sense.3
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/darwin-thread-multi-2level/common/sense.pm
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/darwin-thread-multi-2level/common/sense.pod
  Directories:
    - /opt/homebrew/Cellar/perl/5.42.2/lib/perl5/site_perl/5.42/darwin-thread-multi-2level/common
    - /opt/homebrew/Cellar/perl/5.42.2/share/man/man3

Credits and References

About LCK#457
Perl

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

Project Source on GitHub Return to the LittleCodingKata Catalog
About LittleCodingKata

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

Follow the Blog follow projects and notes as they are published in your favourite feed reader