Avoid warning about exiting sub with next
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / Latex.pm
CommitLineData
fae069ed 1package SQL::Translator::Producer::Latex;
2
fae069ed 3=pod
4
5=head1 NAME
6
7SQL::Translator::Producer::Latex -
8 Produces latex formatted tables ready for import from schema.
9
10=head1 SYNOPSIS
11
12 use SQL::Translator;
13 my $translator = SQL::Translator->new(
14 from => 'MySQL',
15 filename => 'foo_schema.sql',
16 to => 'Latex',
17 );
18 print $translator->translate;
19
20=head1 DESCRIPTION
21
22Currently you will get one class (with the a table
23stereotype) generated per table in the schema. The fields are added as
24attributes of the classes and their datatypes set. It doesn't currently set any
25of the relationships. It doesn't do any layout, all the classses are in one big
26stack. However it is still useful as you can use the layout tools in Dia to
27automatically arrange them horizontally or vertically.
28
29=head2 Producer Args
30
31=over 4
32
33=back
34
35=cut
36
fae069ed 37use strict;
f27f9229 38use warnings;
fae069ed 39
0c04c5a2 40our @EXPORT_OK;
41our $VERSION = '1.59';
fae069ed 42$DEBUG = 0 unless defined $DEBUG;
43
44use SQL::Translator::Utils 'debug';
45
46sub produce {
47 my $translator = shift;
48 my $schema = $translator->schema;
49 my $o = '';
50 for my $table ( $schema->get_tables ) {
51 my $table_name = $table->name or next;
52 my $n = latex($table_name);
53 $o .=
54 sprintf '
55\subsubsection{%s}
56%s
57\begin{table}[htb]
58\caption{%s}
59\label{tab:%s}
60\center
61{ \small
62 \begin{tabular}{l l p{8cm}}
63 Column & Datatype & Description \\\\ \hline
64',
65 $n, latex($table->comments), $n, $table_name;
66
67 foreach my $f ($table->get_fields) {
68 $o .= sprintf '%s & %s & %s \\\\', map {latex($_)} ($f->name, $f->data_type, $f->comments || '');
69 $o .= "\n";
70
71 }
72$o .= sprintf '
73\end{tabular}
74}
75\end{table}
76\clearpage
77';
78 }
79 return $o;
80}
81sub latex {
82 my $s = shift;
83 return '' unless defined $s;
84 $s =~ s/([\&\_\$\{\#])/\\$1/g;
85 return $s;
86}
ea93df61 87
fae069ed 881;
89
fae069ed 90=pod
91
92=head1 AUTHOR
93
ea93df61 94Chris Mungall
fae069ed 95
96=head1 SEE ALSO
97
98SQL::Translator.
99
100=cut