From: Ken Youens-Clark Date: Fri, 6 Jun 2003 22:36:09 +0000 (+0000) Subject: Added comments method and parsing on init. X-Git-Tag: v0.02~73 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=88b8377e76b5e04d61e1111a478c0f8d747b0312;p=dbsrgits%2FSQL-Translator.git Added comments method and parsing on init. --- diff --git a/lib/SQL/Translator/Schema/Table.pm b/lib/SQL/Translator/Schema/Table.pm index 196b159..a263cee 100644 --- a/lib/SQL/Translator/Schema/Table.pm +++ b/lib/SQL/Translator/Schema/Table.pm @@ -1,7 +1,7 @@ package SQL::Translator::Schema::Table; # ---------------------------------------------------------------------- -# $Id: Table.pm,v 1.6 2003-06-06 00:10:32 kycl4rk Exp $ +# $Id: Table.pm,v 1.7 2003-06-06 22:36:09 kycl4rk Exp $ # ---------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark # @@ -70,9 +70,9 @@ Object constructor. my ( $self, $config ) = @_; - for my $arg ( qw[ schema name ] ) { + for my $arg ( qw[ schema name comments ] ) { next unless defined $config->{ $arg }; - $self->$arg( $config->{ $arg } ) or return; + defined $self->$arg( $config->{ $arg } ) or return; } return $self; @@ -246,6 +246,32 @@ existing field, you will get an error and the field will not be created. } # ---------------------------------------------------------------------- +sub comments { + +=pod + +=head2 comments + +Get or set the comments on a table. May be called several times to +set and it will accumulate the comments. Called in an array context, +returns each comment individually; called in a scalar context, returns +all the comments joined on newlines. + + $table->comments('foo'); + $table->comments('bar'); + print join( ', ', $table->comments ); # prints "foo, bar" + +=cut + + my $self = shift; + push @{ $self->{'comments'} }, @_ if @_; + + return wantarray + ? @{ $self->{'comments'} || [] } + : join( "\n", @{ $self->{'comments'} || [] } ); +} + +# ---------------------------------------------------------------------- sub get_constraints { =pod @@ -473,7 +499,7 @@ These are eqivalent: $constraint = $self->add_constraint( type => PRIMARY_KEY, fields => $fields, - ); + ) or return; } }