move to MooseX::Declare extends style
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Index.pm
1 use MooseX::Declare;
2 class SQL::Translator::Object::Index extends SQL::Translator::Object {
3     use MooseX::Types::Moose qw(ArrayRef HashRef Str);
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 => 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     around add_column(Column $column) { $self->$orig($column->name, $column) }
41
42     method get_fields { $self->get_columns }
43     method fields { $self->column_ids }
44 }