From: Justin Hunter Date: Tue, 22 Sep 2009 01:04:14 +0000 (-0700) Subject: add overload (stringification) to Column, setup some defaults and make some attrs... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=072eb21885367b4e7f85e732719b933792a9ec53;p=dbsrgits%2FSQL-Translator-2.0-ish.git add overload (stringification) to Column, setup some defaults and make some attrs not required --- diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index bfd14a2..d80d49f 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -1,32 +1,41 @@ use MooseX::Declare; -class SQL::Translator::Object::Column extends SQL::Translator::Object { +class SQL::Translator::Object::Column extends SQL::Translator::Object is dirty { use MooseX::Types::Moose qw(Bool Int Maybe ScalarRef Str); use MooseX::MultiMethods; use SQL::Translator::Types qw(Bit ColumnSize Constraint Table Trigger); + clean; + + use overload + '""' => sub { shift->name }, + 'bool' => sub { $_[0]->name || $_[0] }, + fallback => 1, + ; has 'table' => ( is => 'rw', isa => Table, - required => 1, weak_ref => 1, ); has 'name' => ( is => 'rw', isa => Str, - required => 1 + required => 1, + trigger => sub { die "Cannot use '' as a column name" if $_[1] eq '' } ); has 'data_type' => ( is => 'rw', isa => Str, - required => 1 + required => 1, + default => '', ); has 'sql_data_type' => ( is => 'rw', isa => Int, - required => 1 + required => 1, + default => 0 ); has 'size' => (