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, |
4f4fd192 |
36 | ); |
526e74d1 |
37 | |
b750d2f1 |
38 | has 'deferrable' => ( |
39 | is => 'rw', |
40 | isa => Bool, |
075b652f |
41 | default => 1 |
b750d2f1 |
42 | ); |
43 | |
44 | has 'expression' => ( |
45 | is => 'rw', |
46 | isa => Str, |
47 | ); |
48 | |
d63c8da0 |
49 | has 'reference_table' => ( |
50 | isa => Maybe[Str], |
51 | is => 'rw', |
52 | ); |
53 | |
54 | has 'reference_columns' => ( |
106f5e00 |
55 | isa => ArrayRef, |
56 | traits => ['Array'], |
57 | handles => { |
58 | reference_columns => 'elements', |
59 | }, |
60 | default => sub { [] }, |
cb13230a |
61 | ); |
62 | |
63 | has 'match_type' => ( |
64 | isa => Str, |
d191bceb |
65 | is => 'rw', |
66 | lazy => 1, |
67 | default => '' |
d63c8da0 |
68 | ); |
69 | |
51700db2 |
70 | around add_column(Column $column) { $self->$orig($column->name, $column) } |
4f4fd192 |
71 | } |