1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!psgi -w
use strict;
use Text::Xslate;
use Plack::Request;
my %vpath = (
'hello.tx' => <<'TX',
<!doctype html>
<html>
<head>
<title>hello</title>
</head>
<body>
<form><p>
<input type="text" name="lang" />
<input type="submit" />
</p></form>
<p>Hello, <: $lang :> world!</p>
</body>
</html>
TX
);
my $tx = Text::Xslate->new(
path => \%vpath,
cache_dir => '.eg_cache',
);
sub app {
my($env) = @_;
my $req = Plack::Request->new($env);
my $res = $req->new_response(
200,
[content_type => 'text/html; charset=utf-8'],
);
my %vars = (
lang => $req->param('lang') || '<Xslate>',
);
my $body = $tx->render('hello.tx', \%vars);
utf8::encode($body);
$res->body($body);
return $res->finalize();
}
return \&app;
|