1 package SQL::Translator::Producer::POD;
3 # -------------------------------------------------------------------
4 # $Id: POD.pm,v 1.5 2004-02-09 23:02:15 kycl4rk Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2002-4 SQLFairy Authors
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 # -------------------------------------------------------------------
25 SQL::Translator::Producer::POD - POD producer for SQL::Translator
31 my $t = SQL::Translator->new( parser => '...', producer => 'POD', '...' );
36 Creates a POD description of each table, field, index, and constraint.
37 A good starting point for text documentation of a schema. You can
38 easily convert the output to HTML or text using "perldoc" or other
39 interesting formats using Pod::POM or Template::Toolkit's POD plugin.
44 use vars qw[ $VERSION ];
45 $VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
47 use SQL::Translator::Schema::Constants;
48 use SQL::Translator::Utils qw(header_comment);
50 # -------------------------------------------------------------------
53 my $schema = $t->schema;
54 my $schema_name = $schema->name || 'Schema';
55 my $args = $t->producer_args;
56 my $title = $args->{'title'} || $schema_name;
58 my $pod = "=pod\n\n=head1 DESCRIPTION\n\n$title\n\n=head1 TABLES\n\n";
60 for my $table ( $schema->get_tables ) {
61 my $table_name = $table->name or next;
62 my @fields = $table->get_fields or next;
63 $pod .= "=head2 $table_name\n\n=head3 FIELDS\n\n";
68 for my $field ( @fields ) {
69 $pod .= "=head4 " . $field->name . "\n\n=over 4\n\n";
71 my $data_type = $field->data_type;
72 my $size = $field->size;
73 $data_type .= "($size)" if $size;
75 $pod .= "=item * $data_type\n\n";
76 $pod .= "=item * PRIMARY KEY\n\n" if $field->is_primary_key;
78 my $default = $field->default_value;
79 $pod .= "=item * Default '$default' \n\n" if defined $default;
81 $pod .= sprintf( "=item * Nullable '%s' \n\n",
82 $field->is_nullable ? 'Yes' : 'No' );
90 if ( my @indices = $table->get_indices ) {
91 $pod .= "=head3 INDICES\n\n";
92 for my $index ( @indices ) {
93 $pod .= "=head4 " . $index->type . "\n\n=over 4\n\n";
94 $pod .= "=item * Fields = " .
95 join(', ', $index->fields ) . "\n\n";
103 if ( my @constraints = $table->get_constraints ) {
104 $pod .= "=head3 CONSTRAINTS\n\n";
105 for my $c ( @constraints ) {
106 $pod .= "=head4 " . $c->type . "\n\n=over 4\n\n";
107 $pod .= "=item * Fields = " .
108 join(', ', $c->fields ) . "\n\n";
110 if ( $c->type eq FOREIGN_KEY ) {
111 $pod .= "=item * Reference Table = L</" .
112 $c->reference_table . ">\n\n";
113 $pod .= "=item * Reference Fields = " .
114 join(', ', map {"L</$_>"} $c->reference_fields ) .
118 if ( my $update = $c->on_update ) {
119 $pod .= "=item * On update = $update";
122 if ( my $delete = $c->on_delete ) {
123 $pod .= "=item * On delete = $delete";
131 my $header = ( map { $_ || () } split( /\n/, header_comment('', '') ) )[0];
132 $header =~ s/^Created by //;
133 $pod .= "=head1 PRODUCED BY\n\n$header\n\n=cut";
140 # -------------------------------------------------------------------
141 # Expect poison from the standing water.
143 # -------------------------------------------------------------------
149 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
153 perldoc, perlpod, Pod::POM, Template::Manual::Plugins.