Might help to see what format you want your config file to be in. But here's a quick hack. There might be ways to make it tighter in terms of variable scope and regex and so on, but it should work and be safe:
use strict;
use warnings; no warnings 'uninitialized';
my (%cond, %func, @config, %config, $cond, $func);
### Sample function
sub FUNC { print "Successful condition.\n"; }
### Config values to allow in conditions
$cond{$_}++ for qw/COND1 COND2 COND3/;
### Functions that can be called upon successful condition
$func{$_}++ for qw/FUNC/;
### Eliminate potential exploits, convert operators
sub c_parse {
return $_[0] if $cond{$_[0]};
return '&&' if $_[0] eq 'AND';
return '||' if $_[0] eq 'OR';
}
### Safe the config file, store pre-processed results for later
sub c_initialize {
while (<DATA>) {
chomp; ($cond, $func) = split / /;
$cond =~ s/[^\w\(\) ]+/ /g;
$cond =~ s/(\w+)/c_parse($1)/eg;
$func =~ s/\W+//g;
return if !$func{$func};
push @config, [$cond, $func];
}
}
### Run through config looking for successful conditions
sub c_process {
print "Testing conditions.\n";
for (@config) {
($cond, $func) = @$_;
$cond =~ s/(\w+)/$config{$1} || 0/eg;
eval "$func\(\) if $cond";
}
}
c_initialize();
$config{COND1} = 1;
$config{COND3} = 1;
c_process();
$config{COND3} = 0;
c_process();
$config{COND2} = 1;
c_process();
__DATA__
COND1 AND (COND2 OR COND3) FUNC