How can I determine if a Perl module is core or part of a standard installation?

How to check if the Perl module is part of the kernel - that is, it is part of the standard installation?

I'm looking for:

  • command line command:
  • Perl routine / function for checking inside code

Perhaps the question should be this: how can I find out which modules were originally provided with a specific Perl installation on the machine? (Actually, he is now being asked how How can I find out which modules were originally provided with a specific Perl installation on the machine?

Given that now, it seems, there will be no standard Perl standard installation, at least the answer to this new question will tell me what I originally had during the installation when it was first installed.

With this knowledge, and if I save the original installer image / package or find out how to get accurate information on the Internet again, then I have a repeated installation of Perl for several machines taking into account which modules will be present and which modules will not.

To clarify further: I look at what was originally with the installation, which modules were provided as part of this installation, and what was built in. NOT what has been installed since.

And I want this to be possible on a machine with an installed installation. Therefore, for this I will rely on the installation in order to have a record in one form or another regarding what it was originally from.

I asked the question: How can I find out which modules were originally provided with a specific Perl installation on the machine? (How can I find out which modules were originally provided using a specific Perl installation on a machine?)

+44
module perl standard-library
Jan 12
source share
7 answers

The corelist command from Module :: CoreList will determine if the 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. Module::CoreList POD is too brief - you need to go hunting through the source code to find which 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 
+52
Jan 12
source share

Actually there is no such thing as a โ€œcoreโ€. There used to be a standard Perl distribution, but many people don't have a standard Perl distribution. Operating system distributions change it by adding or removing modules, changing modules, etc. You cannot rely on a standard distribution, which is actually a standard distribution. Some Linux distributions do not even include Perl documentation as part of a basic Perl installation.

You mentioned that you cannot use Module :: CoreList because it is not the core, but if you can create files, you can install the module. You can even pretend you wrote it yourself.

+7
Jan 13 '10 at 14:21
source share

You can check perlmodlib in 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 : (); } 

Usage example:

 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 most definitely part of the true kernel and standard Perl installation. For example, the source distribution for perl-5.10.1 contains

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

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

Settings that do not contain these elements are non-standard. Yes, I appreciate that this may seem academic from your point of view, but your vendorโ€™s packaging allowed a non-standard installation that disrupts other programs.

With the Debian package manager, you can get a standard Perl installation using

  $ apt-get --install-recommends install perl 
+6
Jan 12 '10 at 15:40
source share

For the really lazy, List the core modules at perldoc.perl.org.

+3
Jan 12
source share

You can use (e.g. search for Net::FTP ):

 perl -MNet::FTP -e 1 

If it has no way out, it is installed.

Other resources

 perldoc perlmodlib perldoc perllocal 

A node by perlmonks

+1
Jan 12
source share
  • From the command line:

    Say you want to know if the Tie::Hash module is installed.
    To find out, run from the command line:

     perl -MTie::Hash -e 1 

    If you do not get any output from the above command, then the module will be installed; if you get an error message, it is not installed.

  • To perform this check from a script, you can use Module :: Load :: Conditional .

0
Jan 12
source share

In response to Gbacon's comment, you say you want the answer to be a neutral platform. I do not know such a solution, but I am interested, even if this is the right way.

If you want to know on specific machines, I would use the tools that come with the platform. Debian, which will include dpkg (pre-installed on any Debian system) or apt-file (not pre-installed) or other APT tools.

As an example, consider the output of this:

 dpkg-query -L perl | less 

Obviously, you will need to make out the conclusion, but it puts me as the beginning precisely because it is specific to the machine in question.

0
Jan 16
source share



All Articles