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';
23 requires 'quote_string';
29 has numeric_types => (
33 has sizeless_types => (
37 has unquoted_defaults => (
45 has add_drop_table => (
49 # would also be handy to have a required size set if there is such a thing
51 sub field_name { $_[0]->quote($_[1]->name) }
54 ( $_[1]->comments ? ('-- ' . $_[1]->comments . "\n ") : () )
58 my ($self, $table) = @_;
59 if ($self->add_comments) {
63 "-- Table: " . $self->quote($table->name) . "",
65 map "-- $_", $table->comments
72 sub field_nullable { ($_[1]->is_nullable ? $_[0]->nullable : 'NOT NULL' ) }
75 my ($self, $field, $exceptions) = @_;
77 my $default = $field->default_value;
78 return () if !defined $default;
80 $default = \"$default"
81 if $exceptions and !ref $default and $exceptions->{$default};
84 } elsif (!($self->numeric_types->{lc($field->data_type)} && Scalar::Util::looks_like_number ($default))) {
85 $default = $self->quote_string($default);
87 return ( "DEFAULT $default" )
91 my ($self, $field) = @_;
93 my $field_type = $field->data_type;
94 ($self->type_map->{$field_type} || $field_type).$self->field_type_size($field)
98 my ($self, $field) = @_;
100 ($field->size && !$self->sizeless_types->{$field->data_type}
101 ? '(' . $field->size . ')'
107 my ($self, $table) = @_;
108 ( map $self->field($_), $table->get_fields )
112 my ($self, $table) = @_;
113 (map $self->index($_), $table->get_indices)
116 sub nullable { 'NULL' }
118 sub header_comments { header_comment() . "\n" if $_[0]->add_comments }
124 See the included AUTHORS file:
125 L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>
129 Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above.
133 This code is free software and may be distributed under the same terms as Perl