Thursday, October 6, 2011

Almost unattended CPAN module installation

Summary

This article explains how to reduce questions during the installation of CPAN modules. Simply change the cpan configuration:
sudo cpan
o conf prerequisites_policy follow
o conf build_requires_install_policy yes
o conf commit

Discussion

Unattended installation of CPAN modules is unfortunately a utopia. The reason is simple; the interface for module installation is unrestricted, and any module can ask questions of the user during the installation process, eg "Skip network tests [y]?". This is a bother, especially when installing some modules which seem to indirectly depend on half of the modules on CPAN. These questions would be acceptable if all could have been clumped together at the start of the process, since I am not responsible for manually updating any significant number of hosts. Module dependencies are resolved in each individual package's installation process instead of being handled on a higher level, which means that it is not possible to resolve all questions at the start of the process.

Though perl's module installation process is crude, it is also in good company. Even the more modern package manager used by Debian, dpkg, also suffers from the same illness. Configuration questions pops up now and then during installation and upgrade. Ubuntu has made a fine job of minimizing most of these, but changing any system configuration file will always result in required attendance during upgrade: "Do you want to: I) install package maintainer's version..." etc. That's why I prefer configuration directory supported configuration, ie putting local changes in local files which are separate from the file in the package, eg Apache, sudo.

Back to the topic at hand. I have found three types of questions which can appear during perl module installation:
  1. package dependencies,
  2. temporary modules required for build or test, and
  3. package specific configuration or test.
There may be more, but these are the ones I have run into. Items 1 and 2 are handled by CPAN, and item 3 by the individual package, which means that only items of type 1 and 2 can be handled completely unattended. My preference is to always follow dependencies and always install modules required for build or test, thinking "if one package wants it, chances are good other wants it too".

As described in the summary, change the following cpan configuration items:
sudo cpan
o conf prerequisites_policy follow
o conf build_requires_install_policy yes
o conf commit
And there you have it, no more questions about dependencies.

Finally, one may think that solving the last item would be as simple as to tell cpan to always answer "yes" to whatever question the package is throwing in your general direction, perhaps like this:
yes | sudo cpan Some::Module
Unfortunately the world isn't black and white so the above would fail for DBIx::Migration::Directories, which asks for a directory where schemas are stored.

Conclusion

Setting the above configuration options have saved me a lot of time during installation, since I can mostly leave the terminal unattended. I recently made a scratch installation of a Xubuntu 11.04 system, and upgraded to the latest version of CPAN ("sudo cpan CPAN"). It caused a module explosion but I still got no more than a handful of questions during the entire process, and could focus on more rewarding things, like beer'n pretzels. Now you can too.