Secrets of cpanm cpanfile Support

On a previous client's project, I set up Carton to manage dependencies. This worked out really well, but I came to realize that most of the benefit on that project was using a single cpanfile to list all dependencies.

(Allison wrote a tiny Makefile to manage something else on the project, so it made a lot of sense to add make targets to "update all dependencies" or "use Sqitch to deploy the current version of the database.)

Carton tends to work best if you want to bundle everything into a single directory you can either deploy as is or check into source control. It reminds me of Java's Maven, but without the awful craziness. That's way more than I need for my current small project, where I want a couple of really simple things:

  • Manage database migrations with a single command
  • Manage module installations with a single command

Sqitch gives me the former. Carton's more than I need for the latter, but cpanfile support is great. Fortunately, I have control over the deployment environment. First I set up perlbrew with Perl 5.18.2. I installed Perl locally so that the deploying user account on the server has write access to module installation directories. Then I found the special cpanm incantation to install dependencies from a cpanfile. Here's the Makefile target:

cpan_update:
        cpanm --cpanfile    ${PWD}/config/cpan/cpanfile \
              --installdeps ${PWD}/config/cpan

That's it. Keep in mind three things. One, you must use both the --cpanfile and --installdeps options. You can't get by without --installdeps. Two, you need a recent version of cpanminus. I updated to 1.7001 and that's fine. Three, the paths you provide to both arguments must be absolute. I struggled with this for quite a while until I realized the latter.

This is a small project, but even this little bit of automation has been incredibly helpful. I'll have no trouble keeping my code and database synchronized between my development machines and my production server.

Modern Perl: The Book

cover image for Modern Perl: the book

The best Perl Programmers read Modern Perl: The Book.

affiliated with ModernPerl.net

Categories

Pages

About this Entry

This page contains a single entry by chromatic published on January 8, 2014 6:00 AM.

The Limits of a Programming Language Vision was the previous entry in this blog.

How to Rewrite Software without Destroying Your Business is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.


Sponsored by Blender Recipe Reviews and the Trendshare how to invest guide

Powered by the Perl programming language

what is programming?