codelinguist
codelinguist

Reputation: 51

Getting the full set of installed Perl modules

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?

Upvotes: 2

Views: 10749

Answers (1)

Lee Duhem
Lee Duhem

Reputation: 15121

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:

Upvotes: 8

Related Questions