package SQL::Translator::Validator;
# ----------------------------------------------------------------------
-# $Id: Validator.pm,v 1.5 2002-11-22 03:03:40 kycl4rk Exp $
+# $Id: Validator.pm,v 1.8 2003-04-17 13:42:44 dlc Exp $
# ----------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw($VERSION @EXPORT);
-$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/;
use Exporter;
use base qw(Exporter);
$log .= "\n\tIndices:";
if (@indices) {
for my $index (@indices) {
+ next unless ref($index) eq 'HASH';
+ next unless scalar keys %$index;
$log .= "\n\t\t" . ($index->{"name"} || "(unnamed)")
. " on "
- . join ", ", @{$index->{"fields"}};
+ . join ", ", @{$index->{"fields"} ||= []};
}
} else {
$log .= " none defined";
=head1 SYNOPSIS
- print "1..1\n";
-
+ use Test::More plan tests => 1;
use SQL::Translator;
use SQL::Translator::Validator;
# Default producer passes the data structure through unchanged
my $parsed = $tr->translate($datafile);
- print "not " unless validate($parsed);
- print "ok 1 # data structure looks OK\n";
+ ok(validate($parsed), "data structure conformance to definition");
=head1 DESCRIPTION
or, potentially, even as a runtime assertion for producers you don't
trust:
- $tr->producer(\¶noid_producer);
+ $tr->producer(\¶noid_producer, real_producer => "MySQL");
sub paranoid_producer {
my ($tr, $data) = @_;
- return unless validate($data);
+ validate($data) or die "You gave me crap!"
- # continue...
+ # Load real producer, and execute it
+ $tr->producer($tr->producer_args->{'real_producer'});
+ return $tr->produce($data);
+ }
SQL::Translator::Validator can also be used as a reporting tool. When
B<validate> is called in a list context, the second value returned