X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FTypes.pm;h=143f31bcee8106b182f952393d1eca987efae5a6;hb=a499b4bdb67f16a5a7f0934c52104895f7321f97;hp=f8eb10cc6b6be7cb5d00da8b45e286c928699c64;hpb=850220add003688ea91d67b11965ee81e94c4cab;p=dbsrgits%2FSQL-Translator-2.0-ish.git diff --git a/lib/SQL/Translator/Types.pm b/lib/SQL/Translator/Types.pm index f8eb10c..143f31b 100644 --- a/lib/SQL/Translator/Types.pm +++ b/lib/SQL/Translator/Types.pm @@ -1,8 +1,11 @@ use MooseX::Declare; class SQL::Translator::Types { 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 MatchType Parser Producer Translator DBICSchema)]; + 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' }; @@ -42,7 +45,7 @@ class SQL::Translator::Types { subtype Bit, as Int, where { $_ == 1 || $_ == 0 }; coerce Bit, from Undef, via { 0 }, - from Str, via { $_ eq '1' ? 1 : 0 }; + from Str, via { length() ? 1 : 0 }; subtype DBIHandle, as 'DBI::db'; @@ -57,5 +60,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]]; }