The CPAN::Mini::Webserver module is getting a lot of love in the last few weeks.
The most recent 0.40 version includes a lot of goodies including:
- act as a true CPAN mirror so that you can point you
cpan client to it;
- syntax highlight of Perl code;
- Bonjour registration: easy to find on a local lan;
- shows which modules are installed locally;
- A lot more meta information shown about each module.
Getting everything right is easy.
Installing CPAN::Mini
First, you need a CPAN::Mini mirror of the full CPAN. Right now it takes 862Mb of my disk.
Create a .minicpanrc in your $HOME directory with the following:
local: /Users/melo/Documents/cpan
remote: http://cpan.perl.pt/
also_mirror: authors/00whois.xml
Adjust the local and remote settings to a local directory where the mirror will be placed and the CPAN mirror you wish to use.
Then run minicpan. You can stick this in your own crontab, also . I run mine each morning at 10:20.
The first time will take a bit of time, but updates are very fast. Recent versions of CPAN::Mini use HTTP keep-alive, so I recommend that you use a HTTP-based mirror.
You can take the opportunity and update your cpan configuration to use this module. To do that, run the cpan client, and use o conf init /urllist/. Keep you current mirror and add the new local directory at the end of the list. Don't forget o conf commit to make your changes persistent.
My configuration looks like this:
cpan[1]> o conf urllist
urllist
0 [http://cpan.perl.pt/]
1 [file:///Users/melo/Documents/cpan/]
Having a HTTP mirror and your local mirror this way triggers an optimization in the cpan client. He will always keep the module indexes up-to-date using the external mirror, but for each module that he needs to install, the local mirror is tried first.
Installing CPAN::Mini::Webserver
Install tht CPAN::Mini::Webserver. You will also need to install the plugin HTTP::Server::Simple::Bonjour and a proper Net::Rendezvous::Publish::Backend module for your operating system (I use Net::Rendezvous::Publish::Backend::Apple).
Running CPAN::Mini::Webserver
You can now run minicpan_webserver and open http://localhost:2963/. You can change the port number with minicpan_webserver -p PORT.
You can also keep it running by sticking this on the inittab or if you use a Mac, use Lingon and create a "My Agents" entry to keep it running. I use the second option.
Bonjour workaround
On a last note, the Bonjour stuff doesn't work since 0.39. CPAN::Mini::Webserver is overriding the print_banner method that the Bonjour plugin uses. I've reported this as a bug.
There is no easy way out. Probably the best way is to add a new init_plugins hook to HTTP::Server::Simple that gets called before the print_banner and then change the Bonjour plugin to use that.
On my copy I patched CPAN::Mini::Webserver directly and commented the print_banner function. I prefer to have Bonjour than a prettier banner I never get to see anyway.