Skip to content

Instantly share code, notes, and snippets.

@rymizuki
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rymizuki/84c0d5c0cb0893c86292 to your computer and use it in GitHub Desktop.
Save rymizuki/84c0d5c0cb0893c86292 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use utr8;
use Raft::Lite;
# 個人的にDSLは最小限に抑えたい
__PACKAGE__->enable_raft_middlewares(
'Lint',
# 拡張子からresponse形式を判定する。
# defaultを指定すると`qr{\.\w+$}`にマッチしないpathのreponseを定義可
'Response::AutoHandler' => +{
default => +{ ext => +{html =>'HTML'} },
}
);
use Data::Section::Simple;
sub load_config {
return +{
'Text::Xslate' => +{
path => Data::Section::Simple->new->get_data_section(),
cache => 0,
},
};
}
# curl 'http://localhost:8000/'
# 特に指定がなければhtmlで返す
get '/' => +{tmpl => 'index.tx'}, sub {
my $self = shift;
return $self->render(+{});
};
# curl 'http://localhost:8000/api/user.json'
# json で返したい
get '/api/user' => +{ext => +{json => 'JSON', xml => 'XML'}}, sub {
my $self = shift;
my $user = $self->model('user')->get(id => $self->session->('get'))
return $self->render($user->to_hashref);
};
__PACKAGE__->to_psgi();
__DATA__
@@ index.tx
<!doctype html>
<html lang="ja">
<head>
<meta charset="UtF-8"/>
<title><: $title :></title>
</head>
<body>
<h1>hello world</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment