1 package SQL::Translator::Producer::POD;
3 # -------------------------------------------------------------------
4 # Copyright (C) 2002-2009 SQLFairy Authors
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # -------------------------------------------------------------------
23 SQL::Translator::Producer::POD - POD producer for SQL::Translator
29 my $t = SQL::Translator->new( parser => '...', producer => 'POD', '...' );
34 Creates a POD description of each table, field, index, and constraint.
35 A good starting point for text documentation of a schema. You can
36 easily convert the output to HTML or text using "perldoc" or other
37 interesting formats using Pod::POM or Template::Toolkit's POD plugin.
42 use vars qw[ $VERSION ];
45 use SQL::Translator::Schema::Constants;
46 use SQL::Translator::Utils qw(header_comment);
48 # -------------------------------------------------------------------
51 my $schema = $t->schema;
52 my $schema_name = $schema->name || 'Schema';
53 my $args = $t->producer_args;
54 my $title = $args->{'title'} || $schema_name;
56 my $pod = "=pod\n\n=head1 DESCRIPTION\n\n$title\n\n=head1 TABLES\n\n";
58 for my $table ( $schema->get_tables ) {
59 my $table_name = $table->name or next;
60 my @fields = $table->get_fields or next;
61 $pod .= "=head2 $table_name\n\n=head3 FIELDS\n\n";
66 for my $field ( @fields ) {
67 $pod .= "=head4 " . $field->name . "\n\n=over 4\n\n";
69 my $data_type = $field->data_type;
70 my $size = $field->size;
71 $data_type .= "($size)" if $size;
73 $pod .= "=item * $data_type\n\n";
74 $pod .= "=item * PRIMARY KEY\n\n" if $field->is_primary_key;
76 my $default = $field->default_value;
77 $pod .= "=item * Default '$default' \n\n" if defined $default;
79 $pod .= sprintf( "=item * Nullable '%s' \n\n",
80 $field->is_nullable ? 'Yes' : 'No' );
88 if ( my @indices = $table->get_indices ) {
89 $pod .= "=head3 INDICES\n\n";
90 for my $index ( @indices ) {
91 $pod .= "=head4 " . $index->type . "\n\n=over 4\n\n";
92 $pod .= "=item * Fields = " .
93 join(', ', $index->fields ) . "\n\n";
101 if ( my @constraints = $table->get_constraints ) {
102 $pod .= "=head3 CONSTRAINTS\n\n";
103 for my $c ( @constraints ) {
104 $pod .= "=head4 " . $c->type . "\n\n=over 4\n\n";
105 $pod .= "=item * Fields = " .
106 join(', ', $c->fields ) . "\n\n";
108 if ( $c->type eq FOREIGN_KEY ) {
109 $pod .= "=item * Reference Table = L</" .
110 $c->reference_table . ">\n\n";
111 $pod .= "=item * Reference Fields = " .
112 join(', ', map {"L</$_>"} $c->reference_fields ) .
116 if ( my $update = $c->on_update ) {
117 $pod .= "=item * On update = $update\n\n";
120 if ( my $delete = $c->on_delete ) {
121 $pod .= "=item * On delete = $delete\n\n";
129 my $header = ( map { $_ || () } split( /\n/, header_comment('', '') ) )[0];
130 $header =~ s/^Created by //;
131 $pod .= "=head1 PRODUCED BY\n\n$header\n\n=cut";
138 # -------------------------------------------------------------------
139 # Expect poison from the standing water.
141 # -------------------------------------------------------------------
147 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
151 Jonathan Yu E<lt>frequency@cpan.orgE<gt>
155 perldoc, perlpod, Pod::POM, Template::Manual::Plugins.