From: Justin Hunter Date: Sat, 22 Aug 2009 21:33:16 +0000 (-0700) Subject: move comments down to the base Object X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dc323499f4db1e3d70263f927c9bc1aabd2f496;p=dbsrgits%2FSQL-Translator-2.0-ish.git move comments down to the base Object --- diff --git a/lib/SQL/Translator/Object.pm b/lib/SQL/Translator/Object.pm index 15302b5..271e1da 100644 --- a/lib/SQL/Translator/Object.pm +++ b/lib/SQL/Translator/Object.pm @@ -1,4 +1,22 @@ use MooseX::Declare; class SQL::Translator::Object { use Tie::IxHash; + use MooseX::MultiMethods; + use MooseX::Types::Moose qw(Any ArrayRef Str); + + has '_comments' => ( + metaclass => 'Collection::Array', + is => 'rw', + isa => ArrayRef, + provides => { + push => 'add_comment', + pop => 'remove_last_comment', + }, + 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 } } diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index c7f1bb5..a487c3d 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -40,11 +40,6 @@ class SQL::Translator::Object::Column { is => 'rw', isa => Maybe[Str], ); - - has 'comments' => ( - is => 'rw', - isa => Maybe[Str], - ); has 'is_auto_increment' => ( is => 'rw', diff --git a/lib/SQL/Translator/Object/Procedure.pm b/lib/SQL/Translator/Object/Procedure.pm index b8af8ab..df1ec38 100644 --- a/lib/SQL/Translator/Object/Procedure.pm +++ b/lib/SQL/Translator/Object/Procedure.pm @@ -28,16 +28,4 @@ class SQL::Translator::Object::Procedure { isa => Str, required => 1 ); - - has 'comments' => ( - is => 'rw', - isa => Str, - ); - - has 'schema' => ( - is => 'rw', - isa => Schema, - required => 1, - default => sub { Schema->new } - ); } diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index 5853879..435e71f 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -68,11 +68,6 @@ class SQL::Translator::Object::Table { default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); - has 'comments' => ( - is => 'rw', - isa => Maybe[Str], - ); - has 'temporary' => ( is => 'rw', isa => Bool,