generate svg of DBICTest::Schema in author mode
[dbsrgits/DBIx-Class.git] / maint / gen_dbictest_schema_diagram
CommitLineData
ad93ee36 1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
6use DBICTest;
7
8use Module::Runtime 'use_module';
9use SQL::Translator;
10use Path::Class 'file';
11use Getopt::Long;
12my $getopt = Getopt::Long::Parser->new(
13 config => [qw/gnu_getopt bundling_override no_ignore_case/]
14);
15my $args = {};
16$getopt->getoptions($args, qw/
17 diagram-out=s@
18 schema-class=s@
19/);
20
21die "You need to specify one diagram output filename via --diagram-out\n"
22 if @{$args->{'diagram-out'}||[]} != 1;
23
24die "You need to specify one DBIC schema class via --schema-class\n"
25 if @{$args->{'schema-class'}||[]} != 1;
26
27my $diagram_fh;
28if ($args->{'diagram-out'}[0] eq '-') {
29 $diagram_fh = *STDOUT;
30}
31else {
32 my $fn = file($args->{'diagram-out'}[0]);
33 $fn->dir->mkpath;
34 open $diagram_fh, '>', $fn
35 or die "Unable to open $fn: $!\n";
36}
37binmode $diagram_fh; # avoid win32 \n crapfest
38
39my $schema_class = $args->{'schema-class'}[0];
40use_module( $schema_class );
41my $schema = $schema_class->connect( DBICTest->_database(quote_char => '"') );
42
43my $trans = SQL::Translator->new(
44 parser => 'SQL::Translator::Parser::DBIx::Class',
45 parser_args => { dbic_schema => $schema },
46 producer => 'GraphViz',
47 producer_args => {
48 show_constraints => 1,
49 show_datatypes => 1,
50 show_sizes => 1,
51 out_file => $diagram_fh,
52 output_type => 'svg',
53 layout => 'neato',
54 }
55);
56
57$trans->translate or die $trans->error;