From: Justin Hunter Date: Wed, 30 Sep 2009 00:11:44 +0000 (-0700) Subject: break out size into length & precision X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=958a3ef79ae72dd5e29895552d2e39574f920f28;p=dbsrgits%2FSQL-Translator-2.0-ish.git break out size into length & precision --- diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index d80d49f..8091aac 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -38,12 +38,20 @@ class SQL::Translator::Object::Column extends SQL::Translator::Object is dirty { default => 0 ); - has 'size' => ( + has 'length' => ( is => 'rw', - isa => ColumnSize, - coerce => 1, - auto_deref => 1, - default => sub { [ 0 ] }, + isa => Int, + default => 0, + lazy => 1, + predicate => 'has_length', + ); + + has 'precision' => ( + is => 'rw', + isa => Int, + default => 0, + lazy => 1, + predicate => 'has_precision', ); has 'is_nullable' => ( @@ -102,4 +110,18 @@ class SQL::Translator::Object::Column extends SQL::Translator::Object is dirty { method is_unique { } before name($name?) { die "Can't use column name $name" if $name && $self->table->exists_column($name) && $name ne $self->name; } + + multi method size(Str $size) { my ($length, $precision) = split /,/, $size; $self->length($length); $self->precision($precision) if $precision; $self->size } + multi method size(Int $length, Int $precision) { $self->length($length); $self->precision($precision); $self->size } + multi method size(ArrayRef $size) { $self->length($size->[0]); $self->precision($size->[1]) if @$size == 2; $self->size } + + multi method size(Any $) { + return $self->has_precision + ? wantarray + ? ($self->length, $self->precision) + : join ',', ($self->length, $self->precision) + : $self->length; + } + + method BUILD(HashRef $args) { $self->size($args->{size}) if $args->{size} } }