Finding Stuff In Your Local CPAN Mirror

So you’ve got this great new local CPAN you can use to install stuff you know about but how do you find stuff you don’t know about? There are two main ways I inspect the contents of my local CPAN mirror. The first is a simple shell function for searching package names, the second has a bit more to it but we will save that for later.

grep to the Rescue

One of the metadata files in our local mirror isn/modules/02packages.details.txt.gz. Let’s take a look inside.

/modules/02packages.details.txt.gz

File:         02packages.details.txtnURL:          http://www.perl.com/CPAN/modules/02packages.details.txtnDescription:  Package names found in directory $CPAN/authors/id/nColumns:      package name, version, pathnIntended-For: Automated fetch routines, namespace documentation.nWritten-By:   CPAN::Mini::Inject 0.33nLine-Count:   145223nLast-Updated: Tue, 12 Aug 2014 15:01:40 GMTnnAAA::Demo                         undef  J/JW/JWACH/Apache-FastForward-1.1.tar.gznAAA::eBay                         undef  J/JW/JWACH/Apache-FastForward-1.1.tar.gznAAAA::Crypt::DH                    0.04  B/BI/BINGOS/AAAA-Crypt-DH-0.04.tar.gznAAAA::Mail::SpamAssassin          0.002  S/SC/SCHWIGON/AAAA-Mail-SpamAssassin-0.002.tar.gznAAAAAAAAA                          1.01  M/MS/MSCHWERN/AAAAAAAAA-1.01.tar.gznAAC::Pvoice                        0.91  J/JO/JOUKE/AAC-Pvoice-0.91.tar.gznAAC::Pvoice::Bitmap                1.12  J/JO/JOUKE/AAC-Pvoice-0.91.tar.gznAAC::Pvoice::Dialog                1.01  J/JO/JOUKE/AAC-Pvoice-0.91.tar.gzn...

nnn

The format is pretty straightforward. After a few header lines, we have onenline per package seen by the indexer. The lines consist of three whitespacenseparated columns of a package name, current package version (if the indexer found one),nand latest distribution containing it. The AAC-Provoice and Apache-FastForwardndistributions show us that each individual package within the distribution isnlisted. We could easily use zgrep to find packages that match a pattern.

nn

/modules/02packages.details.txt.gz
1n2n3n4n5n
$ zgrep -i tiny ~/Dropbox/minicpan/modules/02packages.details.txt.gznAcme::Has::Tiny                   0.001  T/TO/TOBYINK/Acme-Has-Tiny-0.001.tar.gznAcme::Module::Build::Tiny          0.0   D/DA/DAGOLDEN/Acme-Acme-Module-Build-Tiny-0.06.tar.gznAcme::Tiny                        0.003  E/ET/ETHER/Acme-Tiny-0.003.tar.gzn...

nnn

This is a little long to type regularly. A shell alias isn’t appropriate as wenwant to sandwich the provided input between zgrep and the path to the file.nFortunately, a shell function will allow us to do this without much morenverbosity.

nn

1n2n3n
function cpangrep {n    zgrep $* /home/yourusername/Dropbox/minicpan/modules/02packages.details.txt.gzn}n

nnn

Dropping this line in your .zshrc or .bashrc will allow you to searchn02packages.details.txt.gz with the cpangrep command.

nn

1n2n3n4n5n6n7n8n
$ cpangrep tiny | wc -ln21n$ cpangrep -i tiny | wc -ln344n$ cpangrep -i tinynAcme::Has::Tiny                   0.001  T/TO/TOBYINK/Acme-Has-Tiny-0.001.tar.gznAcme::Module::Build::Tiny          0.06  D/DA/DAGOLDEN/Acme-Acme-Module-Buildn...n

nnn

Since we use $* instead of $1, all arguments we give to the function arenpassed on to zgrep. This allows us to do things like search with or withoutnignoring case on demand.

nn

CPAN::Mini::Webserver

nn

CPAN::Mini::Webserver provides anscript that launches a web server providing an interface to your local minicpan.nUsage couldn’t be easier, install CPAN::Mini::Webserver then runnminicpan_webserver. By default the server binds to port 2963 but you cannchange this with the --port argument.

nn

If you’ve used search.cpan.org ornmetacpan, there should be no surprises in how to navigatenaround the site. Thendocumentation has information onna few things you can plug in to your .minicpanrc to enable things like fullntext indexing.

nn

Here are a few screenshots of CPAN::Mini::Webserver to wet your appetite.

nn

nnnn

n