So you'd like to ... do offline development and testing
[This post will be imported to cpanlists.org once the service is ready]
Do you want to develop your Perl project on your PC or laptop, without having to be constantly connected to the Internet? Then follow this simple guide.
Creating a CPAN mirror
First you'll want an offline CPAN mirror, where most of the useful Perl modules reside. There is already a document explaining how to do this, so go read it. At the time of this writing (Feb 2014), a full CPAN mirror stands at +- 16GB. Chances are you don't need a full mirror, but a mini one, which contains only the latest version of each module and currently stands at about 2.5GB. You can then update your offline mirror every so often (I do this about once a week).
Next, you'll also want App::cpanminus, if you don't already have it. This CPAN client makes it easy to install from an offline CPAN or DarkPAN mirror.
Now to install a module from your local mirror, you can simply do:
% cpanm --mirror /path/to/your/cpan --mirror-only Module::Name
To save typing, you can make a shell alias, e.g.:
% alias cpanm-local='cpanm --mirror /path/to/your/cpan --mirror-only'
Creating a DarkPAN
If you package your application as Perl distributions (I blogged about the benefits of doing this), you can create your own DarkPAN so installing your modules can be as easy as installing CPAN modules.
You'll want a tool to create a CPAN-like repository. There are several tools available, but I currently use OrePAN. An example usage:
% mkdir /path/to/your/darkpan-proj1 % orepan.pl --dest /path/to/your/darkpan-proj1 --pauseid SHARYANTO Proj1-Module1-0.03.tar.gz % orepan.pl --dest /path/to/your/darkpan-proj1 --pauseid SHARYANTO Proj1-Module2-0.02.tar.gz ...
Invoke orepan.pl for every distribution you create. I usually do this from a Dist::Zilla release plugin so when I release my distribution, the release is automatically added to my DarkPAN.
Now to install your module from your DarkPAN, you can simply do:
% cpanm --mirror /path/to/your/darkpan-proj1 --mirror /path/to/your/cpan --mirror-only Proj1::Module1
The last --mirror option is a fallback to CPAN, so when your distribution has a dependency to other CPAN modules, they can be installed too. You can add as many --mirror options to your DarkPAN before the last CPAN --mirror option so you can install from multiple DarkPANs+CPAN in one go.
Keeping your installation up-to-date
You can use App::cpanoutdated for this. It can check the version of installed modules against that on a CPAN/DarkPAN mirror. It will output the list of outdated modules, which you can feed to cpanm so you can simply do this to update your modules:
# update all your CPAN modules % cpan-outdated --mirror /path/to/your/cpan | cpanm # update your proj1 modules % cpan-outdated --mirror /path/to/your/darkpan-proj1 | cpanm
Don't forget to add --mirror option(s) to your cpanm command so cpanm knows where to look for your modules.
Thanks to RJBS, MERLYN, MIYAGAWA, and TOKUHIROM for creating the above-mentioned tools.