1SQL::Translator::ProducUesre:r:TCToSncthreimbau(t3e)d PeSrQlL:D:oTcruamnesnltaattoiro:n:Producer::TTSchema(3)
2
3
4

NAME

6       SQL::Translator::Producer::TTSchema -
7           Produces output using the Template Toolkit from a SQL schema
8

SYNOPSIS

10         use SQL::Translator;
11         my $translator     = SQL::Translator->new(
12             from           => 'MySQL',
13             filename       => 'foo_schema.sql',
14             to             => 'TTSchema',
15             producer_args  => {
16                 ttfile     => 'foo_template.tt',  # Template file to use
17
18                 # Extra template variables
19                 ttargs     => {
20                     author => "Mr Foo",
21                 },
22
23                 # Template config options
24                 ttargs     => {
25                     INCLUDE_PATH => '/foo/templates',
26                 },
27             },
28         );
29         print $translator->translate;
30

DESCRIPTION

32       Produces schema output using a given Template Tookit template.
33
34       It needs one additional producer_arg of "ttfile" which is the file name
35       of the template to use.  This template will be passed a variable called
36       "schema", which is the "SQL::Translator::Producer::Schema" object
37       created by the parser. You can then use it to walk the schema via the
38       methods documented in that module.
39
40       Here's a brief example of what the template could look like:
41
42         database: [% schema.database %]
43         tables:
44         [% FOREACH table = schema.get_tables %]
45             [% table.name %]
46             ================
47             [% FOREACH field = table.get_fields %]
48                 [% field.name %]   [% field.data_type %]([% field.size %])
49             [% END -%]
50         [% END %]
51
52       See t/data/template/basic.tt for a more complete example.
53
54       The template will also get the set of extra variables given as a
55       hashref via the "tt_vars" producer arg.
56
57       You can set any of the options used to initiallize the Template object
58       by adding a tt_conf producer_arg. See Template Toolkit docs for details
59       of the options.  (Note that the old style of passing this config
60       directly in the producer args has been deprecated).
61
62         $translator          = SQL::Translator->new(
63             to               => 'TT',
64             producer_args    => {
65                 ttfile       => 'foo_template.tt',
66                 ttargs       => {},
67                 tt_conf      = {
68                   INCLUDE_PATH => '/foo/templates/tt',
69                   INTERPOLATE  => 1,
70                 }
71             },
72         );
73
74       You can use this producer to create any type of text output you like,
75       even using it to create your own versions of what the other producers
76       make.  For example, you could create a template that translates the
77       schema into MySQL's syntax, your own HTML documentation, your own
78       Class::DBI classes (or some other code) -- the opportunities are
79       limitless!
80
81   Producer Args
82       ttfile
83           The template file to generate the output with.
84
85       tt_vars
86           A hash ref of extra variables you want to add to the template.
87
88       tt_conf
89           A hash ref of configuration options to pass to the Template
90           object's constructor.
91

AUTHOR

93       Mark Addison <grommit@users.sourceforge.net>.
94

TODO

96       More template vars? e.g. [% tables %] as a shortcut for [%
97       schema.get_tables %].
98

SEE ALSO

100       SQL::Translator.
101
102
103
104perl v5.12.0                      2009-08S-Q1L8::Translator::Producer::TTSchema(3)
Impressum