Commit | Line | Data |
a8eeeefc |
1 | use MooseX::Declare; |
2 | class SQL::Translator::Types { |
59109131 |
3 | use MooseX::Types::Moose qw(ArrayRef CodeRef HashRef Int Maybe Str Undef); |
a499b4bd |
4 | use MooseX::Types::Parameterizable qw(Parameterizable); |
ada068ed |
5 | use MooseX::Types -declare, [qw(Column Constraint ForeignKey Index PrimaryKey Procedure Schema Sequence Table Trigger View |
a499b4bd |
6 | Bit DBIHandle MatchType Parser Producer Translator DBICSchema IxHash |
7 | ColumnHash ConstraintHash IndexHash ProcedureHash SequenceHash TableHash TriggerHash ViewHash)]; |
8 | use Tie::IxHash; |
c3653d16 |
9 | |
850220ad |
10 | class_type DBICSchema, { class => 'DBIx::Class::Schema' }; |
a8eeeefc |
11 | |
12 | class_type Column, { class => 'SQL::Translator::Object::Column' }; |
13 | class_type Constraint, { class => 'SQL::Translator::Object::Constraint' }; |
14 | class_type ForeignKey, { class => 'SQL::Translator::Object::ForeignKey' }; |
15 | class_type Index, { class => 'SQL::Translator::Object::Index' }; |
16 | class_type PrimaryKey, { class => 'SQL::Translator::Object::PrimaryKey' }; |
17 | class_type Procedure, { class => 'SQL::Translator::Object::Procedure' }; |
18 | class_type Schema, { class => 'SQL::Translator::Object::Schema' }; |
19 | class_type Sequence, { class=> 'SQL::Translator::Object::Sequence' }; |
20 | class_type Table, { class => 'SQL::Translator::Object::Table' }; |
21 | class_type Trigger, { class => 'SQL::Translator::Object::Trigger' }; |
22 | class_type View, { class => 'SQL::Translator::Object::View' }; |
23 | |
24 | class_type Parser, { class => 'SQL::Translator::Parser' }; |
25 | class_type Producer, { class => 'SQL::Translator::Producer' }; |
1c355765 |
26 | class_type Translator, { class => 'SQL::Translator' }; |
1e0243f3 |
27 | |
e9776208 |
28 | coerce Column, from HashRef, via { SQL::Translator::Object::Column->new($_) }; |
f5605c1d |
29 | coerce Constraint, from HashRef, via { SQL::Translator::Object::Constraint->new($_) }; |
30 | coerce ForeignKey, from HashRef, via { SQL::Translator::Object::ForeignKey->new($_) }; |
e9776208 |
31 | coerce Index, from HashRef, via { SQL::Translator::Object::Index->new($_) }; |
f5605c1d |
32 | coerce PrimaryKey, from HashRef, via { SQL::Translator::Object::PrimaryKey->new($_) }; |
33 | coerce Procedure, from HashRef, via { SQL::Translator::Object::Procedure->new($_) }; |
34 | coerce Schema, from HashRef, via { SQL::Translator::Object::Schema->new($_) }; |
35 | coerce Sequence, from HashRef, via { SQL::Translator::Object::Sequence->new($_) }; |
36 | coerce Table, from HashRef, via { SQL::Translator::Object::Table->new($_) }; |
37 | coerce Trigger, from HashRef, via { SQL::Translator::Object::Trigger->new($_) }; |
38 | coerce View, from HashRef, via { SQL::Translator::Object::View->new($_) }; |
59109131 |
39 | |
59ad6549 |
40 | coerce ArrayRef, from Str, via { [ $_ ] }; |
41 | |
3c557f72 |
42 | subtype MatchType, as Str, where { /^(full|partial|simple)$/ || $_ eq '' }; |
43 | coerce MatchType, from Str, via { lc $_ }; |
44 | |
ada068ed |
45 | subtype Bit, as Int, where { $_ == 1 || $_ == 0 }; |
46 | coerce Bit, |
47 | from Undef, via { 0 }, |
e3582697 |
48 | from Str, via { length() ? 1 : 0 }; |
ada068ed |
49 | |
a8eeeefc |
50 | subtype DBIHandle, as 'DBI::db'; |
51 | |
52 | coerce DBIHandle, |
53 | from Str, |
54 | via(\&_coerce_dbihandle_from_str), |
55 | from ArrayRef, |
56 | via(\&_coerce_dbihandle_from_arrayref); |
57 | from CodeRef, |
58 | via(\&_coerce_dbihandle_from_coderef); |
59 | |
60 | sub coerce_dbihandle_from_str { } |
61 | sub coerce_dbihandle_from_arrayref { } |
62 | sub coerce_dbihandle_from_coderef { } |
a499b4bd |
63 | |
64 | subtype IxHash, as 'Tie::IxHash'; |
65 | coerce IxHash, from HashRef, via { Tie::IxHash->new($_) }; |
66 | |
67 | subtype ColumnHash, as Parameterizable[IxHash, Maybe[Column]]; |
68 | subtype ConstraintHash, as Parameterizable[IxHash, Maybe[Constraint]]; |
69 | subtype IndexHash, as Parameterizable[IxHash, Maybe[Index]]; |
70 | subtype ProcedureHash, as Parameterizable[IxHash, Maybe[Procedure]]; |
71 | subtype SequenceHash, as Parameterizable[IxHash, Maybe[Sequence]]; |
72 | subtype TableHash, as Parameterizable[IxHash, Maybe[Table]]; |
73 | subtype TriggerHash, as Parameterizable[IxHash, Maybe[Trigger]]; |
74 | subtype ViewHash, as Parameterizable[IxHash, Maybe[View]]; |
a8eeeefc |
75 | } |