Remove copyright headers from individual scripts
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / GraphViz.pm
index 764074e..3c026eb 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
 
@@ -245,10 +242,13 @@ sub produce {
     # translate legacy {node|edge|graph}attrs to just {node|edge|graph}
     for my $argtype (qw/node edge graph/) {
         my $old_arg = $argtype . 'attrs';
-        $args->{$argtype} = {
-          map { %{ $_ || {} } }
-          ( delete $args->{$old_arg}, $args->{$argtype} )
-        };
+
+        my %arglist = (map
+          { %{ $_ || {} } }
+          ( delete $args->{$old_arg}, delete $args->{$argtype} )
+        );
+
+        $args->{$argtype} = \%arglist if keys %arglist;
     }
 
     # explode font settings
@@ -341,7 +341,6 @@ sub produce {
         }
     }
 
-
     #
     # Create a blank GraphViz object and see if we can produce the output type.
     #
@@ -517,7 +516,7 @@ sub produce {
           $node_args->{cluster} = $cluster_name;
         }
 
-        $gv->add_node ($table_name, %$node_args);
+        $gv->add_node(qq["$table_name"], %$node_args);
 
         debug("Processing table '$table_name'");
 
@@ -592,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;