use Tie::IxHash default
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Constraint.pm
1 package SQL::Translator::Object::Constraint;
2 use namespace::autoclean;
3 use Moose;
4 use MooseX::Types::Moose qw(HashRef Str);
5 use MooseX::AttributeHelpers;
6 use SQL::Translator::Types qw(Column);
7 extends 'SQL::Translator::Object';
8
9 has 'name' => (
10     is => 'rw',
11     isa => Str,
12     required => 1
13 );
14
15 has 'columns' => (
16     metaclass => 'Collection::Hash',
17     is => 'rw',
18     isa => HashRef[Column],
19     provides => {
20         exists => 'exists_column',
21         keys   => 'column_ids',
22         get    => 'get_column',
23     },
24     curries => {
25         set => {
26             add_column => sub {
27                 my ($self, $body, $column) = @_;
28                 $self->$body($column->name, $column);
29             }
30         }
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 );
40
41 __PACKAGE__->meta->make_immutable;
42
43 1;