Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if a Perl module is core or part of the standard install?

People also ask

How do I tell what Perl modules are installed?

Check installed perl modules via terminal Available commands are: l - List all installed modules m <module> - Select a module q - Quit the program cmd? Then type l to list all the installed modules, you can also use command m <module> to select the module and get its information. After finish, just type q to quit.

How do I check if a Perl library is installed on Linux?

You need to use instmodsh (interactive inventory for installed Perl modules) command to find out what modules already installed on my system. instmodsh command provides an interactive shell type interface to query details of locally installed Perl modules.

What is the difference between package and module in Perl?

A Perl package is a collection of code which resides in its own namespace. Perl module is a package defined in a file having the same name as that of the package and having extension . pm. Two different modules may contain a variable or a function of the same name.


The corelist command from the Module::CoreList module will determine if a module is Core or not.

> corelist Carp

Carp was first release with perl 5

> corelist XML::Twig

XML::Twig was not in CORE (or so I think)

Here is one way to use it in a script. The Module::CoreList POD is too terse -- you have to go hunting through the source code to find what methods to call:

use strict;
use warnings;
use Module::CoreList;

my $mod = 'Carp';
#my $mod = 'XML::Twig';
my @ms = Module::CoreList->find_modules(qr/^$mod$/);
if (@ms) {
    print "$mod in core\n";
}
else {
    print "$mod not in core\n";
}

__END__

Carp in core

You could check perlmodlib in a sub:

my %_stdmod;
sub is_standard_module {
  my($module) = @_;

  unless (keys %_stdmod) {
    chomp(my $perlmodlib = `perldoc -l perlmodlib`);
    die "cannot locate perlmodlib\n" unless $perlmodlib;

    open my $fh, "<", $perlmodlib
      or die "$0: open $perlmodlib: $!\n";

    while (<$fh>) {
      next unless /^=head\d\s+Pragmatic\s+Modules/ ..
                  /^=head\d\s+CPAN/;

      if (/^=item\s+(\w+(::\w+)*)/) {
        ++$_stdmod{ lc $1 };
      }
    }
  }

  exists $_stdmod{ lc $module } ? $module : ();
}

Example usage:

die "Usage: $0 module..\n" unless @ARGV;

foreach my $mod (@ARGV) {
  my $stdmod = is_standard_module $mod;
  print "$0: $mod is ", ($stdmod ? "" : "not "), "standard\n";
}

Output:

$ ./isstdmod threads::shared AnyDBM_File CGI LWP::Simple
./isstdmod: threads::shared is standard
./isstdmod: AnyDBM_File is standard
./isstdmod: CGI is standard
./isstdmod: LWP::Simple is not standard

perldoc is most definitely part of the Perl's true core and standard installation. The source distribution for perl-5.10.1, for example, contains

  • perldoc.PL, generates perldoc as part of the standard installation
  • perlmodlib.PL, generates perlmodlib.pod as part of the standard installation

This is not a new addition. Perl-5.6.0, about ten years old, had perlmodlib as part of its true-core, standard installation.

Installations that do not contain these items are non-standard. Yes, I appreciate that it may seem academic from your perspective, but your vendor's packaging permitted a non-standard installation that breaks otherwise working programs.

With Debian's package manager, you can get the standard Perl installation with

$ apt-get --install-recommends install perl

There really is no such thing as "core" any more. There used to be a standard Perl distribution, but a lot of people don't have a standard Perl distribution. Operating system distributions modify it by either adding or removing modules, changing modules, and so on. You can't rely on the standard distribution being actually standard. Some Linux distributions don't even include the Perl documentation as part of the base Perl installation.

You mention that you can't use Module::CoreList because it isn't core, but if you can create files, you can install the module. You can even pretend that you wrote it yourself.


For the really lazy, there's the Core Modules list on the perldoc.perl.org website.


You can use (for example, search for Net::FTP):

perl -MNet::FTP -e 1

If it doesn't have output, then it's installed.

Other resources

perldoc perlmodlib 
perldoc perllocal

A node from perlmonks