change Undef to an empty ArrayRef and remove auto_deref
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Constraint.pm
index 1ffa480..91e8cee 100644 (file)
@@ -1,7 +1,6 @@
 use MooseX::Declare;
 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 Table);
 
     has 'table' => (
@@ -18,15 +17,19 @@ class SQL::Translator::Object::Constraint extends SQL::Translator::Object {
     );
     
     has 'columns' => (
-        metaclass => 'Collection::Hash',
+        traits => ['Hash'],
         is => 'rw',
         isa => HashRef[Column],
-        provides => {
-            exists => 'exists_column',
-            keys   => 'column_ids',
-            values => 'get_columns',
-            get    => 'get_column',
-            set    => 'add_column',
+        handles => {
+            exists_column => 'exists',
+            column_ids    => 'keys',
+            get_columns   => 'values',
+            get_column    => 'get',
+            add_column    => 'set',
+
+            ## compat
+            get_fields    => 'values',
+            fields        => 'keys',
         },
         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
     );
@@ -40,7 +43,7 @@ class SQL::Translator::Object::Constraint extends SQL::Translator::Object {
     has 'deferrable' => (
         is => 'rw',
         isa => Bool,
-        default => 0
+        default => 1
     );
 
     has 'expression' => (
@@ -54,9 +57,12 @@ class SQL::Translator::Object::Constraint extends SQL::Translator::Object {
     );
 
     has 'reference_columns' => (
-        isa => ArrayRef | Undef,
-        is => 'rw',
-        auto_deref => 1
+        isa => ArrayRef,
+        traits => ['Array'],
+        handles => {
+            reference_columns => 'elements',
+        },
+        default => sub { [] },
     );
 
     has 'match_type' => (
@@ -66,9 +72,5 @@ class SQL::Translator::Object::Constraint extends SQL::Translator::Object {
 
     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 }
 }