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

Lo, I have a directory '/other/perlmodsrc/tars' that contains all the cpan modules my system needs, including the dependencies. There are 94 modules and installing them by hand is a little tedious. Is there any way to automate it? I could knock up a perl script to do each one via a shell, but that is very inelegant. What I'm after is the CPAN shell, only without CPAN and without the shell :) John

Replies are listed 'Best First'.
Re: automating install of perl modules
by Corion (Patriarch) on Jun 11, 2008 at 10:47 UTC

    My approach is to create a bundle module which lists all the modules to be installed, and then to install that bundle through CPAN:

    package Bundle::WWW::Mechanize::Shell; $VERSION = '0.29'; 1; __END__ =head1 NAME Bundle::WWW::Mechanize::Shell - install all optional modules for WWW:: +Mechanize::Shell =head1 SYNOPSIS cpan Bundle::WWW::Mechanize::Shell =head1 CONTENTS WWW::Mechanize::Shell Test::Inline - for extended testing Pod::Constants - for the online help ...

    A different approach is to package your application as a CPAN distribution as well, and have it list all the required modules as prerequisites as well.

Re: automating install of perl modules
by marto (Cardinal) on Jun 11, 2008 at 10:49 UTC
    I am not sure if this will help, but you may get away with using CPAN to create an autobundle which you can use to install all of these modules. I mention this here, along with some other posts on this topic that may be of interest to you.

    Hope this helps

    Martin
Re: automating install of perl modules
by phillipo (Novice) on Jun 11, 2008 at 13:58 UTC
    CPAN supports a native offline mode, which recommends doing it from a copy of the ~/.cpan/sources directory.

    Once you've taken a copy, you can then install all files under it like this:

    % find authors/ | grep -e "/id/.*\.gz" | perl -MCPAN -MCPAN::Config -n + -e '$CPAN::Config->{keep_source_where} = "/other/perlmodsrc/tars"; c +homp; @f = split /\//; $mod = join("/", splice @f, -2, 2); CPAN::Shel +l->install($mod);'

    I have created one of these directories using only the ~/.cpan/sources/authors and not the ~/.cpan/sources/modules directory successfully, but CPAN seems to update them automatically.

    I've also created one by creating a /somepath/cpan/authors/id/A/AL/ALL directory, and copying all the files into there, but that mucks up dependancies.

    So, if you're happy enough to build the correct directory structure, and to copy in a recent ~/.cpan/sources/modules directory, and don't mind if CPAN does connect and maybe update those module definition files, then this should be a workable solution.

    If you're worried about network connectivity or newer versions of modules coming available, then you could try hacking through PAUSE (mldistwatch specifically) to grab the file generator code, and auto-generate your 02packages.details.data.gz and 03modlist.data.gz which should allow the rest to work nicely.

    Other ways would be to write a script to extract each tar, enter the directory, do a make and make install, then to go back and do a make test on each directory - this would nicely skip the dependancy issues.
      One further thought in relation to this:
      I've also created one by creating a /somepath/cpan/authors/id/A/AL/ALL directory, and copying all the files into there, but that mucks up dependancies.
      I just went a little further on this - if you recreate the 02packages.details.txt.gz file with the correct path in the 3rd field (i.e, change to A/AL/ALL/<module.tar.gz>), and then wipe the Metadata in ~/.cpan, it figures out the dependancies properly and grabs them from the local cache - that would alleviate having to create the correct directory structure, and it also shows that 02packages.details.txt.gz is the key file to ensure is consistent.
Re: automating install of perl modules
by alexm (Chaplain) on Jun 11, 2008 at 17:38 UTC

    You might want to take a look to brian_d_foy's Building My Own CPAN.

    The presentation explains how to...

    • use CPAN-Mini to get a copy of the latest modules available on CPAN (currently less than 900MB),
    • filter out some dists or modules (by name or auhtor),
    • inject other dists or modules not available on CPAN by using CPAN::Mini::Inject,
    • and even include obsolete stuff from BackPAN.

    However, the quick answer to your question maybe is in slides 23 and 34:

    CPAN::Shell->o( qw( conf urllist unshift ), $where_i_found_cpan, );

    Where $where_i_found_cpan (e.g. file:///MINICPAN) is a directory containing the typical CPAN structure with:

    • authors/id/A/AB/ABC/...
    • modules/...

    HTH

    Update: Added an example for $where_i_found_cpan using the file:///... prefix.

Re: automating install of perl modules
by Bloodnok (Vicar) on Jun 11, 2008 at 15:13 UTC
    In a previous incarnation, I persuaded make to do almost the same thing as you require - AFAIR, it was along the lines of ...
    MODULES = module-a-1.0 module-b-1.1 all: perl -e '\ foreach ((qw/$(MODULES)/)) {\ chdir($$_) or die("chdir($$_) failed - $$!");\ system("perl Makefile.PL");\ system("$(MAKE) test install");\ }\ '

    • As the host machine was air-gapped from the intraweb, direct installation from CPAN wasn't an option - hence all modules had previously been downloaded.
    • I was lucky in as much as all the modules I required used the Makefile.PL method of creation.
    • I used perl in the make script since this was written for use on a Windoze machine.

    HTH

    At last, a user level that best describes my experience :-))
Re: automating install of perl modules
by bingos (Vicar) on Jun 12, 2008 at 09:07 UTC
      Thank you all for your time. I've got plenty to be going on with there.