add is_valid method and a default for type
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Index.pm
CommitLineData
4f4fd192 1use MooseX::Declare;
ebf2721d 2class 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',
db2e467f 29
30 ## compat
31 get_fields => 'values',
32 fields => 'keys',
4f4fd192 33 },
34 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
35 );
2850baeb 36
4f4fd192 37 has 'type' => (
38 is => 'rw',
39 isa => Str,
7e6d96f8 40 required => 1,
41 default => 'NORMAL',
4f4fd192 42 );
65061e1b 43
51700db2 44 around add_column(Column $column) { $self->$orig($column->name, $column) }
7e6d96f8 45
46 method is_valid { $self->table && scalar $self->get_columns ? 1 : undef }
4f4fd192 47}