From: Justin Hunter Date: Sat, 22 Aug 2009 21:38:24 +0000 (-0700) Subject: add 'extra' attribute (may move down to Object.pm) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5f18427082c4438b23912765537f9f9b80c6212b;p=dbsrgits%2FSQL-Translator-2.0-ish.git add 'extra' attribute (may move down to Object.pm) --- diff --git a/lib/SQL/Translator/Object/Schema.pm b/lib/SQL/Translator/Object/Schema.pm index 97458d7..a8bd8cc 100644 --- a/lib/SQL/Translator/Object/Schema.pm +++ b/lib/SQL/Translator/Object/Schema.pm @@ -68,6 +68,12 @@ 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) } @@ -81,5 +87,4 @@ class SQL::Translator::Object::Schema { method fields { } method on_table { } method action { } - method extra { } } diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index 435e71f..ba97281 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -1,7 +1,8 @@ use MooseX::Declare; class SQL::Translator::Object::Table { - use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str); + use MooseX::Types::Moose qw(Any ArrayRef Bool HashRef Maybe Str); use MooseX::AttributeHelpers; + use MooseX::MultiMethods; use SQL::Translator::Types qw(Column Constraint Index Schema Sequence); use SQL::Translator::Object::Schema; extends 'SQL::Translator::Object'; @@ -80,16 +81,22 @@ class SQL::Translator::Object::Table { auto_deref => 1 ); + 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) } 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) { - $self->get_column($column)->is_primary_key(1); - } + method get_fields { $self->get_columns } + method fields { $self->column_ids } + + multi method primary_key(Any $) { grep /^PRIMARY KEY$/, $_->type for $self->get_constraints } + multi method primary_key(Str $column) { $self->get_column($column)->is_primary_key(1) } method order { } } diff --git a/lib/SQL/Translator/Object/View.pm b/lib/SQL/Translator/Object/View.pm index a1ad806..342052b 100644 --- a/lib/SQL/Translator/Object/View.pm +++ b/lib/SQL/Translator/Object/View.pm @@ -31,8 +31,14 @@ 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 { return $self->get_columns } - method fields { return $self->column_ids } + method get_fields { $self->get_columns } + method fields { $self->column_ids } }