Devanchya has asked for the wisdom of the Perl Monks concerning the following question:

hello All,

I feel guilty asking this question because it seems like it should be so simple:
How can I very quickly and easily get all the perl modules on a system and display them on the screen with the version if one is supplied (I'm assuing it would be a call to ::VERSION())

As an added bonus, would I be able to tell easily if they were core or not?

I'm forced to do a rather quick move of a server to a new box and want to ensure that all the specialist modules I've gotten from CPAN and other sources over the year. I know I could just look in each of the INC directories but that seems messy.

--

Even smart people are dumb in most things...
  • Comment on Easiest way to find all the Perl Modules on a system?

Replies are listed 'Best First'.
Re: Easiest way to find all the Perl Modules on a system?
by zentara (Cardinal) on Dec 14, 2006 at 13:45 UTC
    See ExtUtils-Install. The perldoc for ExtUtils::Installed.pm says
    ExtUtils::Installed provides a standard way to find out what core an +d module files have been installed.
    try:
    #!/usr/bin/perl use ExtUtils::Installed; my ($inst) = ExtUtils::Installed->new(); my (@modules) = $inst->modules(); foreach (@modules) { print $_, ' v', $inst->version($_), "\n"; }
    I guess if you specify the directory to search, you can separate the Core modules out.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      That is an elegant solution. I used to use all kinds of find and greps and perl one liners... I have added this to my bashrc. It makes me wonder what else I'm missing. Hrm, except that I see below it doesn't find everything.

      And looking at the src for the package, it'd not be easy to inherit E::I and extend new() to include more dirs — it's just not set up for that. Sad really.

      -Paul

Re: Easiest way to find all the Perl Modules on a system?
by Limbic~Region (Chancellor) on Dec 14, 2006 at 13:49 UTC
    Devanchya,
    See Module Installation Verifier.

    ExtUtils::Installed also has version() so modifying it for your needs shouldn't be difficult. From the docs, it also says

    This returns a list of the names of all the installed modules. The perl 'core' is given the special name 'Perl'

    Module::CoreList keeps track of what version of perl each module became core which may be of some use as well.

    I see zentara beat me to the punch.

    Cheers - L~R

      Beware: ExtUtils::Installed doesn't list all modules.

      I've used Pod::Webserver to display a list of all the modules that are installed in my browser, including any bespoke ones that aren't from CPAN.

      --

      Oh Lord, won’t you burn me a Knoppix CD ?
      My friends all rate Windows, I must disagree.
      Your powers of persuasion will set them all free,
      So oh Lord, won’t you burn me a Knoppix CD ?
      (Missquoting Janis Joplin)

        rinceWind,
        Good to know. It appears demerphq is the current maintainer and there are 15 current bugs in RT.

        Cheers - L~R

Re: Easiest way to find all the Perl Modules on a system?
by monkfan (Curate) on Dec 14, 2006 at 13:41 UTC
    perl -e 'while (<@INC>) { while (<$_/*.pm>) { print "$_\n"; } }'

    Regards,
    Edward
      monkfan,
      Not only does your code not do what was asked for, I think it is broken. I believe both uses of glob in your while loop lead to infinite loops. I can't be sure as I don't have access to perl currently. Update: tye informed me this does work. This is because glob in scalar context doesn't create an iterator, it is an iterator. After re-reading I/O Operators in perlop I realized I was mistaken. I would still recommend spelling out glob over angle brackets to avoid confusion with readline.

      Update 2: I am not sure why, but this still seems odd to me. Perhaps it is because I have less than 30 hours to wait before starting a 3 week vacation. I wonder how the following two examples would behave (i.e. how they are scoped):

      while (my $file = next_file()) { print "$file\n"; } sub next_file { <*> }
      while (my $file = next_file()) { print "$file\n"; my $next = <*>; last if ! defined $next; print "$next\n"; } sub next_file { <*> }

      Cheers - L~R

Re: Easiest way to find all the Perl Modules on a system?
by CountZero (Bishop) on Dec 15, 2006 at 07:27 UTC
    What about the "autobundle" function from the CPAN-module? It will catch most of the modules on your system, with the exception perhaps of those which were not installed through use of the CPAN-module. The docs say "available from CPAN and currently installed within @INC"

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law