Fagyal Csongor wrote:
[% SET a = "
adsf
adsf
"
%]
[...]
is compiled to
"\n adsf\n \n "
No, it's not. It's compiled to this:
$stash->set('a', '
adsf
adsf
');
TT works correctly in both this and your earlier PERL
example. Here's a test script:
use strict;
use warnings;
use Template;
use Template::Parser;
$Template::Parser::DEBUG = 1;
my $tt = Template->new(EVAL_PERL => 1);
$tt->process(\*DATA);
__END__
[% SET a = "
line one
line two
"
%]
<<[% a %]>>
[% PERL %]
my $xxx = <<__EOF__;
foo
bar
baz
__EOF__
print "<<$xxx>>";
[% END %]
Here's the program output:
<<
line one
line two
>>
<<foo
bar
baz
>>
Looks good to me.
And here's the debug output showing the Perl code generated:
[Template::Parser] compiled main template document block:
sub {
my $context = shift || die "template sub called without context\n";
my $stash = $context->stash;
my $output = '';
my $error;
eval { BLOCK: {
#line 1 "input file handle"
$stash->set('a', '
line one
line two
');
$output .= "\n<<";
#line 6 "input file handle"
$output .= $stash->get('a');
$output .= ">>\n\n";
#line 16 "input file handle"
# PERL
$context->throw('perl', 'EVAL_PERL not set')
unless $context->eval_perl();
$output .= do {
my $output = "package Template::Perl;\n";
$output .= "\nmy \$xxx = <<__EOF__;\nfoo\nbar\nbaz\n__EOF__\n\nprint
\"<<\$xxx>>\";\n";
local($Template::Perl::context) = $context;
local($Template::Perl::stash) = $stash;
my $result = '';
tie *Template::Perl::PERLOUT, 'Template::TieString', \$result;
my $save_stdout = select *Template::Perl::PERLOUT;
eval $output;
select $save_stdout;
$context->throw($@) if $@;
$result;
};
$output .= "\n";
} };
if ($@) {
$error = $context->catch($@, \$output);
die $error unless $error->type eq 'return';
}
return $output;
}
It's worth pointing out that you will get indenting added if you
set the Template::Directives::PRETTY flag. It's used to make the
generated Perl code easier to read for humans debugging it, but
shouldn't normally be enabled in a "live" system. Perhaps that's
the source of the confusion? i.e. you set the flag to debug the
code and you're seeing the prettified code with indenting.
Without that flag set, TT should generate it as you wrote it. No
auto-indent.
HTH
A
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates