From: Ken Youens-Clark Date: Wed, 11 Jun 2003 03:58:53 +0000 (+0000) Subject: Added validation code. X-Git-Tag: v0.02~34 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f4af30dea542a6e98ef7980abbc539ea942638a;p=dbsrgits%2FSQL-Translator.git Added validation code. --- diff --git a/lib/SQL/Translator.pm b/lib/SQL/Translator.pm index 9c0cf38..c809887 100644 --- a/lib/SQL/Translator.pm +++ b/lib/SQL/Translator.pm @@ -1,7 +1,7 @@ package SQL::Translator; # ---------------------------------------------------------------------- -# $Id: Translator.pm,v 1.27 2003-05-09 19:51:28 kycl4rk Exp $ +# $Id: Translator.pm,v 1.28 2003-06-11 03:58:53 kycl4rk Exp $ # ---------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # darren chamberlain , @@ -27,7 +27,7 @@ use vars qw( $VERSION $REVISION $DEFAULT_SUB $DEBUG $ERROR ); use base 'Class::Base'; $VERSION = '0.01'; -$REVISION = sprintf "%d.%02d", q$Revision: 1.27 $ =~ /(\d+)\.(\d+)/; +$REVISION = sprintf "%d.%02d", q$Revision: 1.28 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; $ERROR = ""; @@ -115,6 +115,8 @@ sub init { $self->trace( $config->{'trace'} ); + $self->validate( $config->{'validate'} ); + return $self; } @@ -557,7 +559,12 @@ sub translate { return $self->error($msg); } - eval { $producer_output = $producer->($self, $parser_output) }; + if ( $self->validate ) { + my $schema = $self->schema; + return $self->error('Invalid schema') unless $schema->is_valid; + } + + eval { $producer_output = $producer->($self) }; if ($@ || ! $producer_output) { my $msg = sprintf "translate: Error with producer '%s': %s", $producer_type, ($@) ? $@ : " no results"; @@ -636,7 +643,6 @@ sub _args { $self->{$type}; } - # ---------------------------------------------------------------------- # _list($type) # ---------------------------------------------------------------------- @@ -728,6 +734,27 @@ sub isa($$) { return UNIVERSAL::isa($ref, $type); } +# ---------------------------------------------------------------------- +sub validate { + +=pod + +=head2 validate + +Get or set whether to validate the parsed data. + + my $validate = $schema->validate(1); + +=cut + + my ( $self, $arg ) = @_; + if ( defined $arg ) { + $self->{'validate'} = $arg ? 1 : 0; + } + return $self->{'validate'} || 0; +} + + 1; #----------------------------------------------------- # Rescue the drowning and tie your shoestrings.