X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FObject%2FConstraint.pm;h=b1db92cec598c47130bc3bde6c755f674e135bbf;hb=ebf2721d0450ee3a6c73b89e5d7c00d8af3d1105;hp=3ce6a35be1581b8e3799a78bc2324e7e3cf2eeed;hpb=b750d2f185523d7425967b675f9dd51ea659ef83;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 3ce6a35..b1db92c 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -1,9 +1,15 @@ use MooseX::Declare; -class SQL::Translator::Object::Constraint { - use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str); +class SQL::Translator::Object::Constraint extends SQL::Translator::Object { + use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str Undef); use MooseX::AttributeHelpers; - use SQL::Translator::Types qw(Column); - extends 'SQL::Translator::Object'; + use SQL::Translator::Types qw(Column Table); + + has 'table' => ( + is => 'rw', + isa => Table, + required => 1, + weak_ref => 1, + ); has 'name' => ( is => 'rw', @@ -20,14 +26,7 @@ class SQL::Translator::Object::Constraint { keys => 'column_ids', values => 'get_columns', get => 'get_column', - }, - curries => { - set => { - add_column => sub { - my ($self, $body, $column) = @_; - $self->$body($column->name, $column); - } - } + set => 'add_column', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -49,21 +48,24 @@ class SQL::Translator::Object::Constraint { isa => Str, ); - has 'options' => ( + has 'reference_table' => ( + isa => Maybe[Str], is => 'rw', - isa => ArrayRef, - auto_deref => 1 ); - has 'extra' => ( - is => 'rw', - isa => HashRef, - auto_deref => 1, + has 'reference_columns' => ( + isa => ArrayRef | Undef, + is => 'rw', + auto_deref => 1 ); - method get_fields { return $self->get_columns } - method fields { return $self->column_ids } - method field_names { return $self->column_ids } + around add_column(Column $column) { $self->$orig($column->name, $column) } + + method get_fields { $self->get_columns } + method fields { $self->column_ids } + method field_names { $self->column_ids } + + method reference_fields { $self->reference_columns } method match_type { } }