Fix broken POD links found by App::PodLinkChecker
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / GraphViz.pm
index a360e4c..f17a9d3 100644 (file)
@@ -1,23 +1,5 @@
 package SQL::Translator::Producer::GraphViz;
 
-# -------------------------------------------------------------------
-# Copyright (C) 2002-2009 SQLFairy Authors
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307  USA
-# -------------------------------------------------------------------
-
 =pod
 
 =head1 NAME
@@ -28,15 +10,15 @@ SQL::Translator::Producer::GraphViz - GraphViz producer for SQL::Translator
 
   use SQL::Translator;
 
-  my $trans = new SQL::Translator(
+  my $trans = SQL::Translator->new(
       from => 'MySQL',            # or your db of choice
-      to => 'GraphViz',
+      to   => 'GraphViz',
       producer_args => {
-          out_file => 'schema.png',
-          bgcolor => 'lightgoldenrodyellow',
+          out_file         => 'schema.png',
+          bgcolor          => 'lightgoldenrodyellow',
           show_constraints => 1,
-          show_datatypes => 1,
-          show_sizes => 1
+          show_datatypes   => 1,
+          show_sizes       => 1
       }
   ) or die SQL::Translator->error;
 
@@ -88,7 +70,22 @@ table names that should be skipped.
 
 =item * cluster
 
-POD PENDING
+Clustering of tables allows you to group and box tables according to
+function or domain or whatever criteria you choose.  The syntax for
+clustering tables is:
+
+  cluster => 'cluster1=table1,table2;cluster2=table3,table4'
+
+Or pass it as an arrayref like so:
+
+  cluster => [ 'cluster1=table1,table2', 'cluster2=table3,table4' ]
+
+Or like so:
+
+  cluster => [
+    { name => 'cluster1', tables => [ 'table1', 'table2' ] },
+    { name => 'cluster2', tables => [ 'table3', 'table4' ] },
+  ]
 
 =item * out_file
 
@@ -98,14 +95,14 @@ undefined (the default) - the result is returned as a string.
 
 =item * output_type (DEFAULT: 'png')
 
-This determines which 
-L<output method|GraphViz/as_canon,_as_text,_as_gif_etc._methods>
+This determines which
+L<output method|GraphViz/as_canon, as_text, as_gif etc. methods>
 will be invoked to generate the graph: C<png> translates to
 C<as_png>, C<ps> to C<as_ps> and so on.
 
 =item * fontname
 
-This sets the global font name (or full path to font file) for 
+This sets the global font name (or full path to font file) for
 node, edge, and graph labels
 
 =item * fontsize
@@ -116,7 +113,7 @@ constraints)
 
 =item * show_fields (DEFAULT: true)
 
-If set to a true value, the names of the colums in a table will
+If set to a true value, the names of the columns in a table will
 be displayed in each table's node
 
 =item * show_fk_only
@@ -232,8 +229,8 @@ use SQL::Translator::Schema::Constants;
 use SQL::Translator::Utils qw(debug);
 use Scalar::Util qw/openhandle/;
 
-use vars qw[ $VERSION $DEBUG ];
-$VERSION = '1.59';
+our $DEBUG;
+our $VERSION = '1.59';
 $DEBUG   = 0 unless defined $DEBUG;
 
 sub produce {
@@ -304,7 +301,7 @@ sub produce {
       );
 
     # join_pk_only/skip_fields implies natural_join
-    $args->{natural_join} = 1 
+    $args->{natural_join} = 1
       if ($args->{join_pk_only} or scalar keys %skip_fields);
 
     # usually we do not want direction when using natural join
@@ -433,7 +430,7 @@ sub produce {
               my $constraints;
               if ($args->{show_constraints}) {
                 my @constraints;
-                push(@constraints, 'PK') if $field->is_primary_key;
+                push(@constraints, $field->is_auto_increment ? 'PA' : 'PK') if $field->is_primary_key;
                 push(@constraints, 'FK') if $field->is_foreign_key;
                 push(@constraints, 'U')  if $field->is_unique;
                 push(@constraints, 'N')  if $field->is_nullable;
@@ -465,7 +462,7 @@ sub produce {
             push @fmt_indexes, join (' ',
               '*',
               $args->{show_index_names}
-                ? $index->name . ':' 
+                ? $index->name . ':'
                 : ()
               ,
               join (', ', $index->fields),
@@ -594,9 +591,10 @@ sub produce {
                 next if $i == $j;
                 my $table2 = $tables[ $j ];
                 next if $done{ $table1 }{ $table2 };
+                debug("Adding edge '$table2' -> '$table1'");
                 $gv->add_edge(
-                    $table2,
-                    $table1,
+                    qq["$table2"],
+                    qq["$table1"],
                     arrowhead => $optional_constraints{$bi} ? 'empty' : 'normal',
                 );
                 $done{ $table1 }{ $table2 } = 1;
@@ -625,8 +623,6 @@ sub produce {
 
 1;
 
-# -------------------------------------------------------------------
-
 =pod
 
 =head1 AUTHOR