Taking CPAN With You

nn

CPAN is THE killer feature for Perl. Onenproblem you may have from time to time due to it’s online nature is availabilitynissues. How do you install CPAN modules from a plane, train, or automobilenwithout wifi? Or from the middle of nowhere in Oregon (Ione, OR)? Or timely install Moose andnit’s dependencies from a dial-up connection in the middle of the desertednOklahoma plains (Leedey, OK).nWell, my fellow perler, I have been to these places forgotten by the Internets,nand I have installed CPAN modules with impunity.

nn

CPAN::Mini

nn

CPAN::Mini, driven by the includednminicpan,ncreates a local mirror of CPAN containing only the latest non-developer releasenof every distribution on CPAN. With CPAN::Mini yountoo can install CPAN modules with impunity from exotic locations. But just hownmuch disk space must you dedicate for such awesomeness? My mirror is currentlynjust under 3 GB.

nn

Start by installing CPAN::Mini with your CPAN client of choice:

nn

1n2n3n4n5n
$ cpanm CPAN::Minin$ # orn$ cpanp install CPAN::Minin$ # orn$ cpan CPAN::Minin

nnn

Now you need a config file in ~/.minicpan.

nn

~/.minicpanrc
1n2n3n4n
local:   ~/Dropbox/minicpannremote: http://cpan.hexten.net/nalso_mirror: indices/ls-lR.gznskip_perl: 1

nnn

These options should be fairly self-explanatory. Check out thenCPAN Mirrors site to find a healthy mirror in your regionnfor the second line. Now, just run minicpan and wait. Periodically,nyou’ll want to run this command again to download new dists and delete old ones.nThat’s all it takes to be the owner of a shiny tiny local CPAN mirror.

nn

Using Your Shiny New CPAN Mirror

nn

To use your new mirror, just specify the path to your CPAN::Mini mirror in yournCPAN client of choice.

nn

cpanm

nn

For cpanm Inhave an alias in my .zshrc:

nn

1n
minicpanm='cpanm --mirror ~/Dropbox/minicpan --mirror-only'n

nnn

The same line should work in a .bashrc as is. Then, to install a new CPANnmodule, just run minicpanm ACME::urmom.

nn

cpanp

nn

Run cpanp s edit and your editor will launch. If the file you are innisn’t empty, skip to the next step. Now run cpanp s save to copy thencurrent configuration to the user config file and then run cpanp s editnagain.

nn

Find the hosts config and add your new entry at the beginning.

nn

1n2n3n4n5n6n7n8n9n10n11n12n13n14n15n16n17n
$conf->set_conf( hosts => [n      {n        'host' => '',n        'path' => '/Users/yourname/Dropbox/minicpan',n        'scheme' => 'file'n      }n      {n        'host' => 'ftp.cpan.org',n        'path' => '/pub/CPAN/',n        'scheme' => 'ftp'n      },n      {n        'host' => 'www.cpan.org',n        'path' => '/',n        'scheme' => 'http'n      },n# ...n

nnn

Save and exit your editor.

nn

cpan

nn

For cpan, you use the interactive shell to update the configuration:

nn

1n2n3n4n5n6n7n8n9n10n11n12n13n14n15n16n17n18n19n
$ cpanncpan shell -- CPAN exploration and modules installation (v2.00)nEnter 'h' for help.nncpan[1]>  o conf urllist unshift file:///Users/yourname/Dropbox/minicpamnPlease use 'o conf commit' to make the config permanent!nnncpan[2]> o conf urllistn    urllistn    0 [file:///Users/yourname/Dropbox/minicpam]n    1 [http://cpan.erlbaum.net/]n    2 [http://cpan.mirror.clemson.edu/]n    3 [http://cpan.develooper.com/]nType 'o conf' to view all configuration itemsnnncpan[3]> o conf commitncommit: wrote '/Users/yourname/.local/share/.cpan/CPAN/MyConfig.pm'n

nnn

Enjoy (Faster) CPAN Installs From Anywhere

nn

That’s it! From here on out your disk speed and not your Internet connection,nor lack thereof, will be your throttle in your CPAN client of choice acquiringndistribution packages.

n