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

Hi - I have need to maintain software on 2-300 win32 machines. I have Perl prepared for the process but am wondering about the installed modules on each system and how to maintain this. Over time systems will come and go. New machines will need to have the correct 'suite' of PMs installed to work with our tools. Is there a better process than a regular 'require/eval/(call to PPM for missing/upgrade)' for each module? In tests its certainly not a speedy process. Can I work directly with the package 'list' (db? file?) to find out whats there and what needs to be added?

Replies are listed 'Best First'.
Re: discovering installed packages
by bobf (Monsignor) on Jun 05, 2007 at 13:34 UTC

    find out whats there and what needs to be added

    This is a FAQ (or part of it is, anyway): perlfaq3, "How do I find which modules are installed on my system?"

    Nonetheless, it has been asked many times and because TMTOWTDI there are nearly as many different answers. Super Search is your friend. The following results were found using this search:

    Additional links can be found within those threads. Lastly, the section in Tutorials entitled Modules: How to Create, Install, and Use may also be of some use.

    Here are two example scripts that I found floating around my hard drive. The first uses File::Find to locate installed modules (some may advocate the File::Find::Rule interface instead) and the second uses Module::Info to obtain the version and path information for each module. Once you have that information, you can compare it to your list of dependencies.

    Example of File::Find

    use strict; use warnings; use File::Find; my $outfile = 'installed_mods.txt'; open( OUTFILE, '>', $outfile ) or die "error opening $outfile: $!\n"; for( @INC ) { find( \&modules, $_ ); } sub modules { if( -d && /^[a-z]/ ) { $File::Find::prune = 1; return; } return unless /\.pm$/; my $fullPath = "$File::Find::dir/$_"; $fullPath =~ s/\.pm$//; $fullPath =~ s[/(\w+)$][::$1]; print OUTFILE "$fullPath\n"; }

    Example of Module::Info

    use strict; use warnings; use Module::Info; my @mods = Module::Info->all_installed( 'Bit::Vector' ); foreach my $mod ( @mods ) { print join( "\n ", $mod->name, $mod->version, $mod->inc_dir, $mod->file, $mod->is_core ); }

    Update: Added Super Search results

      <caveat>Im a perl noob - and particularly to this board - sorry about hitting a FAQ</caveat> I entered this bit:
      #!/usr/bin/perl -w use ExtUtils::Installed; my $inst = ExtUtils::Installed->new(); my @modules = $inst->modules(); use Data::Dumper; print Dumper(@modules);
      Works great - but why isn't 'extutils' in the list? <edit> Found this thread: http://www.perlmonks.org/?node_id=574615 </edit>
Re: discovering installed packages
by citromatik (Curate) on Jun 05, 2007 at 13:58 UTC
    Hack from Perl Hacks

    Maybe you can create a personal bundle of modules, and then install the Bundle in the rest of machines

    To do this, create an empty package with the modules you want listed in the POD "contents" section

    package Bundle::Personal::Modules 1; __END__ =head1 NAME Bundle::Personal::Modules =head1 SYNOPSIS perl -MCPAN -e 'install Bundle::Personal::Modules' =head1 CONTENTS #Here your modules... Data::Dumper Test::Pod # etc...
    To install the modules in the rest of machines:
    perl -MCPAN -e 'install Bundle::Personal::Modules'

    citromatik

Re: discovering installed packages
by naikonta (Curate) on Jun 05, 2007 at 13:17 UTC
    Have you considered using PAR?

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re: discovering installed packages
by CountZero (Bishop) on Jun 05, 2007 at 20:47 UTC
    On the assumption that all your Windows machines have a similar set-up (i.e. Perl and its modules can be found at the same place), why don't you just simply cut & paste the modules from one machine to another?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James