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; }