X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FObject%2FConstraint.pm;h=992d41441dd7f3706009e83067b35bd06f861b82;hb=fbf61b974d223040b2415f861e09426093440995;hp=6ac6e887d36bbb7f3c641b73c2d58c39335e7ae9;hpb=eeb819a168d2689b686624e78ff260d36bca16fe;p=dbsrgits%2FSQL-Translator-2.0-ish.git diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index 6ac6e88..992d414 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -1,9 +1,43 @@ package SQL::Translator::Object::Constraint; +use namespace::autoclean; use Moose; -use SQL::Translator::Types; +use MooseX::Types::Moose qw(HashRef Str); +use MooseX::AttributeHelpers; +use SQL::Translator::Types qw(Column); +extends 'SQL::Translator::Object'; -has 'name' => (is => 'ro', isa => 'Str', required => 1); -has 'columns' => (is => 'ro', isa => 'ArrayRef[Column]', required => 1); -has 'type' => (is => 'ro', isa => 'Str', required => 1); +has 'name' => ( + is => 'rw', + isa => Str, + required => 1 +); + +has 'columns' => ( + metaclass => 'Collection::Hash', + is => 'rw', + isa => HashRef[Column], + provides => { + exists => 'exists_column', + keys => 'column_ids', + get => 'get_column', + }, + curries => { + set => { + add_column => sub { + my ($self, $body, $column) = @_; + $self->$body($column->name, $column); + } + } + }, + default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, +); + +has 'type' => ( + is => 'rw', + isa => Str, + required => 1 +); + +__PACKAGE__->meta->make_immutable; 1;