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