in reply to Import Constants From File to Templates?
I just skimmed thru the docs and found two possible approaches:
my $tt = Template->new({ VARIABLES => { version => 3.14, release => 'Sahara', }, }); my $vars = { serial_no => 271828, }; $tt->process('myfile', $vars);
my $tt = Template->new({ CONSTANTS => { version => 3.14, release => 'skyrocket', col => { back => '#ffffff', fore => '#000000', }, myobj => My::Object->new(), mysub => sub { ... }, joint => ', ', }, });
Hence you could write a sub current_constants() which is introspecting your current package and return a list of pairs which maps each constant to it's name. Another way could be to check the exporter settings of the defining package.
my $tt = Template->new({ CONSTANTS => { current_constants() }, });
Once this works you should also be able to write a TT plugin to do this automatically.
Question That's what you want?
°) this was written before the OP added his "EDIT" section.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Import Constants From File to Templates?
by Fletch (Bishop) on Dec 04, 2021 at 14:31 UTC | |
|
Re^2: Import Constants From File to Templates? (introspect current constants) (updated)
by LanX (Saint) on Dec 04, 2021 at 15:04 UTC |