Tool tip: looking at a module's source

I've got a script for looking at locally installed modules, used thusly:

    % pmvi Net::FTP

I use this a lot, since I often find myself wanting to check exactly what a module is doing, either to learn from it, because the doc isn't clear, or I have reason not to trust the doc, or curiosity, or ...

Here's the script:

    #!/bin/sh
    /usr/bin/view `mpath $*`

view is a symlink to vim, and mpath comes with my Module::Path module.

What's your tool tip?

11 Comments

Neat!
I immediately changed my bash function that does this and replaced "perldoc -l" with "mpath". Thank you!

I usually type out komodo $(pm_which -q Some::Module) ( The -q is in case I mistyped the module. )

I have thought about writing a script that opens the file in komodo if it is running, and otherwise open it in another program.

Nice idea. This prompted me to write mless and medit (following mversion and mpath):

mless:
#!/bin/bash
if [[ "$PAGER" == "" ]]; then PAGER=less; fi
$PAGER "`mpath $*`"
medit:
#!/bin/bash
if [[ "$EDITOR" == "" ]]; then EDITOR="emacs -nw"; fi
$EDITOR "`mpath $*`"

What's wrong with perldoc -m ?

My favorite:

cpandoc -m

IIRC, -v is quite a recent addition.

Also, -m and -l can be used in conjunction, which can be useful for things like:

$EDITOR `perldoc -lm Foo::Bar`

... which finds the Foo::Bar module, and opens it in your editor.

I have a script vipm that looks like this after evolving via much usage: http://tsibley.net/paste/2014-01-14aJ6L3Vad-vipm

It uses V.pm to find locally installed modules or cpandoc -m to open up remote ones.

Steven:

if [[ "$EDITOR" == "" ]]; then EDITOR="emacs -nw"; fi
$EDITOR "`mpath $*`"
${EDITOR:-emacs -nw} "`mpath $*`"

And analogously for the other one. Consult Parameter Expansion in man bash.

Thanks for that!
The only thing that is wrong with your version is the name. The proper name for this tool is "vimp" :-)

ps: mine used to used perldoc -l. Now it uses mpath. I suppose that it is worth while re-reading the perl doc once a decade or so.

Another alternative to perldoc and cpandoc is my mcpandoc tool (which is really just cpandoc with some extra logic). It does what cpandoc does, only it tries to grab the module from a minicpan first. Pretty handy when you have limited network access!

Leave a comment

About Neil Bowers

user-pic Perl hacker since 1992.