Catalystアプリケーションを携帯対応にしてみる


ViewはTTでやる。
Viewだけ機種毎に切り替える。

MyApp.pm

use Catalyst qw/
    MobileAgent
/;


TT.pm

# processをオーバーライド
sub process {
    my ( $self, $c ) = @_;

    # 機種を判断
    if($c->req->mobile_agent->is_docomo){
        # ドコモ
        $self->{include_path} = (@{$c->config->{View::TT}->{INCLUDE_PATH}}, $c->path_to('root/docomo_tmpl'));
    }elsif($c->request->mobile_agent->is_vodafone){
        # vodafone
        $self->{include_path} = (@{$c->config->{View::TT}->{INCLUDE_PATH}}, $c->path_to('root/voda_tmpl'));
    }elsif($c->request->mobile_agent->is_ezweb){
        # au
        $self->{include_path} = (@{$c->config->{View::TT}->{INCLUDE_PATH}}, $c->path_to('root/ez_tmpl'));
    }else{
        # PC等
        $self->{include_path} = (@{$c->config->{View::TT}->{INCLUDE_PATH}}, $c->path_to('root/pc_tmpl'));
    }

    # 通常のprocess処理
    $self->SUPER::process($c);

    return 1;
}