move from curries to provides => { set => 'add_...' } and around add_... { }
[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             set    => 'add_column',
24         },
25         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
26     );
27     
28     has 'type' => (
29         is => 'rw',
30         isa => Str,
31         required => 1
32     );
33
34     has 'deferrable' => (
35         is => 'rw',
36         isa => Bool,
37         default => 0
38     );
39
40     has 'expression' => (
41         is => 'rw',
42         isa => Str,
43     );
44
45     has 'options' => (
46         is => 'rw',
47         isa => ArrayRef,
48         auto_deref => 1
49     );
50
51     has 'extra' => (
52         is => 'rw',
53         isa => HashRef,
54         auto_deref => 1,
55     );
56
57     around add_column(Column $column) { $self->$orig($column->name, $column) }
58
59     method get_fields { return $self->get_columns }
60     method fields { return $self->column_ids }
61     method field_names { return $self->column_ids }
62
63     method match_type { }
64 }