Last active
August 29, 2015 14:00
-
-
Save rymizuki/84c0d5c0cb0893c86292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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