I've started a module-starter
(with --builder=Module::Build
). I want to use SQL::Library
to collect my SQL into an .ini file... but in order to find the file during run time, I need to know its exact path. How do I get the path of the "data directory" of a module at run time?
Until now, I've been using FindBin (like "$FindBin::Bin/../../path/to/module/datafiles/foo.ini"
, but I found this is not very robust (For example, it seems to break when there are two programs with the same name in two different dirs in PATH).
In Perl a true value is any value that is not: null, zero or a zero-length string. A distribution is a collection of files that usually includes a Perl module and several other files.
A Perl package is a collection of code which resides in its own namespace. Perl module is a package defined in a file having the same name as that of the package and having extension . pm. Two different modules may contain a variable or a function of the same name.
Perl modules are a set of related functions in a library file. They are specifically designed to be reusable by other modules or programs. There are 108,000 modules ready for you to use on the Comprehensive Perl Archive Network.
This is what File::ShareDir is for. Since you're using Module::Build, you'll need to set the share_dir parameter (and require Module::Build 0.36) in order to have your data files installed along with your module. Then, in your code, you'll use File::ShareDir to calculate the path of foo.ini
(e.g. dist_file('My-Dist', 'foo.ini')
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With