Today, programming languages have so much big standard libraries that it’s a pain to know everything: one of my programming teacher (a C and C++ addict) told me that the thing that hurts him with Java and .Net was the huge standard library and the difficulty of having a good knowledge of these toolkits. Maybe he was right, and that documentation is sometimes a kind of unusable garbage, or even disappearing (for example when Oracle moved everything about Java to random locations).
However, it can be a bigger pain to re-write something that already exists than to learn and build easy tools to search for information inside the standard library. A tool that allow to search for common modules names (like URI manipulation or JSON or IO, anything). It’s sometimes too long to search on metacpan.org and on perl.org when you just need to use
something in your code. This problem also comes from bad (human) memory, you can’t remember all these tools that you used only a few times. You can even less remember oneliners with more than 20 chars…
$ perl -MExtUtils::Installed -MData::Dumper -e \
'my ($inst) = ExtUtils::Installed->new(); print Dumper($inst->modules());'
… is maybe a possible solution to search for modules, but it is hard to remember.
I wondered how I could display all the modules installed on my machine (most of the time, you don’t need a new module). So after a search, I found something that makes it possible (standard library or user-land-installed modules, AKA @INC
content).
The only thing that were missing was a kind of easy searchability. As I was too lazy and shy to try to extend App::Module::Lister
, I’ve just wrote some configuration in my .bashrc
.
First you have to install App::Module::Lister…
$ cpanm App::Module::Lister
Searching App::Module::Lister on cpanmetadb ...
Fetching http://www.cpan.org/authors/id/B/BD/BDFOY/App-Module-Lister-0.15.tar.gz
Building and testing App-Module-Lister-0.15
All tests successful.
Successfully installed App-Module-Lister-0.15
1 distribution installed
…then in .bashrc, add the following, that allow to search inside Perl @INC
and find installed modules. Note that it can take one argument, the searched string:
function plister () {
# Get the current position to go back into it after the script run
INITIAL_POSITION=$(PWD)
PLISTER_HOME=$HOME/perl5/lib/perl5/App/Module/
# Have to move because of limitation of the module
# See https://frama.link/yynZCC6r
cd ${PLISTER_HOME}
# Search with a pattern
if [ $1 ] ; then
# \grep "unalias" grep if you got some
perl Lister.pm | \grep --ignore-case $1
echo "Searched with App::Module::Lister with pattern $1"
# Search all modules installed
else
perl Lister.pm
echo "Searched with App::Module::Lister with no pattern"
fi
cd ${INITIAL_POSITION}
}
source
your .bashrc
, and you now got a nice modules local search-engine based on App::Module::Lister
abilities.
$ plister Module::Starter
Module::Starter 1.60
Module::Starter::Smart 0.0.4
Module::Starter::Simple 1.60
Module::Starter::App 1.60
Module::Starter::BuilderSet 1.60
Module::Starter::Plugin::Template 1.60
Searched with App::Module::Lister with pattern Module::Starter
This blog post has been previously published on smonff.github.io.