在 Perl 中,使用 Appconfig 我希望能够在另一个配置文件中包含 cfg 文件
我做了很多研究,但没有运气......
我想要一个配置文件,其中包含一些默认值或通用值。然后让其他配置文件包含默认配置,并根据需要覆盖变量。
示例:
Default.cfg :
[${name}]
bin = /bin/1
tmp_dir = /tmp
tmp_file = /tmp/${name}_tmp_file
------------------------------
myProc.cfg :
name = Test_proc
[${name}]
bin = /bin/TEST
这样,myProc.cfg 使用 default.cfg 中定义的相同 tmp_dir,但定义“名称”并重新定义 bin 目录。
好吧,这个例子非常简单,但我有无数的配置,它们共享相同的 cfg 行,但略有不同,我正在尝试合并配置。
我的应用程序采用 Perl 语言,并且已经使用 AppConfig。
预先感谢您的帮助。
I've done a lot of research but no luck...
I want to have a config file with some default or generic values in it. Then have other config files INCLUDE that default config, and overwrite variables if needed.
example:
Default.cfg :
[${name}]
bin = /bin/1
tmp_dir = /tmp
tmp_file = /tmp/${name}_tmp_file
------------------------------
myProc.cfg :
name = Test_proc
[${name}]
bin = /bin/TEST
This way, myProc.cfg uses the same tmp_dir defined in the default.cfg but defines the "name" and redefines bin dir.
Well, this example is very simple but I have gizillion configs that share the same lines of cfg but differ a little and I'm trying to consolidate configs.
My app is in Perl and already using AppConfig.
Thank you in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Config::General
应该能够处理这个问题,但是如果您想坚持使用AppConfig
,只需创建一个子类,通过手动处理包含来预处理配置文件,说s/_my_special_include_syntax = (.+)$/IncludeThis($1)/ge;
据我所知,这应该可以在没有任何其他修改的情况下工作,因为最后一个分配获胜,因此,最后一个分配会覆盖默认值
Config::General
ought to be able to handle this, but if you wish to stick withAppConfig
, simply create a subclass, that preprocesses the config file, by manually processing includes , says/_my_special_include_syntax = (.+)$/IncludeThis($1)/ge;
afaik, this should work without any other modifications, since last assignment wins, thus, the last assignment overrides defaults
YAML 可以处理一个文件中的多个“文档”。因此可以使用 YAML 来分隔多个
AppConfig
文档。我还没有真正深入研究AppConfig,但是像下面这样的东西在调整后应该可以工作。
下面的代码展示了如何将它们分成文档,和您甚至可能不需要这样做。第三个文档是文件到文本的映射。
YAML can handle multiple "documents" in a file. So it's possible to use YAML to separate several
AppConfig
documents.I haven't done real diving into AppConfig, but something like the following should--when tuned--work.
The code below shows how you can separate them up into documents, and that you might not even have to. The third document is a mapping of file to text.
答案很晚,但我发现 AppConfig 可以运行多次。
为了发布我的文件,我将所有登录名/密码移至 configfile.ini.secret 并将示例登录名/密码留在 configfile.ini 中
,您可以通过下一个文件的名称对文件进行菊花链,而不是仅仅对 .secret 进行硬编码在上一篇中。
类似的东西(perl 语法可能是错误的)
或者你可以将文件放在 config.d 目录中并按字母顺序处理所有文件。
A late answer, but I found that AppConfig can be run multiple times.
To publish my files I moved all my login/passwords to configfile.ini.secret and left example login/passwords in configfile.ini
Instead of just hardcoding the .secret, you could daisy-chain the files by having the name of the next file in the previous one.
Something like (and perl syntax is probably wrong)
Or you could put files in a config.d directory and process all in alfabetical order.