From: Justin Hunter Date: Mon, 24 Aug 2009 22:29:59 +0000 (-0700) Subject: move extra down to Object.pm X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6381c78d23878fe50d7912193c4b609c77a169aa;p=dbsrgits%2FSQL-Translator-2.0-ish.git move extra down to Object.pm --- diff --git a/lib/SQL/Translator/Object.pm b/lib/SQL/Translator/Object.pm index af3ad53..7302766 100644 --- a/lib/SQL/Translator/Object.pm +++ b/lib/SQL/Translator/Object.pm @@ -2,7 +2,7 @@ use MooseX::Declare; class SQL::Translator::Object { use Tie::IxHash; use MooseX::MultiMethods; - use MooseX::Types::Moose qw(Any ArrayRef Str); + use MooseX::Types::Moose qw(Any ArrayRef HashRef Str); has '_comments' => ( metaclass => 'Collection::Array', @@ -28,11 +28,30 @@ class SQL::Translator::Object { auto_deref => 1, ); + has '_extra' => ( + metaclass => 'Collection::Hash', + is => 'rw', + isa => HashRef, + provides => { + exists => 'exists_extra', + keys => 'extra_ids', + values => 'get_extras', + get => 'get_extra', + set => 'add_extra', + }, + default => sub { {} }, + auto_deref => 1, + ); + multi method comments(Str $comment) { $self->add_comment($comment) } multi method comments(ArrayRef $comment) { $self->add_comment($comment) } - multi method comments(Any $) { return wantarray ? @{$self->_comments} : join "\n", $self->_comments } + multi method comments(Any $) { wantarray ? @{$self->_comments} : join "\n", $self->_comments } multi method options(Str $option) { $self->add_option($option) } multi method options(ArrayRef $option) { $self->add_option($option) if scalar @$option } multi method options(Any $) { wantarray ? @{$self->_options} : $self->_options } + + multi method extra(Str $extra) { $self->get_extra($extra) } + multi method extra(HashRef $extra) { $self->_extra($extra) } + multi method extra(Any $) { wantarray ? %{$self->_extra} : $self->_extra } } diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index ea80e95..567c020 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -78,12 +78,6 @@ class SQL::Translator::Object::Column { isa => Trigger, ); - has 'extra' => ( - is => 'rw', - isa => HashRef, - auto_deref => 1, - ); - around size(@args) { $self->$orig(@args) if @args; my @sizes = $self->$orig; diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index 1a933ea..66bffc9 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -60,12 +60,6 @@ class SQL::Translator::Object::Constraint { auto_deref => 1 ); - has 'extra' => ( - is => 'rw', - isa => HashRef, - auto_deref => 1, - ); - around add_column(Column $column) { $self->$orig($column->name, $column) } method get_fields { $self->get_columns } diff --git a/lib/SQL/Translator/Object/Index.pm b/lib/SQL/Translator/Object/Index.pm index ced7635..e6b787d 100644 --- a/lib/SQL/Translator/Object/Index.pm +++ b/lib/SQL/Translator/Object/Index.pm @@ -38,12 +38,6 @@ class SQL::Translator::Object::Index { required => 1 ); - has 'extra' => ( - is => 'rw', - isa => HashRef, - auto_deref => 1, - ); - around add_column(Column $column) { $self->$orig($column->name, $column) } method get_fields { $self->get_columns } diff --git a/lib/SQL/Translator/Object/Schema.pm b/lib/SQL/Translator/Object/Schema.pm index a8bd8cc..b3c69ed 100644 --- a/lib/SQL/Translator/Object/Schema.pm +++ b/lib/SQL/Translator/Object/Schema.pm @@ -68,12 +68,6 @@ class SQL::Translator::Object::Schema { default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); - has 'extra' => ( - is => 'rw', - isa => HashRef, - auto_deref => 1, - ); - 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) } diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index 4e75ad5..fff8c07 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -82,12 +82,6 @@ class SQL::Translator::Object::Table { default => 0 ); - has 'extra' => ( - is => 'rw', - isa => HashRef, - 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) } diff --git a/lib/SQL/Translator/Object/View.pm b/lib/SQL/Translator/Object/View.pm index 342052b..6c63c9d 100644 --- a/lib/SQL/Translator/Object/View.pm +++ b/lib/SQL/Translator/Object/View.pm @@ -31,12 +31,6 @@ class SQL::Translator::Object::View { required => 1 ); - has 'extra' => ( - is => 'rw', - isa => HashRef, - auto_deref => 1, - ); - around add_column(Column $column) { $self->$orig($column->name, $column) } method get_fields { $self->get_columns }