move to MooseX::Declare extends style
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Constraint.pm
index 3ce6a35..b1db92c 100644 (file)
@@ -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 { }
 }