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

CGI::Application::Dispatch

  • 9,536 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
9,536
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
4
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

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