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).
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'))