Skip to content

Instantly share code, notes, and snippets.

@sullust
Created September 1, 2012 05:33
Show Gist options
  • Save sullust/3564649 to your computer and use it in GitHub Desktop.
Save sullust/3564649 to your computer and use it in GitHub Desktop.
Automating CPAN across a network
CPAN is an excellent tool, but the system has its limitations. One major drawback is that it's a single-system solution, which is fine if you want to manage your Perl installations on a single-computer basis. But if you have a set of Perl modules spread across your Web server farm or even across your lab on a range of platforms, trying to keep up to date across all the computers can be a time-consuming process -- even if you use the automation techniques I discussed above.
CPAN also consumes a lot of Internet bandwidth in that for each computer on which you use CPAN, CPAN expects to download a copy of the files from one of the central CPAN repositories. CPAN also relies on a configuration that has to be tailored to each computer: You can copy a configuration file, which resides in /perlinstalldirectory/CPAN/Config.pm, only if you can configure your platforms identically.
An obvious route to take when using CPAN is to use the autobundle function. This function generates a list of every installed module in a Perl installation, then dumps the list into a format that you can execute to re-install the selection either on the same computer (after an update to the latest Perl version) or onto another computer. The code in Listing 2 shows you how to create a new bundle.
Listing 2. Code to create a CPAN autobundle
$ perl -MCPAN -e autobundle
...
Package namespace installed latest in CPAN file
AnyDBM_File 1.00 1.00 N/NW/NWCLARK/perl-5.8.5.tar.gz
Apache::ASP 2.57 2.57 C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
Apache::ASP::ApacheCommon undef undef C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
Apache::ASP::Application undef undef C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
Apache::ASP::CGI undef undef C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
Apache::ASP::CGI::Table undef undef C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
Apache::ASP::CGI::Test undef undef C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
Apache::ASP::Collection undef undef C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
Apache::ASP::CollectionItem undef undef C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
Apache::ASP::Date undef undef C/CH/CHAMAS/Apache-ASP-2.57.tar.gz
...
Wrote bundle file
/export/build/solaris/cpan/Bundle/Snapshot_2004_08_08_00.pm
The file that is generated is created within your CPAN installation directory. You can copy it from that location or, if you're upgrading to a later version of Perl, you can simply run the bundle module to re-install everything:
$ perl -MCPAN -e 'install Bundle::Snapshot_2004_08_08_00'
Although the bundle function works fine, I have to admit that I'm not a huge fan of the bundling system as a network solution for a few reasons. First, bundling relies on having an identical configuration on each computer, which is fine if everything is identical. But if you have different platforms and environments, you can easily run into problems. Second, because the autobundle feature lists every module installed, it lists multiple packages (individual packages may contain multiple modules). However, the feature can also list references to later versions of Perl (as the source for some module updates).
The final problem, however, is that bundling relies on having a single computer responsible for containing the latest version of all the modules. You can't use the feature to upgrade a standard suite up to the latest versions -- whatever they may be -- and this stipulation makes the system complex to use in a network environment.
if you want to build a custom solution, two are available. You can use a central CPAN installation directory, or you can use a central CPAN source directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment