1SQL::Translator::ProducUesre:r:TCToSncthreimbau(t3e)d PeSrQlL:D:oTcruamnesnltaattoiro:n:Producer::TTSchema(3)
2
3
4
6 SQL::Translator::Producer::TTSchema -
7 Produces output using the Template Toolkit from a SQL schema
8
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
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 cre‐
37 ated 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 limit‐
79 less!
80
81 Producer Args
82
83 ttfile
84 The template file to generate the output with.
85
86 tt_vars
87 A hash ref of extra variables you want to add to the template.
88
89 tt_conf
90 A hash ref of configuration options to pass to the Template
91 object's constructor.
92
94 Mark Addison <grommit@users.sourceforge.net>.
95
97 More template vars? e.g. [% tables %] as a shortcut for [%
98 schema.get_tables %].
99
101 SQL::Translator.
102
103
104
105perl v5.8.8 2007-10S-Q2L4::Translator::Producer::TTSchema(3)