Skip to content

Commit

Permalink
add compiled EP template example to rendering guide
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 28, 2012
1 parent 8cb0db9 commit 6bd4adb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.56 2012-02-28 00:00:00
2.56 2012-02-29 00:00:00
- Improved documentation.

2.55 2012-02-28 00:00:00
Expand Down
24 changes: 20 additions & 4 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -92,6 +92,20 @@ expressions.
% }
</ul>

Aside from differences in whitespace handling, both examples generate similar
Perl code, a naive translation could look like this.

my $output = '';
my $i = 10;
$output .= '<ul>';
for my $j (1 .. $i) {
$output .= '<li>';
$output .= escape scalar $j;
$output .= '</li>';
}
$output .= '</ul>';
return $output;

An additional equal sign can be used to disable escaping of the characters
C<E<lt>>, C<E<gt>>, C<&>, C<'> and C<"> in results from Perl expressions,
which is the default to prevent XSS attacks against your application.
Expand Down Expand Up @@ -443,18 +457,20 @@ Blocks are always delimited by the C<begin> and C<end> keywords.
%= $block->('Sebastian')
% }

A naive translation to Perl pseudocode could look like this.
A naive translation to Perl code could look like this.

@@ welcome.html.pl
my $output = '';
my $block = sub {
my $name = shift;
my $output = '';
$output .= "Hello $name.";
return $output;
$output .= 'Hello ';
$output .= escape scalar $name;
$output .= '.';
return Mojo::ByteStream->new($output);
}
for (1 .. 10) {
$output .= $block->('Sebastian');
$output .= escape scalar $block->('Sebastian');
}
return $output;

Expand Down

0 comments on commit 6bd4adb

Please sign in to comment.