Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Text::Template and delayed use vars

by frazap (Beadle)
on May 04, 2018 at 11:50 UTC ( #1214051=note: print w/replies, xml ) Need Help??


in reply to Text::Template and delayed use vars

Yes it's possible, reading Simon Cozens' Advanced Perl, I found this whitch work:
foreach my $f (@files) { my $config = Config::YAML::Tiny->new( config => $f ); my @template_file = split( / /, $config->get_template ); foreach my $tf (@template_file) { my @fields = split( / /, $config->get_fields ); for my $v ( @fields ) { no strict 'refs'; *{"T::$v"}= \$config->{$v}; } my $template = Text::Template->new( TYPE => 'FILE', SOURCE => $tf ) or die "Couldn't construct template: $Text::Template::ERROR" +; my $result = $template->fill_in( PACKAGE => 'T', PREPEND => 'use strict;' ); ...

And in the template file(s) I had to change $value with $T::value, $pos with $T::pos

update In fact, with $T::pos in the template file, I loose the error if the variable name is wrong: $T:ops is just replace by nothing but no error is given. I have to use $pos or $value in the template.

The docs could be made clearer I think

F.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1214051]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2018-07-22 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (452 votes). Check out past polls.

    Notices?