11
my $conditions = shift;
12
(ref($conditions) eq "HASH") or die "Ah, shit";
15
if (ref($plugin) eq "ARRAY") {
16
foreach my $subvalue (@{$plugin}) {
17
$matches ||= check_matches($subvalue, $conditions);
22
(ref($plugin) eq "HASH") or return 0;
23
(scalar(keys(%$conditions)) == 0) && return 1;
25
foreach my $key (keys(%$conditions)) {
27
if (ref($conditions->{$key}) eq "HASH") {
28
$matches = check_matches($plugin->{$key}, $conditions->{$key});
29
} elsif (ref($conditions->{$key}) eq "ARRAY") {
31
foreach my $condition (@{$conditions->{$key}}) {
32
$matches &&= check_matches($plugin->{$key}, $condition);
35
if (exists($plugin->{$key}) and ref($plugin->{$key}) ne "HASH" and ref($plugin->{$key}) ne "ARRAY") {
36
$matches = $conditions->{$key} =~ /[\+\?\.\*\^\$\(\)\[\]\{\}\|\\]*/ ?
37
($plugin->{$key} =~ /$conditions->{$key}/) :
38
($plugin->{$key} eq $conditions->{$key});
47
sub verify_overrides {
51
my $overrides = shift;
53
my @plugins = sort(<$dir/$lang/*.xml>);
54
foreach my $plugin (@plugins) {
55
my $xml = new XML::Simple;
56
my $data = $xml->XMLin($plugin, keyattr => []);
59
foreach my $conditions (@{$config->{'matches'}}) {
60
$matches = check_matches($data, $conditions);
63
foreach my $conditions (@{$config->{'ignore'}}) {
64
$matches &&= not check_matches($data, $conditions);
68
my $id = basename($plugin);
70
my @arr = @{$overrides->{$lang}};
71
my ($index) = grep($arr[$_] eq $id, 0..$#arr);
72
$matches ^ defined($index) and die "Verification failed for $id search plugin in $lang";
87
defined($dir) or die "Missing options";
89
open(CONFIG, "debian/searchplugins/compute-overrides.json") or die "Cannot open config";
91
while (<CONFIG>) { $json .= $_; }
93
$config = JSON::decode_json($json);
95
open(LIST, "debian/config/search-mods.list") and do {
98
if (/^\[Overrides\]$/) {
100
} elsif ($parsing == 1) {
103
} elsif (/^([^\:]*)\:(.*)/) {
104
my @l = split(',', $2);
105
map($_ = basename($_), @l);
106
map($_ =~ s/\.xml$//, @l);
107
$overrides{$1} = \@l;
113
open(SHIPPED_LOCALES, "debian/config/locales.shipped") or die "Cannot open list of shipped locales";
114
while(<SHIPPED_LOCALES>) {
115
$_ =~ s/#.*//; s/\s*$//;
116
/^([^\:]*)\:.*/ and do {
117
verify_overrides($dir, $1, $config, \%overrides);
120
close(SHIPPED_LOCALES);