move options down to Object.pm
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Constraint.pm
1 use MooseX::Declare;
2 class SQL::Translator::Object::Constraint {
3     use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str Undef);
4     use MooseX::AttributeHelpers;
5     use SQL::Translator::Types qw(Column Table);
6     extends 'SQL::Translator::Object';
7
8     has 'table' => (
9         is => 'rw',
10         isa => Table,
11         required => 1,
12         weak_ref => 1,
13     );
14     
15     has 'name' => (
16         is => 'rw',
17         isa => Maybe[Str],
18         required => 1
19     );
20     
21     has 'columns' => (
22         metaclass => 'Collection::Hash',
23         is => 'rw',
24         isa => HashRef[Column],
25         provides => {
26             exists => 'exists_column',
27             keys   => 'column_ids',
28             values => 'get_columns',
29             get    => 'get_column',
30             set    => 'add_column',
31         },
32         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
33     );
34     
35     has 'type' => (
36         is => 'rw',
37         isa => Str,
38         required => 1
39     );
40
41     has 'deferrable' => (
42         is => 'rw',
43         isa => Bool,
44         default => 0
45     );
46
47     has 'expression' => (
48         is => 'rw',
49         isa => Str,
50     );
51
52     has 'reference_table' => (
53         isa => Maybe[Str],
54         is => 'rw',
55     );
56
57     has 'reference_columns' => (
58          isa => ArrayRef | Undef,
59          is => 'rw',
60          auto_deref => 1
61     );
62
63     has 'extra' => (
64         is => 'rw',
65         isa => HashRef,
66         auto_deref => 1,
67     );
68
69     around add_column(Column $column) { $self->$orig($column->name, $column) }
70
71     method get_fields { $self->get_columns }
72     method fields { $self->column_ids }
73     method field_names { $self->column_ids }
74
75     method reference_fields { $self->reference_columns }
76
77     method match_type { }
78 }