X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FTypes.pm;h=3a6f84639ca58c7407e34ff4a8a17ca449d3509e;hb=8d112909f77db57e6cf0948ce0ee5e0323157ee4;hp=182636a4ee1b424c4d89c3b7b28de35d7b997481;hpb=1c3557654a365adf2563b4407f7a822a298838c9;p=dbsrgits%2FSQL-Translator-2.0-ish.git diff --git a/lib/SQL/Translator/Types.pm b/lib/SQL/Translator/Types.pm index 182636a..3a6f846 100644 --- a/lib/SQL/Translator/Types.pm +++ b/lib/SQL/Translator/Types.pm @@ -1,7 +1,10 @@ use MooseX::Declare; class SQL::Translator::Types { - use MooseX::Types::Moose qw(ArrayRef CodeRef Int Maybe Str Undef); - use MooseX::Types -declare, [qw(Column Constraint ForeignKey Index PrimaryKey Procedure Schema Sequence Table Trigger View DBIHandle ColumnSize Parser Producer Translator)]; + 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 MatchType Parser Producer Translator DBICSchema)]; + + class_type DBICSchema, { class => 'DBIx::Class::Schema' }; class_type Column, { class => 'SQL::Translator::Object::Column' }; class_type Constraint, { class => 'SQL::Translator::Object::Constraint' }; @@ -19,11 +22,27 @@ class SQL::Translator::Types { class_type Producer, { class => 'SQL::Translator::Producer' }; class_type Translator, { class => 'SQL::Translator' }; - subtype ColumnSize, as ArrayRef[Int]; - coerce ColumnSize, - from Int, via { [ $_ ] }, - from Str, via { [ split /,/ ] }, - from Undef, via { [ 0 ] }; + coerce Column, from HashRef, via { SQL::Translator::Object::Column->new($_) }; + coerce Constraint, from HashRef, via { SQL::Translator::Object::Constraint->new($_) }; + coerce ForeignKey, from HashRef, via { SQL::Translator::Object::ForeignKey->new($_) }; + coerce Index, from HashRef, via { SQL::Translator::Object::Index->new($_) }; + coerce PrimaryKey, from HashRef, via { SQL::Translator::Object::PrimaryKey->new($_) }; + coerce Procedure, from HashRef, via { SQL::Translator::Object::Procedure->new($_) }; + coerce Schema, from HashRef, via { SQL::Translator::Object::Schema->new($_) }; + coerce Sequence, from HashRef, via { SQL::Translator::Object::Sequence->new($_) }; + coerce Table, from HashRef, via { SQL::Translator::Object::Table->new($_) }; + coerce Trigger, from HashRef, via { SQL::Translator::Object::Trigger->new($_) }; + coerce View, from HashRef, via { SQL::Translator::Object::View->new($_) }; + + coerce ArrayRef, from Str, via { [ $_ ] }; + + 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 { length() ? 1 : 0 }; subtype DBIHandle, as 'DBI::db';