What I've got thus far, is modified via an email sent to a specific (secured) account on an internal control box. In this email body is a template, pseudo-XML, which contains the options I want to pass to the system binary in 'key = value' pairs, and looks like this:
<tmpl> foo = 1 bar = SomeThing blort = 2003-06-29 </tmpl>
I detach this template from the body of the email with Mail::Internet as follows:
my $message = new Mail::Internet ([<>]); my @body = @{$message->body()};
From here, I parse it out with Config::General, and end up with things like this:
my %config = $conf->getall; my $template = $conf->obj('tmpl'); my $foo = $config{'tmpl'}->{'foo'}; my $bar = $config{'tmpl'}->{'bar'}; my $blort = $config{'tmpl'}->{'blort'}; # ... up to 40 possible values
When I have these all in scalars, I go through them one-by-one, and validate each, to make sure I didn't pass any typos or other invalid values. for example, the key 'foo' in the template can only take a digit, so I can restrict that, and check it. The next key, 'bar' may only take a common word, starting with a capital letter. I can also check that. You can see how lengthy this gets after 40 possible values need to be stuffed into scalars and checked for proper syntax and validity.
Is there a better way to parse, accept, and validate each of these values from the template, without duplicating 40 separate checks for each value that can be passed?
In reply to A Refactoring We Will Go by hacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |