I got this from a co worker of mine (Prakash) and figured I'd share this useful tool with you all... You call it with a name the module in question and it gives its location and the version.

Call it like so...

  pmpath Data::Dumper
You get returned...
  /usr/lib/perl/5.6.1/Data/Dumper.pm (2.102)
I use it quite a bit for comparing module versions on different servers or find the location of the package to check out the source

Here's the code for an executable called pmpath located in my '~/bin' dir.

  #!/usr/bin/perl 
  $module = shift;
  ($mod = $module) =~ s#::#/#g;
  die ("Need a module name\n") unless $mod;
  $mod .= '.pm';
  require $mod;
  print $INC{$mod}." (".${$module."::VERSION"}.")\n";
Have Fun, Jeff
--
 __ () __ __ __ __   
| o)--(_ | o) =| =|  Jeff Bisbee        #!/usr/bin/perl -w
|__)__|__)__)__|__|  jbisbee@yahoo.com  use strict;

Replies are listed 'Best First'.
Re: pmpath
by particle (Vicar) on Jan 23, 2002 at 18:49 UTC
    be careful with code like this, as you've left open the possibility that unintended code will run on your system.

    when you require a module, it calls the module's import method at runtime. this method can be defined to almost anything within the module. although in many cases only the default import method is used, it is possible to have a good bit of code there. for an example, look at the POSIX module, which uses import (and AUTOLOADing, but that's a different story.)

    i'd suggest using File::Find and regular expressions to do this in a development environment with a shared @INC. you can never be too careful.

    ~Particle

      require loads a module at runtime, but it does not call the module's import function. From `perldoc -f require':
      ...demands that a library file be included if it hasn't already been included. The file is included via the do-FILE mechanism, which is essentially just a variety of `eval'.
      And from `perldoc -f use':
      Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to BEGIN { require Module; import Module LIST; }

      --sacked

        True, it doesn't call the import() method as use would, but it does run any code in the module up to the "1;" (or similar) return-code. In other words, if the module has any initialization code (including BEGIN blocks, and in 5.6 onward CHECK and INIT blocks), that code will be executed by the script you are demonstrating.

        You really are better-served by combining File::Find with the pre-defined @INC array as the list of directories to search over.

        --rjray

        right you are!

        my mistake. now where on earth did i read otherwise...?

        sorry for the disinformation, jbisbee!

        ~Particle

A reply falls below the community's threshold of quality. You may see it by logging in.