From: Justin Hunter Date: Sat, 3 Oct 2009 16:47:08 +0000 (-0700) Subject: remove ColumnSize and add MatchType X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3c557f72797892b38f71c51bccfa9711620569b4;p=dbsrgits%2FSQL-Translator-2.0-ish.git remove ColumnSize and add MatchType --- diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index d06923b..af973f2 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -2,7 +2,7 @@ use MooseX::Declare; class SQL::Translator::Object::Column extends SQL::Translator::Object is dirty { use MooseX::Types::Moose qw(Bool Int Maybe ScalarRef Str); use MooseX::MultiMethods; - use SQL::Translator::Types qw(Bit ColumnSize Constraint Table Trigger); + use SQL::Translator::Types qw(Bit Constraint Table Trigger); clean; use overload diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index 7ed4c71..d3ea621 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -2,7 +2,7 @@ use MooseX::Declare; class SQL::Translator::Object::Constraint extends SQL::Translator::Object { use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str Undef); use MooseX::MultiMethods; - use SQL::Translator::Types qw(Column Table); + use SQL::Translator::Types qw(Column MatchType Table); has 'table' => ( is => 'rw', @@ -61,8 +61,9 @@ class SQL::Translator::Object::Constraint extends SQL::Translator::Object { ); has 'match_type' => ( - isa => Str, + isa => MatchType, is => 'rw', + coerce => 1, lazy => 1, default => '' ); diff --git a/lib/SQL/Translator/Types.pm b/lib/SQL/Translator/Types.pm index 62cd428..89dc8cc 100644 --- a/lib/SQL/Translator/Types.pm +++ b/lib/SQL/Translator/Types.pm @@ -2,7 +2,7 @@ use MooseX::Declare; class SQL::Translator::Types { use MooseX::Types::Moose qw(ArrayRef CodeRef HashRef Int Maybe Str Undef); use MooseX::Types -declare, [qw(Column Constraint ForeignKey Index PrimaryKey Procedure Schema Sequence Table Trigger View - Bit DBIHandle ColumnSize Parser Producer Translator)]; + Bit DBIHandle MatchType Parser Producer Translator)]; class_type Column, { class => 'SQL::Translator::Object::Column' }; class_type Constraint, { class => 'SQL::Translator::Object::Constraint' }; @@ -32,17 +32,14 @@ class SQL::Translator::Types { coerce Trigger, from HashRef, via { SQL::Translator::Object::Trigger->new($_) }; coerce View, from HashRef, via { SQL::Translator::Object::View->new($_) }; + subtype MatchType, as Str, where { /^(full|partial|simple)$/ || $_ eq '' }; + coerce MatchType, from Str, via { lc $_ }; + subtype Bit, as Int, where { $_ == 1 || $_ == 0 }; coerce Bit, from Undef, via { 0 }, from Str, via { $_ eq '1' ? 1 : 0 }; - subtype ColumnSize, as ArrayRef[Int]; - coerce ColumnSize, - from Int, via { [ $_ ] }, - from Str, via { [ split /,/ ] }, - from Undef, via { [ 0 ] }; - subtype DBIHandle, as 'DBI::db'; coerce DBIHandle,