X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FSchema%2FConstraint.pm;h=d726aa50ea02344a4c4435f4bffb5946a5974e71;hb=62d2a1c3701f5247d496aa42a88e3149b5bc589c;hp=0fd43c130d68654d576bb2aa7107cde4f5426bde;hpb=68d75205c6994eb347f51726cea9bf3dbf28b498;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Schema/Constraint.pm b/lib/SQL/Translator/Schema/Constraint.pm index 0fd43c1..d726aa5 100644 --- a/lib/SQL/Translator/Schema/Constraint.pm +++ b/lib/SQL/Translator/Schema/Constraint.pm @@ -27,7 +27,7 @@ use Moo; use SQL::Translator::Schema::Constants; use SQL::Translator::Utils qw(ex2err throw); use SQL::Translator::Role::ListAttr; -use SQL::Translator::Types qw(schema_obj); +use SQL::Translator::Types qw(schema_obj enum); use Sub::Quote qw(quote_sub); extends 'SQL::Translator::Schema::Object'; @@ -88,7 +88,11 @@ False, so the following are eqivalent: =cut -has deferrable => ( is => 'rw', coerce => sub { $_[0] ? 1 : 0 }, default => quote_sub(q{ 1 }) ); +has deferrable => ( + is => 'rw', + coerce => quote_sub(q{ $_[0] ? 1 : 0 }), + default => quote_sub(q{ 1 }), +); =head2 expression @@ -222,12 +226,10 @@ Get or set the constraint's match_type. Only valid values are "full" has match_type => ( is => 'rw', default => quote_sub(q{ '' }), - coerce => sub { lc $_[0] }, - isa => sub { - my $arg = $_[0]; - throw("Invalid match type: $arg") - if $arg && !($arg eq 'full' || $arg eq 'partial' || $arg eq 'simple'); - }, + coerce => quote_sub(q{ lc $_[0] }), + isa => enum([qw(full partial simple)], { + msg => "Invalid match type: %s", allow_false => 1, + }), ); around match_type => \&ex2err; @@ -364,11 +366,10 @@ Get or set the constraint's type. has type => ( is => 'rw', default => quote_sub(q{ '' }), - isa => sub { - throw("Invalid constraint type: $_[0]") - if $_[0] && !$VALID_CONSTRAINT_TYPE{ $_[0] }; - }, - coerce => sub { (my $t = $_[0]) =~ s/_/ /g; uc $t }, + coerce => quote_sub(q{ (my $t = $_[0]) =~ s/_/ /g; uc $t }), + isa => enum([keys %VALID_CONSTRAINT_TYPE], { + msg => "Invalid constraint type: %s", allow_false => 1, + }), ); around type => \&ex2err;