From: Justin Hunter Date: Thu, 20 Aug 2009 06:39:15 +0000 (-0700) Subject: move from curries to provides => { set => 'add_...' } and around add_... { } X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=51700db221bbf317b260181e74472cfe89d4b1aa;p=dbsrgits%2FSQL-Translator-2.0-ish.git move from curries to provides => { set => 'add_...' } and around add_... { } --- diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index 3ce6a35..ed252a8 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -20,14 +20,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 }, ); @@ -61,6 +54,8 @@ class SQL::Translator::Object::Constraint { auto_deref => 1, ); + around add_column(Column $column) { $self->$orig($column->name, $column) } + method get_fields { return $self->get_columns } method fields { return $self->column_ids } method field_names { return $self->column_ids } diff --git a/lib/SQL/Translator/Object/Index.pm b/lib/SQL/Translator/Object/Index.pm index d7ac8b5..be3142d 100644 --- a/lib/SQL/Translator/Object/Index.pm +++ b/lib/SQL/Translator/Object/Index.pm @@ -20,14 +20,7 @@ class SQL::Translator::Object::Index { 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 }, ); @@ -50,6 +43,8 @@ class SQL::Translator::Object::Index { auto_deref => 1, ); + around add_column(Column $column) { $self->$orig($column->name, $column) } + method get_fields { return $self->get_columns } method fields { return $self->column_ids } } diff --git a/lib/SQL/Translator/Object/Schema.pm b/lib/SQL/Translator/Object/Schema.pm index 9d2389a..97458d7 100644 --- a/lib/SQL/Translator/Object/Schema.pm +++ b/lib/SQL/Translator/Object/Schema.pm @@ -21,14 +21,7 @@ class SQL::Translator::Object::Schema { keys => 'table_ids', values => 'get_tables', get => 'get_table', - }, - curries => { - set => { - add_table => sub { - my ($self, $body, $table) = @_; - $self->$body($table->name, $table); - } - } + set => 'add_table', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -42,14 +35,7 @@ class SQL::Translator::Object::Schema { keys => 'view_ids', values => 'get_views', get => 'get_view', - }, - curries => { - set => { - add_view => sub { - my ($self, $body, $view) = @_; - $self->$body($view->name, $view); - } - } + set => 'add_view', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -63,14 +49,7 @@ class SQL::Translator::Object::Schema { keys => 'procedure_ids', values => 'get_procedures', get => 'get_procedure', - }, - curries => { - set => { - add_procedure => sub { - my ($self, $body, $procedure) = @_; - $self->$body($procedure->name, $procedure); - } - } + set => 'add_procedure', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -84,18 +63,16 @@ class SQL::Translator::Object::Schema { keys => 'trigger_ids', values => 'get_triggers', get => 'get_trigger', - }, - curries => { - set => { - add_trigger => sub { - my ($self, $body, $trigger) = @_; - $self->$body($trigger->name, $trigger); - } - } + set => 'add_trigger', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); + around add_table(Table $table) { $self->$orig($table->name, $table) } + around add_view(View $view) { $self->$orig($view->name, $view) } + around add_procedure(Procedure $procedure) { $self->$orig($procedure->name, $procedure) } + around add_trigger(Trigger $trigger) { $self->$orig($trigger->name, $trigger) } + method is_valid { 1 } method order { } diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index 2655c19..5853879 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -21,14 +21,7 @@ class SQL::Translator::Object::Table { 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 }, ); @@ -42,14 +35,7 @@ class SQL::Translator::Object::Table { keys => 'index_ids', values => 'get_indices', get => 'get_index', - }, - curries => { - set => { - add_index => sub { - my ($self, $body, $index) = @_; - $self->$body($index->name, $index); - } - } + set => 'add_index', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -63,14 +49,7 @@ class SQL::Translator::Object::Table { keys => 'constraint_ids', values => 'get_constraints', get => 'get_constraint', - }, - curries => { - set => { - add_constraint => sub { - my ($self, $body, $constraint) = @_; - $self->$body($constraint->name, $constraint); - } - } + set => 'add_constraint', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -84,14 +63,7 @@ class SQL::Translator::Object::Table { keys => 'sequence_ids', values => 'get_sequences', get => 'get_sequence', - }, - curries => { - set => { - add_sequence => sub { - my ($self, $body, $sequence) = @_; - $self->$body($sequence->name, $sequence); - } - } + set => 'add_sequence', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -113,6 +85,11 @@ class SQL::Translator::Object::Table { auto_deref => 1 ); + around add_column(Column $column) { $self->$orig($column->name, $column) } + around add_index(Index $index) { $self->$orig($index->name, $index) } + around add_constraint(Constraint $constraint) { $self->$orig($constraint->name, $constraint) } + around add_sequence(Sequence $sequence) { $self->$orig($sequence->name, $sequence) } + method get_fields { return $self->get_columns } method fields { return $self->column_ids } method primary_key(Str $column) { diff --git a/lib/SQL/Translator/Object/Trigger.pm b/lib/SQL/Translator/Object/Trigger.pm index 2f8f442..8501d1e 100644 --- a/lib/SQL/Translator/Object/Trigger.pm +++ b/lib/SQL/Translator/Object/Trigger.pm @@ -20,14 +20,7 @@ class SQL::Translator::Object::Trigger { 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 }, ); @@ -55,6 +48,8 @@ class SQL::Translator::Object::Trigger { required => 1 ); + around add_column(Column $column) { $self->$orig($column->name, $column) } + method get_fields { return $self->get_columns } method fields { return $self->column_ids } } diff --git a/lib/SQL/Translator/Object/View.pm b/lib/SQL/Translator/Object/View.pm index 175aed2..a1ad806 100644 --- a/lib/SQL/Translator/Object/View.pm +++ b/lib/SQL/Translator/Object/View.pm @@ -18,15 +18,9 @@ class SQL::Translator::Object::View { provides => { exists => 'exists_column', 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 }, ); @@ -37,6 +31,8 @@ class SQL::Translator::Object::View { required => 1 ); + around add_column(Column $column) { $self->$orig($column->name, $column) } + method get_fields { return $self->get_columns } method fields { return $self->column_ids } }