Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that I'm slowly converting to a package, and it needs some system modules to be either installed, or delivered with the package.

When I call the script, which uses Foo::Config.pm (my local Config.pm, in ./Foo), Config.pm calls other modules like Color::Rgb, and then dies saying that Color/Rgb.pm could not be found in @INC.

How do I add ./Foo to @INC, so it can find ./Foo/Color/Rgb.pm (which I manually put there, from the Color::Rgb package itself).

Also, when testing this script, how can I be sure that the modules I'm calling from my script are coming from . or ./Foo and subdirectories, and not from the system @INC itself? I need to make sure that the modules I deliver with my code are the ones read, and not system-installed modules of the same name.

I'm aware that PAR can do this, but PAR is not an option here. I'm simply trying to figure out how to get the modules to be called locally. If I cd to ./Foo, and run ./Config.pm directly, it finds the module under ./Color, as it should, but not from the directory above ./Foo that my script resides in. If I have 20 modules that I need to deliver with this script, should I just create all of the ./This/That/TheOther/Module.pm directories directly (assuming a This::That::TheOther::Module module)?

  • Comment on Differentiating between local and system modules

Replies are listed 'Best First'.
Re: Differentiating between local and system modules
by Anonymous Monk on Jun 01, 2003 at 13:13 UTC
    use lib 'Foo'; is what you want.
      Ok, that worked, but now I have another problem. In my code, ./Foo/Config.pm uses Getopt::Long, and POD::Usage, to parse options and spit out the relevant --help stuff. If I call ./myscript.pl --help, it just returns, without dumping the help (I'm using Carp also).

      If I call perl ./Foo/Config.pm --help, it works. The tree looks basically like this:

      . |-- ./myscript.pl `-- ./Foo |-- ./Foo/Color | `-- ./Foo/Color/Rgb.pm `-- ./Foo/Config.pm

      What am I forgetting here?

        I think I found part of the problem. I've got Pod::Usage declared in ./Foo/config.pm, and when I run myscript.pl from the parent directory, pod2usage() expects to find the --help output POD data in myscript.pl, and doesn't look in ./Foo/Config.pm at all, where the actual relevant POD data exists.

        How do I get the POD from ./Foo/Config.pm to show up when I call ./myscript.pl --help (which has a use() specified for 'use Foo::Config;' in it)?