Skip to content

Commit fe3e94f

Browse files
committed
add ${VAR} replacement support to config
This supports ${VAR}, ${VAR:-default}, and ${VAR:+set} variable replacements to allow overridable config variables.
1 parent 6777b50 commit fe3e94f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/MetaCPAN/Server/Config.pm

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,28 @@ sub _zomg {
3636
my $v = Data::Visitor::Callback->new(
3737
plain_value => sub {
3838
return unless defined $_;
39-
s{__HOME__}{$root}ge;
39+
s{
40+
(__HOME__)
41+
|
42+
(\$\{([^\}]+)\})
43+
}{
44+
defined $1 ? $root
45+
: defined $2 ? do {
46+
my $var = $3;
47+
if ($var =~ s{:-(.*)}{}) {
48+
my $sub = $1;
49+
$ENV{$var} // $1;
50+
}
51+
elsif ($var =~ s{:\+(.*)}{}) {
52+
my $sub = $1;
53+
$ENV{$var} ? $sub : '';
54+
}
55+
else {
56+
$ENV{$var} // '';
57+
}
58+
}
59+
: ''
60+
}gex;
4061
}
4162
);
4263
$v->visit($c);

0 commit comments

Comments
 (0)