Amon2::Web::Dispatcher::RouterBoom試してみたメモ。
2014年5月3日
まずは/MyApp/Web/Dispatcher.pmを触る。
package MyApp::Web::Dispatcher;
use Amon2::Web::Dispatcher::RouterBoom;
use Module::Find;
useall 'MyApp::Web::C'; # MyApp::Web::C::以下を全部use
base 'MyApp::Web::C';
# / のアクセス
get '/' => 'Root#index';
# /news のアクセス
get '/news' => 'Root#news';
# /news/1 のアクセス
get '/news/:id' => 'Root#news_detail';
# get '/news/{id}' => 'Root#news_detail'; ## 同じ
# /info/11111 のアクセス
get '/info/{info_id:\d+}' => 'Root#info'; # info_idは数字のみ
1;
/MyApp/Web/C/Root.pmを作る。
package MyApp::Web::C::Root;
use strict;
use warnings;
use utf8;
sub index {
my ( $class, $c ) = @_;
return $c->render('index.tx');
}
sub news {
my ( $class, $c ) = @_;
return $c->render('news.tx');
}
sub news_detail {
my ( $class, $c, $args ) = @_;
# /news/***を受け取る
my $id = $args->{'id'};
return $c->render('news_detail.tx');
}
sub info {
my ( $class, $c, $args ) = @_;
# /info/****を受け取る
my $info_id = $args->{'info_id'};
return $c->render('info.tx');
}
1;
これであとはControllerをガシガシ書いていけばいいと。
てな感じで、少しずつですがAmon2触ってます。