CGI::Application::Dispatch

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    CGI::Application::Dispatch - Presentation Transcript

    1. CGI::Application::Dispatch 2008/06/03 Hideo Kimura
    2. CGI::Application
      • MyApp/Index.pm
      • package MyApp::Index;
      • use base qw(CGI::Application);
      • sub setup {
      • my $self = shift;
      • $self->start_mode(‘index’);
      • $self->run_modes(
      • ‘ index’ => ‘index’;
      • }
      • sub index {return ‘Hello World’;}
      • 1;
      • index.cgi
      • #!/usr/bin/perl
      • use MyApp::Index;
      • my $app = MyApp::Index->new;
      • $app->run;
    3. CGI::Application の難点
      • CGI モードで動かすときにいちいち run させる cgi が必要
      • URI が汚い
        • /index.cgi?rm=index
        • /index.cgi/index
    4. CGI::Application::Dispatch
      • MyApp/Dispach.pm
      • package MyApp::Dispatch;
      • use base qw(CGI::Application::Dispatch);
      • sub dispatch_args {
      • return {
      • prefix => 'MyApp',
      • };
      • }
      • index.cgi
      • #!/usr/bin/perl
      • use MyApp::Dispatch;
      • MyApp::Dispatch->dispatch;
    5. CGI::Application::Dispatch
      • /index.cgi/index/index – MyApp::Index->index
      • /index.cgi/foo/bar – MyApp::Foo->bar
      • 一つの CGI でディスパッチしてくれる
    6. Dispatchテーブル
      • sub dispatch_args {
      • return {
      • prefix => 'MyApp',
      • table => [
      • '' => { app => ‘Index', rm => ‘index' },
      • ':app/:rm' => { },
      • 'admin/:app/:rm' => { prefix => 'MyApp::Admin' },
      • ‘ news/:id' => { app => ‘News’, rm => ‘index’ },
      • ],
      • };
      • }
      • /index.cgi – MyApp::Index->index
      • /index.cgi/foo/bar – MyApp::Foo->bar
      • /index.cgi/admin/foo/bar – MyApp::Admin::Foo->bar
      • /index.cgi/news/100 – MyApp::News->index($self->param(id => 100))
    7. Dispatchテーブルボキャブラリ
      • literal
        • そのまま URL にマッチング
        • admin/
      • variable
        • コロンで始まると $self->param にわたる
        • :id/
      • 特殊な variable
        • :app – モジュール名
        • :rm – ランモード
    8. Dispatch テーブルトランスレーション
      • module_name – Module::Name
      • module-name – ModuleName
      • admin_top-scores – Admin::TopScores
    9. mod_rewrite で URI を Cool に
      • .htaccess
      • RewriteEngine On
      • RewriteBase /~hide/cgiapp/html
      • # If an actual file or directory is requested, serve directly
      • RewriteCond %{REQUEST_FILENAME} !-f
      • RewriteCond %{REQUEST_FILENAME} !-d
      • # Otherwise, pass everything through to the dispatcher
      • RewriteRule ^(.*)$ /~hide/cgiapp/html/index.cgi/$1 [L,QSA]
      • /
      • /admin/index
      • /news/100
    10. Tips
      • PATH_INFO は使わない方がいい
      • モジュールの命名規則は計画的に
      • start_mode は統一した方がいい
    11. まとめ
      • 素の CGI::Application よりは 100 倍まし ( 当社比 )
      • でも階層が深くなるとそれなりに面倒くさくなる
      • :app/:rm の束縛が強い
      • Catalyst は Dispatcher としてはかなり優秀
    12. ご清聴ありがとうございました
      • m(_ _)m

    + Hideo KimuraHideo Kimura, 2 years ago

    custom

    1005 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1005
      • 1005 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 2
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags