X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FTypes.pm;h=2fc13f4a7508ddba10eeaee2abcbc30c00cae02d;hb=8e1b1e1d2c93e670f12e583d4f863cc70a20a29a;hp=fd61352f059901dae1636a3484c1d6aa2b715a21;hpb=ada068ed4adab55a4bd5a26269f8ef34bceeb6e6;p=dbsrgits%2FSQL-Translator-2.0-ish.git diff --git a/lib/SQL/Translator/Types.pm b/lib/SQL/Translator/Types.pm index fd61352..2fc13f4 100644 --- a/lib/SQL/Translator/Types.pm +++ b/lib/SQL/Translator/Types.pm @@ -1,8 +1,13 @@ use MooseX::Declare; class SQL::Translator::Types { - use MooseX::Types::Moose qw(ArrayRef CodeRef Int Maybe Str Undef); + use MooseX::Types::Moose qw(ArrayRef CodeRef HashRef Int Maybe Str Undef); + use MooseX::Types::Parameterizable qw(Parameterizable); 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 DBICSchema IxHash + ColumnHash ConstraintHash IndexHash ProcedureHash SequenceHash TableHash TriggerHash ViewHash)]; + use Tie::IxHash; + + class_type DBICSchema, { class => 'DBIx::Class::Schema' }; class_type Column, { class => 'SQL::Translator::Object::Column' }; class_type Constraint, { class => 'SQL::Translator::Object::Constraint' }; @@ -20,16 +25,28 @@ class SQL::Translator::Types { class_type Producer, { class => 'SQL::Translator::Producer' }; class_type Translator, { class => 'SQL::Translator' }; + coerce Column, from HashRef, via { SQL::Translator::Object::Column->new($_) }, + from Str, via { SQL::Translator::Object::Column->new( name => $_ ) }; + 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 { $_ eq '1' ? 1 : 0 }; - - subtype ColumnSize, as ArrayRef[Int]; - coerce ColumnSize, - from Int, via { [ $_ ] }, - from Str, via { [ split /,/ ] }, - from Undef, via { [ 0 ] }; + from Str, via { length() ? 1 : 0 }; subtype DBIHandle, as 'DBI::db'; @@ -44,5 +61,16 @@ class SQL::Translator::Types { sub coerce_dbihandle_from_str { } sub coerce_dbihandle_from_arrayref { } sub coerce_dbihandle_from_coderef { } - + + subtype IxHash, as 'Tie::IxHash'; + coerce IxHash, from HashRef, via { Tie::IxHash->new($_) }; + + subtype ColumnHash, as Parameterizable[IxHash, Maybe[Column]]; + subtype ConstraintHash, as Parameterizable[IxHash, Maybe[Constraint]]; + subtype IndexHash, as Parameterizable[IxHash, Maybe[Index]]; + subtype ProcedureHash, as Parameterizable[IxHash, Maybe[Procedure]]; + subtype SequenceHash, as Parameterizable[IxHash, Maybe[Sequence]]; + subtype TableHash, as Parameterizable[IxHash, Maybe[Table]]; + subtype TriggerHash, as Parameterizable[IxHash, Maybe[Trigger]]; + subtype ViewHash, as Parameterizable[IxHash, Maybe[View]]; }