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, |
9 | required => 1, |
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' => ( |
cb13230a |
56 | isa => ArrayRef | Undef, |
57 | is => 'rw', |
58 | auto_deref => 1 |
59 | ); |
60 | |
61 | has 'match_type' => ( |
62 | isa => Str, |
63 | is => 'rw' |
d63c8da0 |
64 | ); |
65 | |
51700db2 |
66 | around add_column(Column $column) { $self->$orig($column->name, $column) } |
67 | |
6b4be44b |
68 | method get_fields { $self->get_columns } |
69 | method fields { $self->column_ids } |
70 | method field_names { $self->column_ids } |
71 | |
72 | method reference_fields { $self->reference_columns } |
4f4fd192 |
73 | } |