Dir::Self - a __DIR__ constant for the directory your source file is in
use Dir::Self; use lib __DIR__ . "/lib"; my $conffile = __DIR__ . "/config";
Perl has two pseudo-constants describing the current location in your source
code, __FILE__ and __LINE__. This module adds __DIR__, which expands
to the directory your source file is in, as an absolute pathname.
This is useful if your code wants to access files in the same directory, like helper modules or configuration data. This is a bit like the FindBin manpage except it's not limited to the main program, i.e. you can also use it in modules. And it actually works.
This module cheats. It generates a __DIR__ constant when it is used; any
subsequent uses of this __DIR__ won't pay attention to the actual source
location. So if you have two source files with the same package declaration
in different directories, and one of them uses the Dir::Self manpage, and the other
calls __DIR__, it will get the location of the use, i.e. the first file.
This is unlikely to be a problem because normally each library file gets its own package; but you can always use Dir::Self::__DIR__, which recomputes the directory name each time it's called.
Lukas Mai, <l.mai @web.de>
Copyright (C) 2007 by Lukas Mai
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.