1 package SQL::Translator::Producer::POD;
3 # -------------------------------------------------------------------
4 # $Id: POD.pm,v 1.1 2003-06-09 05:37:04 kycl4rk Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
24 use vars qw[ $VERSION ];
25 $VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/;
27 use SQL::Translator::Schema::Constants;
28 use SQL::Translator::Utils qw(header_comment);
30 # -------------------------------------------------------------------
33 my $schema = $t->schema;
34 my $schema_name = $schema->name || 'Schema';
35 my $args = $t->producer_args;
37 my $pod = "=pod\n\n=head1 DESCRIPTION\n\n$schema_name\n\n=head1 TABLES\n\n";
39 for my $table ( $schema->get_tables ) {
40 my $table_name = $table->name or next;
41 my @fields = $table->get_fields or next;
42 $pod .= "=head2 $table_name\n\n=head3 FIELDS\n\n";
47 for my $field ( $table->get_fields ) {
48 $pod .= "=head4 " . $field->name . "\n\n=over 4\n\n";
50 my $data_type = $field->data_type;
51 my $size = $field->size;
52 $data_type .= "($size)" if $size;
54 $pod .= "=item * $data_type\n\n";
55 $pod .= "=item * PRIMARY KEY\n\n" if $field->is_primary_key;
57 my $default = $field->default_value;
58 $pod .= "=item * Default '$default' \n\n" if defined $default;
60 $pod .= sprintf( "=item * Nullable '%s' \n\n",
61 $field->is_nullable ? 'Yes' : 'No' );
69 if ( my @indices = $table->get_indices ) {
70 $pod .= "=head3 INDICES\n\n";
71 for my $index ( @indices ) {
72 $pod .= "=head4 " . $index->type . "\n\n=over 4\n\n";
73 $pod .= "=item * Fields = " .
74 join(', ', $index->fields ) . "\n\n";
82 if ( my @constraints = $table->get_constraints ) {
83 $pod .= "=head3 CONSTRAINTS\n\n";
84 for my $c ( @constraints ) {
85 $pod .= "=head4 " . $c->type . "\n\n=over 4\n\n";
86 $pod .= "=item * Fields = " .
87 join(', ', $c->fields ) . "\n\n";
89 if ( $c->type eq FOREIGN_KEY ) {
90 $pod .= "=item * Reference Table = " .
91 $c->reference_table . "\n\n";
92 $pod .= "=item * Reference Fields = " .
93 join(', ', $c->reference_fields ) . "\n\n";
96 if ( my $update = $c->on_update ) {
97 $pod .= "=item * On update = $update";
100 if ( my $delete = $c->on_delete ) {
101 $pod .= "=item * On delete = $delete";
109 $pod .= "=head1 PRODUCED BY\n\n" . header_comment('', ''). "=cut";
115 # -------------------------------------------------------------------
116 # Expect poison from the standing water.
118 # -------------------------------------------------------------------
122 SQL::Translator::Producer::POD - POD producer for SQL::Translator
126 use SQL::Translator::Producer::POD;
130 Creates a POD description of each table, field, index, and constraint.
131 A good starting point for text documentation of a schema.
135 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>