Using DropBox for automatic Perl library synchronization

Working efficiently across multiple machines just got a whole lot simpler.

Working on multiple machines with varied architectures can be a pain. It’s never obvious where the most recent version of something is. Merging changes is tedious and error-prone. Building software over and over is a waste of time.

I’ve heard of some gluttons that check in their entire home into GitHub. This glutton has done the same in SVN in the way-way-past. Although source code management systems can be shoe-horned to watch almost anything, they make the problem of synchronization worse. Have you ever frantically checked-in/out on several machines before leaving for the airport to make sure your laptop is up-to-date?

Rsync gets equally confusing when source and destination are constantly changing. And don’t even consider using the --delete flag unless you’re prepared for heartache.

DropBox solves all off these problems with aplomb. It’s in essence a network disk but with a stored local copy, and a thin synchronization layer. The service comes with 2GB of free storage. If you haven’t tried it yet, here’s an invitation. Following this link when you register will net you an extra 250MB.

Here’s how I’m using it to manage Perl versions and libraries. Nothing earth-shattering here. Since DropBox is in essence just a directory, this isn’t any different from installing your own local Perl.

Directory structure

I like to keep multiple versions of Perl around as well as distinct library collections for different architectures. See below for details.

# A local directory for all things Perl
cd ~/Dropbox/perl

todd> ls -1
5.8.8-darwin  # Perl 5.8.8 and core libraries built for darwin
5.10.1-darwin  # Perl 5.10.1 and core libraries built for darwin
lib/darwin-5.10.1 # site_perl for Perl 5.10.1/darwin 
lib/x86-64-5.8.8  # site_perl for Perl 5.8.8/x86-64

If you are already happy with your current Perl, skip to Installing Modules.

Download and unpack

todd> cd ~/src
todd> curl -O
todd> tar xzf perl-5.10.1.tar.gz 


todd> cd perl-5.10.1
todd> Configure -des -Dinc_version_list=none \

Flags: -des means “Accept the defaults for your architecture”, -Dinc_version_list=none prevents Perl from accidentally including other library paths, -D/Users/todd/Dropbox/perl/5.10.1 sets the installation path.

Make and install

todd> make
todd> make test
todd> make install

Configure environment to use the new Perl

todd> export PATH=/Users/todd/Dropbox/perl/5.10.1/bin:${PATH}
todd> perl -v

This is perl, v5.10.1 (*) built for darwin-2level
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2009, Larry Wall

Installing modules

You can install modules directly into this local tree by :

todd> perl -MCPAN -e shell
cpan> install Module::Install

Alternatively, you can maintain libraries in a distinct path. This is useful if a) you want to test different sets of modules in isolation; b) you are already happy with your installed Perl version, or c) you don’t have sufficient privileges to install modules in to the default site_perl path. Although you can set this up during Configure, it’s easiest to use local::lib:

todd> perl -MCPAN -e 'CPAN::install(local::lib)'
todd> cd ~/DropBox/perl/lib/darwin-5.10.1
todd> perl -Mlocal::lib=./
todd> eval $(perl -Mlocal::lib=--self-contained,./)
todd> perl -MCPAN -e shell
cpan> install GO::Nuts

This will install the library GO::Nuts into the independent local library path.

And the best part is that GO::Nuts will instantly be available to your other environments! No more trying to remember what modules you installed during your last dev session. Just make sure the correct Perl (and/or Perl library directory) is in your path and go to it!