| 1 | #!perl | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use File::Basename (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Template::Stencil; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | # Runs under any PSGI server: plackup examples/plack.psgi | ||
| 8 | # (dirname(__FILE__) keeps template resolution independent of cwd). | ||
| 9 | |||
| 10 | 1 | my $stencil = Template::Stencil->new( | |
| 11 | template_dir => File::Basename::dirname(__FILE__) . '/templates', | ||
| 12 | wrapper => 'wrapper.tmpl', | ||
| 13 | stat_ttl => -1, # production: never re-stat cached templates | ||
| 14 | ); | ||
| 15 | |||
| 16 | 2 | ▶ | sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 17 | 2 | my $env = shift; | |
| 18 | my $body = $stencil->render('index', { | ||
| 19 | title => 'Stencil', | ||
| 20 | js_scripts => ['app.js'], | ||
| 21 | user => { name => 'lnation' }, | ||
| 22 | 2 | items => [ map { { name => " item $_ " } } 1 .. 10 ], | |
| 23 | }); | ||
| 24 | 2 | [ 200, | |
| 25 | [ 'Content-Type' => 'text/html; charset=utf-8', | ||
| 26 | 'Content-Length' => length $body ], | ||
| 27 | [ $body ] ]; | ||
| 28 | 1 | }; | |