Commit | Line | Data |
4f4fd192 |
1 | use MooseX::Declare; |
2 | class SQL::Translator::Object::Index { |
b750d2f1 |
3 | use MooseX::Types::Moose qw(ArrayRef HashRef Str); |
4f4fd192 |
4 | use MooseX::AttributeHelpers; |
f49a2a49 |
5 | use SQL::Translator::Types qw(Column Table); |
4f4fd192 |
6 | extends 'SQL::Translator::Object'; |
f49a2a49 |
7 | |
8 | has 'table' => ( |
9 | is => 'rw', |
10 | isa => Table, |
11 | required => 1, |
12 | weak_ref => 1, |
13 | ); |
4f4fd192 |
14 | |
15 | has 'name' => ( |
16 | is => 'rw', |
17 | isa => Str, |
18 | required => 1 |
19 | ); |
20 | |
21 | has 'columns' => ( |
22 | metaclass => 'Collection::Hash', |
23 | is => 'rw', |
24 | isa => HashRef[Column], |
25 | provides => { |
26 | exists => 'exists_column', |
27 | keys => 'column_ids', |
65061e1b |
28 | values => 'get_columns', |
4f4fd192 |
29 | get => 'get_column', |
51700db2 |
30 | set => 'add_column', |
4f4fd192 |
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 | ); |
65061e1b |
40 | |
b750d2f1 |
41 | has 'options' => ( |
42 | is => 'rw', |
43 | isa => ArrayRef, |
44 | auto_deref => 1 |
45 | ); |
46 | |
47 | has 'extra' => ( |
48 | is => 'rw', |
49 | isa => HashRef, |
50 | auto_deref => 1, |
51 | ); |
52 | |
51700db2 |
53 | around add_column(Column $column) { $self->$orig($column->name, $column) } |
54 | |
65061e1b |
55 | method get_fields { return $self->get_columns } |
56 | method fields { return $self->column_ids } |
4f4fd192 |
57 | } |