add curries where applicable
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Table.pm
1 package SQL::Translator::Object::Table;
2 use Moose;
3 use MooseX::Types::Moose qw(HashRef Str);
4 use MooseX::AttributeHelpers;
5 use SQL::Translator::Types qw(Column Constraint Index Schema);
6 use SQL::Translator::Object::Schema;
7 extends 'SQL::Translator::Object';
8
9 has 'name' => (
10   is => 'rw',
11   isa => Str,
12   required => 1
13 );
14
15 has 'columns' => (
16   metaclass => 'Collection::Hash',
17   is => 'rw',
18   isa => HashRef[Column],
19   provides => {
20     exists => 'exists_column',
21     keys   => 'column_ids',
22     get    => 'get_column',
23 #    set    => 'set_column',
24   },
25   curries => { set => { add_column => sub { my ($self, $body, $column) = @_; $self->$body($column->name, $column); } } },
26   default => sub { {} },
27   required => 0
28 );
29
30 has 'indexes' => (
31   metaclass => 'Collection::Hash',
32   is => 'rw',
33   isa => HashRef[Index],
34   provides => {
35     exists => 'exists_index',
36     keys   => 'index_ids',
37     get    => 'get_index',
38 #    set    => 'set_index',
39   },
40   curries => { set => { add_index => sub { my ($self, $body, $index) = @_; $self->$body($index->name, $index); } } },
41   default => sub { {} },
42   required => 0
43 );
44
45 has 'constraints' => (
46   metaclass => 'Collection::Hash',
47   is => 'rw',
48   isa => HashRef[Constraint],
49   provides => {
50     exists => 'exists_constraint',
51     keys   => 'constraint_ids',
52     get    => 'get_constraint',
53     set    => 'set_constraint',
54   },
55   default => sub { {} },
56   required => 0
57 );
58
59 =cut
60 has 'schema' => (
61   is => 'rw',
62   isa => Schema,
63   required => 0,
64   default => sub { SQL::Translator::Object::Schema->new }
65 );
66 =cut
67 no Moose;
68 __PACKAGE__->meta()->make_immutable;
69
70 1;