in reply to module location

May I back up a minute and ask why you are wanting use of DBI to be conditional? Since DBI can work with or without compilation (see docs for DBI::PurePerl), under what circumstance would you want to not use it? I'm not saying there are no such circumstances, I'm just curious.

Replies are listed 'Best First'.
Re: Re: module location
by hmerrill (Friar) on Nov 07, 2003 at 16:38 UTC
    DBI was just an example of a module name. The script I'm working on will take in the name of any perl module and will tell you
    1. if the module is installed on the system 2. if it is installed, what version ($VERSION) it is, and 3. if it is installed, exactly where on the system it resides (absolute file name)
    It's not rocket science - I'm sure others (like Broquaint above with Module::Locate) have probably already done this, but I'll post the code when I'm done.
      Well, for DBI, this tells you all three of those things:

      perl -MDBI=9999

      But good luck on a more general solution, seems like there have been some good suggestions for you.
        Part of that doesn't work, at least on my system. Here's what I get:
        [hmerrill@merrill bin]$ perl -MDBI=9999 DBI version 9999 required--this is only version 1.32 at /usr/lib/perl5/5.8.0/Exporter/Heavy.pm line 121. BEGIN failed--compilation aborted.
        It does print the version of DBI(1.32), but notice that the path name refers to Exporter::Heavy, and not DBI.
      use Module::Locate 'locate'; die "Usage: $0 MODULE\n" unless @ARGV; my $mod = shift @ARGV; my $path; if(eval{ require( $path = locate $mod ) }) { die "$mod missing version number\n" unless $mod->VERSION; print "$mod version ", $mod->VERSION, " installed at $path\n"; } else { die "$mod not installed\n"; }
      HTH

      _________
      broquaint