| 38 | |
| 39 | == Proposal for the Template Toolkit == |
| 40 | |
| 41 | === Template storage === |
| 42 | |
| 43 | Since there may be several components using the Template toolkit, I suggest to store them under `/usr/share/quattor/templates`. We'd then create one subdir for each component, like this: |
| 44 | |
| 45 | * `/usr/share/quattor/templates/accounts/` |
| 46 | * `/usr/share/quattor/templates/sudo/` |
| 47 | |
| 48 | Does it cause any confusion with the Pan templates (mis-)installed under `/usr/share/doc`? If so, we can choose `/usr/share/quattor/tt`. |
| 49 | |
| 50 | === Invoking the templates === |
| 51 | |
| 52 | All components using `Template::Toolkit` will need the smae configuration, namely; the `INCLUDE_PATH` (that should be configurable) and the ability to access variables that start with an underscore. It's easiest to encapsulate all this in the base class. Then, our component would just request this base class the Template object: |
| 53 | |
| 54 | {{{ |
| 55 | #!perl |
| 56 | my ($self, $config) = @_; |
| 57 | |
| 58 | my $t = $config->getElement("/software/components/foo")->getTree(); |
| 59 | my $tpl = $self->template(); |
| 60 | my $fh = CAF::FileWriter->open("/etc/file", log => $self); |
| 61 | print $fh "#A common header\n"; |
| 62 | $tpl->process("component/template.tt", $t, $fh); |
| 63 | }}} |
| 64 | |
| 65 | Alternatively, the base class '''may''' do the parsing on our behalf ('''is this preferred?'''): |
| 66 | |
| 67 | {{{ |
| 68 | #!perl |
| 69 | my $t = ...->getTree(); |
| 70 | my $fh = CAF::FileWriter->open(...); |
| 71 | $self->process_template("component/template.tt", $t, $fh); |
| 72 | }}} |