-
Notifications
You must be signed in to change notification settings - Fork 2
/
LoadGolpe.pm
54 lines (34 loc) · 945 Bytes
/
LoadGolpe.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package LoadGolpe;
use strict;
use YAML;
sub load {
die "app-def.yaml is deprecated, use golpe.yaml" if -e "./app-def.yaml";
die "schema.yaml is deprecated, use golpe.yaml" if -e "./schema.yaml";
my $output = YAML::LoadFile('./golpe.yaml');
for my $app (split / /, $ENV{APPS}) {
my $file = "./src/apps/$app/golpe.yaml";
next if !-e $file;
my $output2 = YAML::LoadFile($file);
$output = merge($output, $output2);
}
return $output;
}
sub merge {
my $x = shift;
my $y = shift;
return $y if !defined $x;
return $x if !defined $y;
die "type mismatch in app's golpe.yaml" if ref($x) ne ref($y);
if (ref($x) eq 'ARRAY') {
return [ @$x, @$y ];
}
if (ref($x) eq 'HASH') {
my $o = { %$x, };
foreach my $k (keys %$y) {
$o->{$k} = merge($x->{$k}, $y->{$k});
}
return $o;
}
return $y;
}
1;