Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

whichpm

by belg4mit (Prior)
on Jul 16, 2003 at 05:53 UTC ( #274701=CUFP: print w/ replies, xml ) Need Help??

#!perl -w use strict; use vars '$VERSION'; #Added 0.02{ use File::Spec; # $VERSION = 0.03; #} foreach( @ARGV ){ eval "require $_" || next; #Short-circuit added 0.03 # s%::%/%g; $_ = File::Spec->catfile(split(/::/, $_)); #Added 0.02 $_ .= '.pm' unless /\.pm$/; print $INC{$_}, ' '; } print "\n"; __END__ =pod =head1 NAME whichpm - lists real paths of specified modules =head1 SYNOPSIS less `whichpm Bar` =head1 DESCRIPTION Analogous to the UN*X command which. Even with TAB completion entering paths like F</afs/athena.mit.edu/user/u/s/user/lib/perl5/site_perl/5.8.0/IO/Pager +> can be gruesome. ~ makes it a bit more bearable F<~/lib/perl5/site_perl/5.8.0/IO/Pager>. Then inspiration struck, perl knows where its libraries are; modulo @I +NC. Better yet, you don't have to know if it's a core module or site speci +fic nor architecture specific vs. platform independent. =head1 AUTHOR Jerrad Pierce <jpierce@cpan.org> =cut

--
I'm not belgian but I play one on TV.

Comment on whichpm
Download Code
Re: whichpm
by Aristotle (Chancellor) on Jul 16, 2003 at 07:54 UTC
    I've been using something nearly identical for a while - even named it whichpm as well.
    use strict; use warnings; use File::Spec::Functions qw(catfile); my @loaded = grep { eval "require $_"; !$@ ? 1 : ($@ =~ s/\(\@INC contains: \Q@INC\E\)//, warn("Failed lo +ading $_: $@"), 0); } @ARGV; my @pm = map catfile(split '::') . (/\.pm\z/ ? '' : '.pm'), @loaded; print "@INC{@pm}\n";

    Makeshifts last the longest.

Re: whichpm
by cchampion (Curate) on Jul 16, 2003 at 08:16 UTC

    $ perldoc -l modulename would give you exactly the same result.

    Or am I missing something?

    $ perldoc -l HTML::Parser /usr/lib/perl5/site_perl/5.6.1/i386-linux/HTML/Parser.pm

      The command perldoc -l gives the location of the pod which might not be the same file as the source code, for example:
      $ perldoc -l Inline::C /usr/local/perl/lib/site_perl/5.6.1/Inline/C.pod

      --
      John.

Re: whichpm
by PodMaster (Abbot) on Jul 16, 2003 at 11:07 UTC
    I recently ran accross Module::InstalledVersion, somewhat similar in its purpose. Neither you nor it pay attention to the dynamic environment variables PERLLIB, PERL5LIB. Just letting you know ;)

    Also, you've already got the pod, so The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan! ;)

    update: duuuuh, I think what I was trying to say is that maybe you shouldn't be actually requireing the module, kinda like what Module::Info info does (hey, you could use Module::Info), but since you're actually editing it ++/duck

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      I had actually thought about these vars, but assumed that require would handle the magic. I'll test it, if it doesn't it's a simple matter of a BEGIN block to split the vars and <s>push</s> unshift them onto @INC.

      UPDATE: As Aristotle got around to showing before I did, the vars are heeded

      Oh umm, okay... Why not? I actually used require intentionally. Let perl do the heavy lifting ;-) It even works for broken modules which don't return true (but not null length files).

      --
      I'm not belgian but I play one on TV.

      Oh?
      $ PERL5LIB="--->HERE<---" perl -le'print "@INC\n"' --->HERE<--- /usr/lib/perl5/5.8.0/i386-linux /usr/lib/perl5/5.8.0 /usr +/lib/perl5/site_perl/5.8.0/i386-linux /usr/lib/perl5/site_perl/5.8.0 +/usr/lib/perl5/site_perl .

      Makeshifts last the longest.

Re: whichpm
by halley (Prior) on Jul 16, 2003 at 17:12 UTC

    My homegrown version started from an example in the Cookbook. I manually walk the @INC and get other module information like $VERSION and =head1 NAME summaries. With an extra option, I can also find shadowing where some yokel has defined a module with the same name as a corporate site-perl module.

    --
    [ e d @ h a l l e y . c c ]

      That would be a wherepm, which could also be useful on occasion.

      --
      In Bob We Trust, All Others Bring Data.

Re: whichpm
by zentara (Archbishop) on Jul 17, 2003 at 15:01 UTC
    I had this one in my library collection:
    #!/usr/bin/perl #usage $0 Some::Module ($f=($m=shift).".pm")=~s{::}{/}g; eval "require $m" and print $INC{$f},$/; #1liner # perl -e '($f=($m=shift).".pm")=~s{::}{/}g; \ # eval "require $m" and print $INC{$f},$/' File::Find #also #perldoc -l Some::Module
whichpm = pmpath
by bsb (Priest) on Jul 24, 2003 at 05:22 UTC
    pmpath in pmtools (by tchrist) does this, I think.

    Here's some other goodies in pmtools.

    This is from the dpkg description of pmtools:

    Description: Perl module tools Perl module tools is a suite of small tools that help manage and insp +ect perl modules, perl Plain Old Documentation files, and perl programs. . Some of the things these tools can do include: - show the full path to a module - show the version and description of a module - list all installed modules with descriptions - show what files a given program or module loads at compile time - show what symbols a module exports - list the methods of a class - display the source code of a function of a module

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://274701]
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-12-28 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls