我应该如何使用Perl模块分发数据文件? [英] How should I distribute data files with Perl modules?
问题描述
我已经启动了 module-starter
(使用-builder = Module :: Build
)。我想使用 SQL :: Library
将我的SQL收集到一个.ini文件中...但是为了在运行时查找该文件,我需要知道它的确切信息路径。如何在运行时获取模块数据目录的路径?
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?
直到现在,我一直在使用FindBin(例如 $ FindBin :: Bin /../../ path / to / module /datafiles/foo.ini
,但是我发现这不是很可靠(例如,当PATH的两个不同目录中有两个同名程序时,它似乎会中断)。
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).
推荐答案
这是文件:: ShareDir 用于。由于您使用的是Module :: Build,因此需要设置 share_dir 参数(并需要Module :: Build 0.36),以便将数据文件与模块一起安装。然后,在代码中, '将使用File :: ShareDir计算 foo.ini
的路径(例如 dist_file('My-Dist','foo.ini')
)
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')
)
这篇关于我应该如何使用Perl模块分发数据文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!