add PrimaryKey and ForeignKey classes
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Constraint.pm
index e9fb5df..992d414 100644 (file)
@@ -1,4 +1,5 @@
 package SQL::Translator::Object::Constraint;
+use namespace::autoclean;
 use Moose;
 use MooseX::Types::Moose qw(HashRef Str);
 use MooseX::AttributeHelpers;
@@ -6,31 +7,37 @@ use SQL::Translator::Types qw(Column);
 extends 'SQL::Translator::Object';
 
 has 'name' => (
-  is => 'rw',
-  isa => Str,
-  required => 1
+    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',
-    set    => 'set_column',
-  },
-  required => 1
+    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
+    is => 'rw',
+    isa => Str,
+    required => 1
 );
 
-no Moose;
 __PACKAGE__->meta->make_immutable;
 
 1;