Template-EmbeddedPerl
view release on metacpan or search on metacpan
lib/Template/EmbeddedPerl/Cookbook.pod view on Meta::CPAN
smart_lines => 1,
auto_escape => 1,
);
my $page = $engine->from_string(<<'EPL');
<ul>
%= partial 'contacts/item', contact => {name => '<Jane>'}
</ul>
EPL
is($page->render, "<ul>\n<li><Jane></li>\n</ul>\n");
The expected result isolates the partial's argument contract and escaping. Use
the same approach for layouts, supplying a minimal page body and then asserting
the wrapper. The checked-in C<t/partial.t> and C<t/layout.t> are runnable
examples of both forms.
=head2 How do I give string and filehandle templates useful source labels?
Pass C<source> whenever the input has a meaningful origin:
B<Fragment: application code>
my $compiled = $engine->from_string(
"first\n<%= \$missing %>\n",
source => 'emails/welcome.epl',
);
my $from_fh = $engine->from_fh(
$fh,
source => 'emails/password-reset.epl',
);
A compile error in the first template reports C<emails/welcome.epl line 2>.
Use labels for generated, database-backed, and streamed templates so errors
identify the actual source and template line.
=head2 How do I read a compile diagnostic and render stack?
An error has a source name, a template line, and nearby source context. Errors
that cross partial, layout, or typed-view composition also end with a render
stack:
B<Fragment: error handling around a composed page>
my $error = eval { $engine->from_file('pages/contacts')->render; '' } || $@;
warn $error;
# ... at /srv/contacts/templates/contacts/item.epl line 2
# Render stack:
# root pages/contacts (/srv/contacts/templates/pages/contacts.epl)
# partial contacts/item (/srv/contacts/templates/contacts/item.epl)
Use the source and line to repair the local template first, then read the stack
from top to bottom to see which parent rendered it. Give string templates a
C<source> label so they provide the same diagnostic value as files.
=head2 How do I inspect the generated Perl?
Set the debug environment variable for a one-off run:
DEBUG_TEMPLATE_EMBEDDED_PERL=1 perl script.pl
The engine writes a C<Compiled: ...> representation of the generated Perl to
standard error before evaluation. Use this only to investigate difficult
compilation problems, then disable it; generated code is an implementation
detail rather than an application interface.
=head1 SEE ALSO
L<Template::EmbeddedPerl>, L<Template::EmbeddedPerl::Tutorial>, and
L<Template::EmbeddedPerl::Cookbook::TypedViews>.
=cut
( run in 0.645 second using v1.01-cache-2.11-cpan-0b58ddf2af1 )