coerce a Column from a HashRef via Column->new
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Types.pm
CommitLineData
a8eeeefc 1use MooseX::Declare;
2class SQL::Translator::Types {
59109131 3 use MooseX::Types::Moose qw(ArrayRef CodeRef HashRef Int Maybe Str Undef);
ada068ed 4 use MooseX::Types -declare, [qw(Column Constraint ForeignKey Index PrimaryKey Procedure Schema Sequence Table Trigger View
5 Bit DBIHandle ColumnSize Parser Producer Translator)];
a8eeeefc 6
7 class_type Column, { class => 'SQL::Translator::Object::Column' };
8 class_type Constraint, { class => 'SQL::Translator::Object::Constraint' };
9 class_type ForeignKey, { class => 'SQL::Translator::Object::ForeignKey' };
10 class_type Index, { class => 'SQL::Translator::Object::Index' };
11 class_type PrimaryKey, { class => 'SQL::Translator::Object::PrimaryKey' };
12 class_type Procedure, { class => 'SQL::Translator::Object::Procedure' };
13 class_type Schema, { class => 'SQL::Translator::Object::Schema' };
14 class_type Sequence, { class=> 'SQL::Translator::Object::Sequence' };
15 class_type Table, { class => 'SQL::Translator::Object::Table' };
16 class_type Trigger, { class => 'SQL::Translator::Object::Trigger' };
17 class_type View, { class => 'SQL::Translator::Object::View' };
18
19 class_type Parser, { class => 'SQL::Translator::Parser' };
20 class_type Producer, { class => 'SQL::Translator::Producer' };
1c355765 21 class_type Translator, { class => 'SQL::Translator' };
1e0243f3 22
59109131 23 coerce Column,
24 from HashRef, via { SQL::Translator::Object::Column->new($_) };
25
ada068ed 26 subtype Bit, as Int, where { $_ == 1 || $_ == 0 };
27 coerce Bit,
28 from Undef, via { 0 },
29 from Str, via { $_ eq '1' ? 1 : 0 };
30
a8eeeefc 31 subtype ColumnSize, as ArrayRef[Int];
32 coerce ColumnSize,
33 from Int, via { [ $_ ] },
34 from Str, via { [ split /,/ ] },
35 from Undef, via { [ 0 ] };
1e0243f3 36
a8eeeefc 37 subtype DBIHandle, as 'DBI::db';
38
39 coerce DBIHandle,
40 from Str,
41 via(\&_coerce_dbihandle_from_str),
42 from ArrayRef,
43 via(\&_coerce_dbihandle_from_arrayref);
44 from CodeRef,
45 via(\&_coerce_dbihandle_from_coderef);
46
47 sub coerce_dbihandle_from_str { }
48 sub coerce_dbihandle_from_arrayref { }
49 sub coerce_dbihandle_from_coderef { }
50
51}