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