67. Request Parameters
get '/' => sub {
my $id = param 'id';
};
post '/' => sub {
my $id = param 'id';
my $file = upload('file');
# Dancer::Request::Upload object
$file->copy_to('/path/to/flie');
};
68. Request Parameters
# GET /entry/foo?id=bar
get '/entry/:id' => sub {
my $id = param 'id';
# $id => foo
};
# 追記 paramsを使えばデータソース別に取れます
# perldoc Dancer::Request
# Fetching_only_params_from_a_given_source
69. Con?g
set 'tmdpir' => '/tmp/myapp';
get '/' => sub {
my $config = config;
return $config->{appname};
};
70. Cookie
get '/login' => sub {
my $id = param 'id';
my $password = param 'password';
if ( $id eq 'cto'
&& $password eq 'onagatani' )
{
cookie 'logged_in' => 1;
redirect '/';
}
};
71. Session
set session => 'YAML';
set session_dir => '/tmp/sessions';
set session_name => 'sid';
# default dancer.session
get '/login' => sub {
my $id = param 'id';
my $password = param 'password';
if ( $id eq 'cto'
&& $password eq 'onagatani' ) {
session 'user' => { name => 'onagatani' };
redirect '/';
}
};
72. Template
set template => ‘template_toolkit’;
get '/' => sub {
my $id = param 'id';
template 'index', { id => $id };
};