my $t = SQL::Translator->new(
from => 'MySQL',
- to => 'GraphViz',
+ to => 'Diagram',
producer_args => {
# All args are optional
out_file => 'schema.png',# if not provided will return from translate()
=cut
use strict;
+use warnings;
use GD;
use Data::Dumper;
use SQL::Translator::Schema::Constants;
use SQL::Translator::Utils qw(debug);
-use vars qw[ $VERSION $DEBUG ];
-$VERSION = '1.59';
+our $DEBUG;
+our $VERSION = '1.62';
$DEBUG = 0 unless defined $DEBUG;
use constant VALID_FONT_SIZE => {
my $schema = $t->schema;
my $args = $t->producer_args;
local $DEBUG = $t->debug;
- debug("Schema =\n", Dumper( $schema ));
- debug("Producer args =\n", Dumper( $args ));
+ debug("Schema =\n", Dumper( $schema )) if $DEBUG;
+ debug("Producer args =\n", Dumper( $args )) if $DEBUG;
my $out_file = $args->{'out_file'} || '';
my $output_type = $args->{'output_type'} || 'png';
my %skip_field = map { $_, 1 } (
ref $args->{'skip_fields'} eq 'ARRAY'
? @{ $args->{'skip_fields'} }
- : split ( /\s*,\s*/, $args->{'skip_fields'} )
+ : split ( /\s*,\s*/, $args->{'skip_fields'}||'' )
);
my %skip_table = map { $_, 1 } (
ref $args->{'skip_tables'} eq 'ARRAY'
? @{ $args->{'skip_tables'} }
- : split ( /\s*,\s*/, $args->{'skip_tables'} )
+ : split ( /\s*,\s*/, $args->{'skip_tables'}||'' )
);
my @skip_tables_like = map { qr/$_/ } (
ref $args->{'skip_tables_like'} eq 'ARRAY'
? @{ $args->{'skip_tables_like'} }
- : split ( /\s*,\s*/, $args->{'skip_tables_like'} )
+ : split ( /\s*,\s*/, $args->{'skip_tables_like'}||'' )
);
my @table_names;
debug("Processing table '$table_name'");
my @fields = $table->get_fields;
- debug("Fields = ", join(', ', map { $_->name } @fields));
+ debug("Fields = ", join(', ', map { $_->name } @fields)) if $DEBUG;
my ( @fld_desc, $max_name, $max_desc );
for my $f ( @fields ) {
my $nlen = length $name;
my $dlen = length $desc;
- $max_name = $nlen if $nlen > $max_name;
- $max_desc = $dlen if $dlen > $max_desc;
+ $max_name = $nlen if $nlen > ($max_name||0);
+ $max_desc = $dlen if $dlen > ($max_desc||0);
push @fld_desc, [ $name, $desc, $f->{'name'}, $is_pk, $attr ];
}
];
push @shapes, [ 'rectangle', @bounds, 'black' ];
- $max_x = $this_max_x if $this_max_x > $max_x;
+ $max_x = $this_max_x if $this_max_x > ($max_x||0);
$y += 25;
if ( ++$no_this_col == $no_per_col ) {# if we've filled up this column
$no_this_col = 0; # reset the number of tables
$max_x += $gutter; # push the x over for next column
$this_col_x = $max_x; # remember the max x for this col
- $max_y = $y if $y > $max_y; # note the max y
+ $max_y = $y if $y > ($max_y||0); # note the max y
$y = $orig_y; # reset the y for next column
}
}
my $longest;
for my $len ( map { length $_ } values %legend ) {
- $longest = $len if $len > $longest;
+ $longest = $len if $len > ($longest||0);
}
$longest += 2;