1

While recursing through all of the @INC directories will give you the modules that "Perl knows about", what's the cleanest way to find all of the modules that have been built on a (Linux) system?

codelinguist
  • 41
  • 1
  • 9
  • 3
    Have you read [this](http://perldoc.perl.org/perlfaq3.html#How-do-I-find-which-modules-are-installed-on-my-system%3f)? Try `cpan -l` – Elliott Frisch Jan 17 '14 at 22:13
  • 2
    All of the modules that have been built? Does that include modules built by other users? Modules installed with perlbrew? – ThisSuitIsBlackNot Jan 17 '14 at 22:16
  • @ThisSuitIsBlackNot, this is the crux of the problem. I tried to keep my question focused, but in hindsight did not adequately address the issue: I am a developer with only adequate sa skills that has been tasked to unravel a system that had been driven to the absolute height-of-cruft. There modules everywhere, a paucity of documentation, and a gaping void of SOPs. I ended up having to dump everything scarcely perl-related into a tarball and will be tracing code for the foreseeable future. A classic throw-it-all-out-and-start-from-scratch-is-faster situation... – codelinguist Jan 20 '14 at 22:46

1 Answers1

8

This is a Perl FAQ, i.e. How do I find which modules are installed on my system?, you can find the answer for this question by perldoc -q installed or perldoc perlfaq3 and then search for 'installed'.

Here is a summary of the answer in 'perlfaq3.pod' to this question and some notes about the answer itself according to my test of it:

  1. use cpan on command line:

    cpan -l
    

    Note: You may need to install extra package to use this command, for example, you need to install 'perl-CPAN' in Fedora 19.

  2. use ExtUtils::Installed in a Perl script:

    use ExtUtils::Installed;
    
    my $inst    = ExtUtils::Installed->new();
    my @modules = $inst->modules();
    

    Note: this may not be able to list all the modules installed by your package management system.

  3. use File::Find::Rule to find all the module files:

    use File::Find::Rule;
    
    my @files = File::Find::Rule->
            extras({follow => 1})->
            file()->
            name( '*.pm' )->
            in( @INC )
            ;
    

    Note: this is not a standard module, you may need to install it first.

  4. use File::Find to find all the module files:

    use File::Find;
    my @files;
    
    find(
        {
            wanted => sub {
                push @files, $File::Find::fullname
                    if -f $File::Find::fullname && /\.pm$/
            },
            follow => 1,
            follow_skip => 2,
        },
        @INC
    );
    
    print join "\n", @files;
    
  5. if you know the module name and just want to check whether it exists in your system, you can use the following commands:

    perldoc Module::Name
    

    or

    perl -MModule::Name -e1
    

The following links may also be helpful:

Community
  • 1
  • 1
Lee Duhem
  • 14,695
  • 3
  • 29
  • 47