如何插入环境变量与Config:: Config::Any的一般设置。这是从我的OX应用程序中提取的配置片段,它返回在我的.conf
fine中指定的数据,除了我不能让它识别环境变量。
has config => (
isa => 'HashRef',
is => 'ro',
lifecycle => 'Singleton',
dependencies => ['config_file'],
block => sub {
my $s = shift;
my $cfg
= load_class('Config::Any')->load_files({
flatten_to_hash => 1,
use_ext => 1,
files => [ $s->param('config_file') ],
General => {
-InterPolateEnv => 1,
},
});
return $cfg->{ $s->param('config_file') };
},
);
这里是我的config
的几个尝试<db>
dsn $PERL_FEEDER_DSN
</db>
<db>
dsn $ENV{PERL_FEEDER_DSN}
</db>
这两种方法都以包含文字$...
的dsn结束。
我以前做过这个,但是我不知道我是怎么做的,或者我可能做错了什么。
您需要将-InterPolateEnv => 1
与-InterPolateVars => 1
一起指定,以便加载Config::General::Interpolated
。据我所知,-InterPolateEnv => 1
本身并不触发该模块的加载。
#!/usr/bin/env perl
use strict;
use warnings;
use Config::General;
my $conf = new Config::General(
-ConfigFile => 'test.conf',
-InterPolateEnv => 1,
-InterPolateVars => 1,
);
use YAML;
print Dump { $conf->getall };
配置文件:<>以前& lt; db>dsn PERL_FEEDER_DSN美元& lt;/db> 之前输出:<>之前,db:dsn:测试