Template-EmbeddedPerl
view release on metacpan or search on metacpan
README.mkdn view on Meta::CPAN
Can't locate object method "input" at /path/to/templates/hello.yat line 4.
3: <%= label('first_name') %>
4: <%= input('first_name') %>
5: <%= errors('last_name') %>
# ENVIRONMENT VARIABLES
The module respects the following environment variables:
- `DEBUG_TEMPLATE_EMBEDDED_PERL`
Set this to a true value to print the compiled template code to the console. Useful
when trying to debug difficult compilation issues, especially given this is early
access code and you might run into bugs.
# REPORTING BUGS & GETTING HELP
If you find a bug, please report it on the GitHub issue tracker at
[https://github.com/jjn1056/Template-EmbeddedPerl/issues](https://github.com/jjn1056/Template-EmbeddedPerl/issues). The bug tracker is
the easiest way to get help with this module from me but I'm also on irc.perl.org
lib/Template/EmbeddedPerl.pm view on Meta::CPAN
die "Invalid sandbox namespace '$sandbox_ns'"
unless defined($sandbox_ns) && $sandbox_ns =~ /\A[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*\z/;
my %helpers = $self->get_helpers;
foreach my $helper(keys %helpers) {
die "Invalid template helper name '$helper'"
unless $helper =~ /\A[A-Za-z_]\w*\z/;
if($self->{sandbox_ns}->can($helper)) {
warn "Skipping injection of helper '$helper'; already exists in namespace $self->{sandbox_ns}"
if $ENV{DEBUG_TEMPLATE_EMBEDDED_PERL};
next;
}
eval qq[
package @{[ $self->{sandbox_ns} ]};
sub $helper {
my \$context = Template::EmbeddedPerl->_current_render_context('$helper');
my \$engine = \$context->engine;
\$engine->get_helpers('$helper')->(\$engine, \@_);
}
]; die $@ if $@;
lib/Template/EmbeddedPerl.pm view on Meta::CPAN
$content =~ s/^\\\\/\\/mg;
$compiled .= ("\n" x $escaped_newline_start)
. ' $_O .= "' . quotemeta($content) . '";'
. ("\n" x $escaped_newline_end);
}
}
$compiled = $self->compiled($compiled, $source);
warn "Compiled: $compiled\n" if $ENV{DEBUG_TEMPLATE_EMBEDDED_PERL};
my $code = eval $compiled; if($@) {
die generate_error_message($@, $template, $source);
}
return $code;
}
sub compiled {
my ($self, $compiled, $source) = @_;
lib/Template/EmbeddedPerl.pm view on Meta::CPAN
decorated with one source-aware C<Render stack>; failed rendering restores the
frame's body, named content, layouts, and stack state so the engine can be
reused for a later top-level render.
=head1 ENVIRONMENT VARIABLES
The module respects the following environment variables:
=over 4
=item * C<DEBUG_TEMPLATE_EMBEDDED_PERL>
Set this to a true value to print the compiled template code to the console. Useful
when trying to debug difficult compilation issues, especially given this is early
access code and you might run into bugs.
=back
=head1 REPORTING BUGS & GETTING HELP
If you find a bug, please report it on the GitHub issue tracker at
lib/Template/EmbeddedPerl/Cookbook.pod view on Meta::CPAN
# 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>.
lib/Template/EmbeddedPerl/Utils.pm view on Meta::CPAN
my $label = defined($source) && length("$source") ? "$source" : 'unknown';
$label =~ s/(?:\r\n?|\n)+/ /g;
$label =~ tr/"/'/;
$label =~ s/[\x00-\x1f\x7f]/?/g;
return $label;
}
sub generate_error_message {
my ($msg, $template, $source) = @_;
warn "RAW MESSAGE: [$msg]" if $ENV{DEBUG_TEMPLATE_EMBEDDED_PERL};
return $msg if _has_render_stack($msg);
$source = diagnostic_source_label($source);
my $text = '';
my $has_template_location = 0;
for my $diagnostic_line (split /(?<=\n)/, $msg) {
my ($message, $line) = _template_location($diagnostic_line, $source);
if (!defined $line) {
t/cookbook_examples.t view on Meta::CPAN
}
my $dist_ini = read_file(File::Spec->catfile($root, 'dist.ini'));
like(
$dist_ini,
qr/^\[MetaNoIndex\]\ndirectory = examples$/m,
'distribution metadata excludes shipped examples from PAUSE indexing',
);
SKIP: {
my $built_meta_path = $ENV{TEMPLATE_EMBEDDED_PERL_BUILT_META};
skip 'built META.json path was not provided', 2 unless defined $built_meta_path;
ok(-f $built_meta_path, 'built META.json exists');
skip 'built META.json is unavailable', 1 unless -f $built_meta_path;
my $built_meta = decode_json(read_file($built_meta_path));
is_deeply(
$built_meta->{no_index},
{directory => ['examples']},
'built metadata excludes the examples directory from indexing',
);
( run in 1.654 second using v1.01-cache-2.11-cpan-0b58ddf2af1 )