From: Justin Hunter Date: Thu, 2 Jul 2009 07:33:07 +0000 (-0700) Subject: add curries where applicable X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7aa485df58674f494ff946fc297e7d4de14e006f;p=dbsrgits%2FSQL-Translator-2.0-ish.git add curries where applicable added: no Moose; __PACKAGE__->meta->make_immutable; --- diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index 7eb1b6c..dd659a3 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -42,11 +42,13 @@ has 'default_value' => ( required => 0 ); +=cut has 'index' => ( is => 'rw', isa => Maybe[Int], required => 1 ); +=cut has 'remarks' => ( is => 'rw', @@ -60,4 +62,7 @@ has 'trigger' => ( required => 0 ); +no Moose; +__PACKAGE__->meta->make_immutable; + 1; diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index 23d40dc..e9fb5df 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -30,4 +30,7 @@ has 'type' => ( required => 1 ); +no Moose; +__PACKAGE__->meta->make_immutable; + 1; diff --git a/lib/SQL/Translator/Object/Index.pm b/lib/SQL/Translator/Object/Index.pm index 931ca0c..57358cf 100644 --- a/lib/SQL/Translator/Object/Index.pm +++ b/lib/SQL/Translator/Object/Index.pm @@ -19,9 +19,11 @@ has 'columns' => ( exists => 'exists_column', keys => 'column_ids', get => 'get_column', - set => 'set_column', +# set => 'set_column', }, - required => 1 + curries => { set => { add_column => sub { my ($self, $body, $column) = @_; $self->$body($column->name, $column); } } }, + default => sub { {} }, + required => 0 ); has 'type' => ( @@ -30,4 +32,7 @@ has 'type' => ( required => 1 ); +no Moose; +__PACKAGE__->meta->make_immutable; + 1; diff --git a/lib/SQL/Translator/Object/Procedure.pm b/lib/SQL/Translator/Object/Procedure.pm index ebc4faa..42fec3e 100644 --- a/lib/SQL/Translator/Object/Procedure.pm +++ b/lib/SQL/Translator/Object/Procedure.pm @@ -50,4 +50,7 @@ has 'schema' => ( default => sub { SQL::Translator::Object::Schema->new } ); +no Moose; +__PACKAGE__->meta->make_immutable; + 1; diff --git a/lib/SQL/Translator/Object/Schema.pm b/lib/SQL/Translator/Object/Schema.pm index 42b9901..1d688fe 100644 --- a/lib/SQL/Translator/Object/Schema.pm +++ b/lib/SQL/Translator/Object/Schema.pm @@ -1,15 +1,15 @@ package SQL::Translator::Object::Schema; use Moose; -use MooseX::Types::Moose qw(HashRef Str); +use MooseX::Types::Moose qw(HashRef Maybe Str); use MooseX::AttributeHelpers; use SQL::Translator::Types qw(Procedure Table View); extends 'SQL::Translator::Object'; has 'name' => ( is => 'rw', - isa => Str, + isa => Maybe[Str], required => 1, - default => '__DEFAULT__' + default => '' ); has 'tables' => ( @@ -20,8 +20,10 @@ has 'tables' => ( exists => 'exists_table', keys => 'table_ids', get => 'get_table', - set => 'set_table', +# set => 'add_table', }, + curries => { set => { add_table => sub { my ($self, $body, $table) = @_; $self->$body($table->name, $table); } } }, + default => sub { {} }, required => 0 ); @@ -33,8 +35,10 @@ has 'views' => ( exists => 'exists_view', keys => 'view_ids', get => 'get_view', - set => 'set_view', +# set => 'set_view', }, + curries => { set => { add_view => sub { my ($self, $body, $view) = @_; $self->$body($view->name, $view); } } }, + default => sub { {} }, required => 0 ); @@ -48,7 +52,11 @@ has 'procedures' => ( get => 'get_procedure', set => 'set_procedure', }, + default => sub { {} }, required => 0 ); +no Moose; +__PACKAGE__->meta()->make_immutable; + 1; diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index a91ca9c..6f64961 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -20,8 +20,10 @@ has 'columns' => ( exists => 'exists_column', keys => 'column_ids', get => 'get_column', - set => 'set_column', +# set => 'set_column', }, + curries => { set => { add_column => sub { my ($self, $body, $column) = @_; $self->$body($column->name, $column); } } }, + default => sub { {} }, required => 0 ); @@ -33,8 +35,10 @@ has 'indexes' => ( exists => 'exists_index', keys => 'index_ids', get => 'get_index', - set => 'set_index', +# set => 'set_index', }, + curries => { set => { add_index => sub { my ($self, $body, $index) = @_; $self->$body($index->name, $index); } } }, + default => sub { {} }, required => 0 ); @@ -48,14 +52,19 @@ has 'constraints' => ( get => 'get_constraint', set => 'set_constraint', }, + default => sub { {} }, required => 0 ); +=cut has 'schema' => ( is => 'rw', isa => Schema, required => 0, default => sub { SQL::Translator::Object::Schema->new } ); +=cut +no Moose; +__PACKAGE__->meta()->make_immutable; 1; diff --git a/lib/SQL/Translator/Object/Trigger.pm b/lib/SQL/Translator/Object/Trigger.pm index d3139dc..2f98b41 100644 --- a/lib/SQL/Translator/Object/Trigger.pm +++ b/lib/SQL/Translator/Object/Trigger.pm @@ -6,4 +6,7 @@ extends 'SQL::Translator::Object'; has 'name' => (is => 'ro', isa => Str, required => 1); +no Moose; +__PACKAGE__->meta->make_immutable; + 1; diff --git a/lib/SQL/Translator/Object/View.pm b/lib/SQL/Translator/Object/View.pm index c32cf48..d179c63 100644 --- a/lib/SQL/Translator/Object/View.pm +++ b/lib/SQL/Translator/Object/View.pm @@ -1,8 +1,28 @@ package SQL::Translator::Object::View; use Moose; -use MooseX::Types::Moose qw(); -use SQL::Translator::Types qw(); -extends 'SQL::Translator::Object::Table'; +use MooseX::Types::Moose qw(HashRef Str); +use MooseX::AttributeHelpers; +use SQL::Translator::Types qw(Column); +extends 'SQL::Translator::Object'; + +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', + set => 'set_column', + }, + required => 0 +); has 'sql' => ( is => 'rw', @@ -10,4 +30,7 @@ has 'sql' => ( required => 1 ); +no Moose; +__PACKAGE__->meta->make_immutable; + 1;