http://www.perlmonks.org?node_id=1025272

In this post I want to share my chef cookbook called cpan. Chef is the modern platform for deploy automation and configuration. One of chef great feature - one may create custom recipes to deploy/configure specific applications, written on any languages. When I first met with chef, I had already had some experience on deploying perl applications. I used standard build cycle:
perl Build.PL ./Build ./Build installdeps ./Build test ./Build install
So the idea of integrating perl application install come into my mind in natural way.

With cpan cookbook one may do standard perl build/test/install idioms using chef. Here I am putting some use cases, just to give some sense of what it is. If you like it, you may learn more on http://community.opscode.com/cookbooks/cpan.

Cpan cookbook use cases

Installing application, distributed with tar-ball. Let's say you have already fetch and store tar-ball with others chef resources (the following code is self-explanatory). So you may easily install it into given install base:
remote_file '/tmp/app-0.0.1.tag.gz' source 'http://local.server/app-0.0.1.tag.gz' end execute 'cd /tmp/ && tar -xzf app.tag.gz' cpan_client 'my application' do user 'root' group 'root' install_type 'application' action 'install' install_base '/path/to/your/application/home' cwd '/tmp/app-0.0.1' end
The same thing with your perl5lib paths taking into account ('/home/user/alex/perl5lib/'):
cpan_client 'my application' do user 'root' group 'root' install_type 'application' action 'install' install_base '/path/to/your/application/home' cwd '/tmp/app-0.0.1' inc %w{ /home/user/alex/perl5lib/ } end
If you need just installing arbitrary cpan module, here some examples to start. Install by given link:
cpan_client "http://search.cpan.org/CPAN/authors/id/M/MA/MARKSTOS/CGI. +pm-3.59.tar.gz" do user 'root' group 'root' module_name 'CGI' action 'install' end
Or just rely on your cpan mirrors:
cpan_client 'CGI' do user 'root' group 'root' install_type 'cpan_module' action 'install' end
With cpan cookbooks you may even play with version requirements. Require minimal version:
cpan_client 'CGI' do user 'root' group 'root' version '3.55' install_type 'cpan_module' action 'install' end
Do not install if already installed:
cpan_client 'CGI' do user 'root' group 'root' version '0' install_type 'cpan_module' action 'install' end
Try to upgrade to highest possible version:
cpan_client 'CGI' do user 'root' group 'root' install_type 'cpan_module' action 'install' end
If you install by distributive, you may even require concrete version:
cpan_client 'http://search.cpan.org/CPAN/authors/id/M/MA/MARKSTOS/CGI. +pm-3.59.tar.gz' do user 'root' group 'root' module_name 'CGI' version '=3.59' action 'install' end
Other examples to check out is on http://community.opscode.com/cookbooks/cpan.