f5729a0b476a9389acee862215ef5ae9ba294005
[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(HashRef Str);
4     use MooseX::MultiMethods;
5     use SQL::Translator::Types qw(Column Table ColumnHash IxHash);
6     use Tie::IxHash;
7
8     has 'table' => (
9         is => 'rw',
10         isa => Table,
11         weak_ref => 1,
12     );
13     
14     has 'name' => (
15         is => 'rw',
16         isa => Str,
17         required => 1
18     );
19
20     has 'columns' => (
21         is => 'rw',
22         isa => IxHash, #ColumnHash,
23         handles => {
24             exists_column => 'EXISTS',
25             column_ids    => 'Keys',
26             get_columns   => 'Values',
27             get_column    => 'FETCH',
28             add_column    => 'STORE',
29             remove_column => 'DELETE',
30             clear_columns => 'CLEAR',
31         },
32         coerce => 1,
33         default => sub { Tie::IxHash->new() }
34     );
35
36     has 'type' => (
37         is => 'rw',
38         isa => Str,
39         required => 1,
40         default => 'NORMAL',
41     );
42
43     around add_column(Column $column) { $self->$orig($column->name, $column) }
44
45     method is_valid { $self->table && scalar $self->get_columns ? 1 : undef }
46 }