Commit | Line | Data |
4f4fd192 |
1 | use MooseX::Declare; |
ebf2721d |
2 | class SQL::Translator::Object::Index extends SQL::Translator::Object { |
1c607f61 |
3 | use MooseX::Types::Moose qw(HashRef Str); |
f49a2a49 |
4 | use SQL::Translator::Types qw(Column Table); |
f49a2a49 |
5 | |
6 | has 'table' => ( |
7 | is => 'rw', |
8 | isa => Table, |
9 | required => 1, |
10 | weak_ref => 1, |
11 | ); |
4f4fd192 |
12 | |
13 | has 'name' => ( |
14 | is => 'rw', |
15 | isa => Str, |
16 | required => 1 |
17 | ); |
2850baeb |
18 | |
4f4fd192 |
19 | has 'columns' => ( |
28bd628e |
20 | traits => ['Hash'], |
4f4fd192 |
21 | is => 'rw', |
22 | isa => HashRef[Column], |
28bd628e |
23 | handles => { |
24 | exists_column => 'exists', |
25 | column_ids => 'keys', |
26 | get_columns => 'values', |
27 | get_column => 'get', |
28 | add_column => 'set', |
4f4fd192 |
29 | }, |
30 | default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, |
31 | ); |
2850baeb |
32 | |
4f4fd192 |
33 | has 'type' => ( |
34 | is => 'rw', |
35 | isa => Str, |
36 | required => 1 |
37 | ); |
65061e1b |
38 | |
51700db2 |
39 | around add_column(Column $column) { $self->$orig($column->name, $column) } |
40 | |
6b4be44b |
41 | method get_fields { $self->get_columns } |
42 | method fields { $self->column_ids } |
4f4fd192 |
43 | } |