[tpm] Detect a module's directory
Shlomi Fish
shlomif at iglu.org.il
Mon Feb 22 11:48:37 PST 2010
Hi Madi!
On Monday 22 Feb 2010 21:28:01 Digimer wrote:
> Hi all,
>
> Possibly stupid question time...
>
> Is there a reliable* way to detect or read the directory that a perl
> module is in? '$ENV{PWD}' returns the directory of the script loading
> the module, not of the module itself. My Google-fu is failing me as
> finding a solution, too.
>
Yes, there is: see %INC in http://perldoc.perl.org/perlvar.html :
{{{
%INC
The hash %INC contains entries for each filename included via the do, require,
or use operators. The key is the filename you specified (with module names
converted to pathnames), and the value is the location of the file found. The
require operator uses this hash to determine whether a particular file has
already been included.
If the file was loaded via a hook (e.g. a subroutine reference, see require
for a description of these hooks), this hook is by default inserted into %INC
in place of a filename. Note, however, that the hook may have set the %INC
entry by itself to provide some more specific info.
}}}
Regards,
Shlomi Fish
P.S: can someone get rid of the toronto-pm at pm.org / tpm at to.pm.org duality?
Reply all on KMail keeps wanting to post it twice.
> The reason I need this is that my core module reads in a
> configuration file from the root of the module's directory. I could
> hard-code it, but I would rather it be flexible in case it gets moved
> down the road.
>
> Thanks!
>
> Madi
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/
Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
More information about the toronto-pm
mailing list