1 package SQL::Translator::Generator::Role::DDL;
5 SQL::Translator::Generator::Role::DDL - Role implementing common parts of
10 I<documentation volunteers needed>
15 use SQL::Translator::Utils qw(header_comment);
18 requires '_build_type_map';
19 requires '_build_numeric_types';
20 requires '_build_unquoted_defaults';
21 requires '_build_sizeless_types';
28 has numeric_types => (
32 has sizeless_types => (
36 has unquoted_defaults => (
44 has add_drop_table => (
48 # would also be handy to have a required size set if there is such a thing
50 sub field_name { $_[0]->quote($_[1]->name) }
53 ( $_[1]->comments ? ('-- ' . $_[1]->comments . "\n ") : () )
57 my ($self, $table) = @_;
58 if ($self->add_comments) {
62 "-- Table: " . $self->quote($table->name) . "",
64 map "-- $_", $table->comments
71 sub field_nullable { ($_[1]->is_nullable ? $_[0]->nullable : 'NOT NULL' ) }
74 my ($self, $field, $exceptions) = @_;
76 my $default = $field->default_value;
77 return () if !defined $default;
79 $default = \"$default"
80 if $exceptions and !ref $default and $exceptions->{$default};
83 } elsif (!($self->numeric_types->{lc($field->data_type)} && Scalar::Util::looks_like_number ($default))) {
84 $default = "'$default'";
86 return ( "DEFAULT $default" )
90 my ($self, $field) = @_;
92 my $field_type = $field->data_type;
93 ($self->type_map->{$field_type} || $field_type).$self->field_type_size($field)
97 my ($self, $field) = @_;
99 ($field->size && !$self->sizeless_types->{$field->data_type}
100 ? '(' . $field->size . ')'
106 my ($self, $table) = @_;
107 ( map $self->field($_), $table->get_fields )
111 my ($self, $table) = @_;
112 (map $self->index($_), $table->get_indices)
115 sub nullable { 'NULL' }
117 sub header_comments { header_comment() . "\n" if $_[0]->add_comments }
123 See the included AUTHORS file:
124 L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>
128 Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above.
132 This code is free software and may be distributed under the same terms as Perl