add back compat attributes
[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);
4     use MooseX::AttributeHelpers;
5     use SQL::Translator::Types qw(Column);
6     extends 'SQL::Translator::Object';
7     
8     has 'name' => (
9         is => 'rw',
10         isa => Maybe[Str],
11         required => 1
12     );
13     
14     has 'columns' => (
15         metaclass => 'Collection::Hash',
16         is => 'rw',
17         isa => HashRef[Column],
18         provides => {
19             exists => 'exists_column',
20             keys   => 'column_ids',
21             values => 'get_columns',
22             get    => 'get_column',
23         },
24         curries => {
25             set => {
26                 add_column => sub {
27                     my ($self, $body, $column) = @_;
28                     $self->$body($column->name, $column);
29                 }
30             }
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 'options' => (
53         is => 'rw',
54         isa => ArrayRef,
55         auto_deref => 1
56     );
57
58     has 'extra' => (
59         is => 'rw',
60         isa => HashRef,
61         auto_deref => 1,
62     );
63
64     method get_fields { return $self->get_columns }
65     method fields { return $self->column_ids }
66     method field_names { return $self->column_ids }
67
68     method match_type { }
69 }