CGI::Application::Dispatch
Upcoming SlideShare
Loading in...5
×
 

CGI::Application::Dispatch

on

  • 9,716 views

 

Statistics

Views

Total Views
9,716
Slideshare-icon Views on SlideShare
9,712
Embed Views
4

Actions

Likes
0
Downloads
4
Comments
0

2 Embeds 4

http://www.slideshare.net 3
http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    CGI::Application::Dispatch CGI::Application::Dispatch Presentation Transcript

    • CGI::Application::Dispatch 2008/06/03 Hideo Kimura
    • 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;
    • CGI::Application の難点
      • CGI モードで動かすときにいちいち run させる cgi が必要
      • URI が汚い
        • /index.cgi?rm=index
        • /index.cgi/index
    • 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;
    • CGI::Application::Dispatch
      • /index.cgi/index/index – MyApp::Index->index
      • /index.cgi/foo/bar – MyApp::Foo->bar
      • 一つの CGI でディスパッチしてくれる
    • 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))
    • Dispatchテーブルボキャブラリ
      • literal
        • そのまま URL にマッチング
        • admin/
      • variable
        • コロンで始まると $self->param にわたる
        • :id/
      • 特殊な variable
        • :app – モジュール名
        • :rm – ランモード
    • Dispatch テーブルトランスレーション
      • module_name – Module::Name
      • module-name – ModuleName
      • admin_top-scores – Admin::TopScores
    • 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
    • Tips
      • PATH_INFO は使わない方がいい
      • モジュールの命名規則は計画的に
      • start_mode は統一した方がいい
    • まとめ
      • 素の CGI::Application よりは 100 倍まし ( 当社比 )
      • でも階層が深くなるとそれなりに面倒くさくなる
      • :app/:rm の束縛が強い
      • Catalyst は Dispatcher としてはかなり優秀
    • ご清聴ありがとうございました
      • m(_ _)m