Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

pmpath

by jbisbee (Pilgrim)
on Jan 23, 2002 at 10:31 UTC ( [id://140844]=CUFP: print w/replies, xml ) Need Help??

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
        right you are!

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

        sorry for the disinformation, jbisbee!

        ~Particle

        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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://140844]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2026-01-13 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (118 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.