From: Arthur Axel 'fREW' Schmidt Date: Wed, 25 Jan 2012 02:13:46 +0000 (-0600) Subject: migrate duplicated code into role X-Git-Tag: v0.11011~27^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4b10273fc97661a210da3719a5da0469bb88902f;p=dbsrgits%2FSQL-Translator.git migrate duplicated code into role --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLServer.pm b/lib/SQL/Translator/Generator/DDL/SQLServer.pm index 5d0f446..4c64eae 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLServer.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLServer.pm @@ -29,10 +29,6 @@ sub _build_type_map { } } -has sizeless_types => ( - is => 'lazy', -); - sub _build_sizeless_types { +{ map { $_ => 1 } qw( tinyint smallint int integer bigint text bit image datetime ) } @@ -47,15 +43,6 @@ sub field { $self->field_default($field), } -sub field_type_size { - my ($self, $field) = @_; - - ($field->size && !$self->sizeless_types->{$field->data_type} - ? '(' . $field->size . ')' - : '' - ) -} - sub field_autoinc { ( $_[1]->is_auto_increment ? 'IDENTITY' : () ) } sub primary_key_constraint { diff --git a/lib/SQL/Translator/Generator/DDL/SQLite.pm b/lib/SQL/Translator/Generator/DDL/SQLite.pm index 8c58869..9dda649 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLite.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLite.pm @@ -16,10 +16,6 @@ sub _build_type_map { } } -has sizeless_types => ( - is => 'lazy', -); - sub _build_sizeless_types { +{ text => 1 } } sub _build_numeric_types { +{ int => 1, tinyint => 1 } } @@ -60,14 +56,5 @@ sub field { $self->field_default($field), } -sub field_type_size { - my ($self, $field) = @_; - - ($field->size && !$self->sizeless_types->{$field->data_type} - ? '(' . $field->size . ')' - : '' - ) -} - 1; diff --git a/lib/SQL/Translator/Generator/Role/DDL.pm b/lib/SQL/Translator/Generator/Role/DDL.pm index 766ff8f..e5b91d0 100644 --- a/lib/SQL/Translator/Generator/Role/DDL.pm +++ b/lib/SQL/Translator/Generator/Role/DDL.pm @@ -6,7 +6,7 @@ use SQL::Translator::Utils qw(header_comment); requires '_build_type_map'; requires '_build_numeric_types'; requires '_build_unquoted_defaults'; -requires 'field_type_size'; +requires '_build_sizeless_types'; requires 'quote'; has type_map => ( @@ -17,6 +17,10 @@ has numeric_types => ( is => 'lazy', ); +has sizeless_types => ( + is => 'lazy', +); + has unquoted_defaults => ( is => 'lazy', ); @@ -69,6 +73,15 @@ sub field_type { ($self->type_map->{$field_type} || $field_type).$self->field_type_size($field) } +sub field_type_size { + my ($self, $field) = @_; + + ($field->size && !$self->sizeless_types->{$field->data_type} + ? '(' . $field->size . ')' + : '' + ) +} + sub fields { my ($self, $table) = @_; ( map $self->field($_), $table->get_fields )