Commit | Line | Data |
4f4fd192 |
1 | use MooseX::Declare; |
ebf2721d |
2 | class SQL::Translator::Object::Constraint extends SQL::Translator::Object { |
f49a2a49 |
3 | use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str Undef); |
035b8503 |
4 | use MooseX::MultiMethods; |
f49a2a49 |
5 | use SQL::Translator::Types qw(Column Table); |
f49a2a49 |
6 | |
7 | has 'table' => ( |
8 | is => 'rw', |
9 | isa => Table, |
f49a2a49 |
10 | weak_ref => 1, |
11 | ); |
4f4fd192 |
12 | |
13 | has 'name' => ( |
14 | is => 'rw', |
526e74d1 |
15 | isa => Maybe[Str], |
4f4fd192 |
16 | required => 1 |
17 | ); |
18 | |
19 | has 'columns' => ( |
28bd628e |
20 | traits => ['Hash'], |
4f4fd192 |
21 | is => 'rw', |
22 | isa => HashRef[Column], |
28bd628e |
23 | handles => { |
24 | exists_column => 'exists', |
25 | column_ids => 'keys', |
26 | get_columns => 'values', |
27 | get_column => 'get', |
28 | add_column => 'set', |
4f4fd192 |
29 | }, |
30 | default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, |
31 | ); |
32 | |
33 | has 'type' => ( |
34 | is => 'rw', |
35 | isa => Str, |
36 | required => 1 |
37 | ); |
526e74d1 |
38 | |
b750d2f1 |
39 | has 'deferrable' => ( |
40 | is => 'rw', |
41 | isa => Bool, |
075b652f |
42 | default => 1 |
b750d2f1 |
43 | ); |
44 | |
45 | has 'expression' => ( |
46 | is => 'rw', |
47 | isa => Str, |
48 | ); |
49 | |
d63c8da0 |
50 | has 'reference_table' => ( |
51 | isa => Maybe[Str], |
52 | is => 'rw', |
53 | ); |
54 | |
55 | has 'reference_columns' => ( |
106f5e00 |
56 | isa => ArrayRef, |
57 | traits => ['Array'], |
58 | handles => { |
59 | reference_columns => 'elements', |
60 | }, |
61 | default => sub { [] }, |
cb13230a |
62 | ); |
63 | |
64 | has 'match_type' => ( |
65 | isa => Str, |
66 | is => 'rw' |
d63c8da0 |
67 | ); |
68 | |
51700db2 |
69 | around add_column(Column $column) { $self->$orig($column->name, $column) } |
70 | |
6b4be44b |
71 | method reference_fields { $self->reference_columns } |
4f4fd192 |
72 | } |