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);
50 my $schema = $t->schema;
51 my $schema_name = $schema->name || 'Schema';
52 my $args = $t->producer_args;
53 my $title = $args->{'title'} || $schema_name;
55 my $pod = "=pod\n\n=head1 DESCRIPTION\n\n$title\n\n=head1 TABLES\n\n";
57 for my $table ( $schema->get_tables ) {
58 my $table_name = $table->name or next;
59 my @fields = $table->get_fields or next;
60 $pod .= "=head2 $table_name\n\n=head3 FIELDS\n\n";
65 for my $field ( @fields ) {
66 $pod .= "=head4 " . $field->name . "\n\n=over 4\n\n";
68 my $data_type = $field->data_type;
69 my $size = $field->size;
70 $data_type .= "($size)" if $size;
72 $pod .= "=item * $data_type\n\n";
73 $pod .= "=item * PRIMARY KEY\n\n" if $field->is_primary_key;
75 my $default = $field->default_value;
76 $pod .= "=item * Default '$default' \n\n" if defined $default;
78 $pod .= sprintf( "=item * Nullable '%s' \n\n",
79 $field->is_nullable ? 'Yes' : 'No' );
87 if ( my @indices = $table->get_indices ) {
88 $pod .= "=head3 INDICES\n\n";
89 for my $index ( @indices ) {
90 $pod .= "=head4 " . $index->type . "\n\n=over 4\n\n";
91 $pod .= "=item * Fields = " .
92 join(', ', $index->fields ) . "\n\n";
100 if ( my @constraints = $table->get_constraints ) {
101 $pod .= "=head3 CONSTRAINTS\n\n";
102 for my $c ( @constraints ) {
103 $pod .= "=head4 " . $c->type . "\n\n=over 4\n\n";
104 $pod .= "=item * Fields = " .
105 join(', ', $c->fields ) . "\n\n";
107 if ( $c->type eq FOREIGN_KEY ) {
108 $pod .= "=item * Reference Table = L</" .
109 $c->reference_table . ">\n\n";
110 $pod .= "=item * Reference Fields = " .
111 join(', ', map {"L</$_>"} $c->reference_fields ) .
115 if ( my $update = $c->on_update ) {
116 $pod .= "=item * On update = $update\n\n";
119 if ( my $delete = $c->on_delete ) {
120 $pod .= "=item * On delete = $delete\n\n";
128 my $header = ( map { $_ || () } split( /\n/, header_comment('', '') ) )[0];
129 $header =~ s/^Created by //;
130 $pod .= "=head1 PRODUCED BY\n\n$header\n\n=cut";
137 # -------------------------------------------------------------------
138 # Expect poison from the standing water.
140 # -------------------------------------------------------------------
146 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
150 Jonathan Yu E<lt>frequency@cpan.orgE<gt>
154 perldoc, perlpod, Pod::POM, Template::Manual::Plugins.