Exactly!
It just seems like a logical abstraction that i find it hard to believe that someone hasn't done it before. either that, or i am missing something.
I mean, it seems facile to come up with a very basic DTD which only specified column names and a series of regexps which that column data must match in order to be accepted.
Of course, this only allows 'intra' data checking; there is still the 'inter'-data checking - looking up external databases to see if X has been entered before etc etc...
either way, being able to specify column data semantics in an external file certainly has it's virtues -- it would be such a simple thing to wrap this in an object:
package SyntaxChecker;
our $Column_Definitions = {};
BEGIN {
load_definitions();
}
sub new
{
my $proto = shift;
my $column_name = shift || die;
my $class = ref $proto || $proto;
my $this = {
column_name => $column_name,
column_definition => $class->_get_definition(
$column_name ),
regexp => [ $class->_get_regexps( $column_name) ],
regexp_cache => [],
};
return $this;
}
sub get_cached_regexps
{
my $this = shift;
return @{ $this->{'regexp_cache'} };
}
sub validate
{
my $this = shift;
my $input_data = shift || die;
my $matched;
if ( my @regexps = $this->_get_cached_regexps() ) {
foreach my $regexp_sub ( @regexps ) {
$regexp_sub->( $input_data ) ||
die $this->{'column_definition'};
$matched++;
}
} else {
foreach my $regexp ( @{$this->{'regexp'}} ) {
my $code = eval "sub{ $input_data =~ $regexp }";
push @{ $this->{'regexp_cache'} }, $code;
}
return $this->validate( $input_data );
}
return $matched;
}
ok, so it's not a complete module -- no error checks or accessors or xml loading/parsing, but that took me all of 20 minutes, so a complete version wouldn't be much extra...
just need a good DTD for the xml description... any takers???
d_i_r_t_y
|