SlideShare a Scribd company logo
1 of 27
Download to read offline
YAPC::Asia 2009                     2009/09/10




                 dann
          techmemo@gmail.com

Angelos           github.com/dann          dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
request
            Engine                                    response
                                              (                  with Plack)
                                                  miyagawa++, tokuhirom++



                                                    Component
          Dispatcher                                 Manager
            URL to Controller
                                                     Component load & search
Angelos                         github.com/dann                                dann
Angelos   github.com/dann   dann
sub build_engine {
  my $self         = shift;
  my $request_handler = $self->request_handler;
  $request_handler ||= $self->build_request_handler;
    return Angelos::PSGI::Engine->new(
       interface => {                    Server Gateway
          module => $self->server,
          ....
       },
       psgi_handler => $request_handler,
    );                            Server Gateway
}
                                           psgi handler
Angelos                  github.com/dann                  dann
use Mouse;
use Angelos::Types qw( ServerGateway );
 
has 'interface' => (
                                     Server Gateway
    is => 'ro',
    isa => ServerGateway,
    coerce => 1,
);                                          Server Gateway
                                          psgi handler (coderef)
has 'psgi_handler' => ( is => 'rw', );
 
sub run {
    my $self = shift;
    $self->interface->run( $self->psgi_handler );
}
 Angelos                   github.com/dann                     dann
package Angelos::PSGI::ServerGatewayBuilder;
use strict;
use warnings;
use Plack::Loader;                 Plack::Loader
                                     ServerGateway
sub build {
  my ( $class, $module, $args ) = @_;
  my $server_gateway = Plack::Loader->load( $module,
%{$args} );
  $server_gateway;
}

 Angelos                 github.com/dann             dann
PSGI   env

...                               WAF Request
sub {                            (with Plack::Request)
          my $env = shift;
          my $req = Angelos::Request->new($env);
          my $res = $self->handle_request($req);
          my $psgi_res = $self->finalize_response($res);
          return $psgi_res;
}
...                      PSGI   response



Angelos                   github.com/dann                 dann
sub handle_request {                         req Dsipatcher
  my ( $self, $req ) = @_;
      eval { $self->DISPATCH($req); };
      if ( my $e = Exception::Class->caught() ) {
          $self->HANDLE_EXCEPTION($e);
      }
      # response
      return $self->context->res;
}

    Angelos                github.com/dann                    dann
request Dispatcher
sub DISPATCH {
  my ( $self, $req ) = @_;               dispatch

    my $dispatch = $self->dispatcher->dispatch($req);
    ...
    # dispatch
    $dispatch->run;
    # response
    $c->res;
}

Angelos                github.com/dann                       dann
<URL to Controller>
sub dispatch {                           HTTP::Router request
  my ( $self, $request ) = @_;                      route
                                         (ikasam_a++)
  my $match = $self->router->match($request);

  my $dispatch = $self->dispatch_class->new( match =>
$match );
  return $dispatch;
}                                   dispatch



Angelos                github.com/dann                        dann
# matching         controller
my $controller = $match->params->{controller};
my $controller_instance = $self-
>find_controller_instance(                Component Manager
    { context => $c,                      Controller
      controller => $controller,
    }
);                                       Controller action
...
$controller_instance->_dispatch_action( $action,
$params );

 Angelos               github.com/dann                       dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
sub _dispatch_action {
  my ( $self, $action, $params ) = @_; Hook
  ...
      eval { $self->ACTION( $self->context, $action, $params ); };
      ...
}




    Angelos                   github.com/dann                        dann
before 'ACTION' => sub {
   my ( $self, $c, $action, $params ) = @_;
   $self->__action_start_time( time() );
};
after 'ACTION' => sub {
   my ( $self, $c, $action, $params ) = @_;
   $self->__action_end_time( time() );
   my $elapsed = $self->__action_end_time - $self-
>__action_start_time;
   my $message
      = "action processing time:naction: $action ntime : $elapsed
secsn";
   $self->log->info($message);
};


 Angelos                    github.com/dann                      dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann
Angelos   github.com/dann   dann

More Related Content

What's hot

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Silex: From nothing to an API
Silex: From nothing to an APISilex: From nothing to an API
Silex: From nothing to an API
chrisdkemper
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
Kris Wallsmith
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
memememomo
 
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Atlassian
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
 

What's hot (20)

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Silex: From nothing to an API
Silex: From nothing to an APISilex: From nothing to an API
Silex: From nothing to an API
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack Support
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
 

Viewers also liked

はてブ砲をくらったときのお話
はてブ砲をくらったときのお話はてブ砲をくらったときのお話
はてブ砲をくらったときのお話
Tsukasa Oishi
 

Viewers also liked (20)

究極にして至高のWAF
究極にして至高のWAF究極にして至高のWAF
究極にして至高のWAF
 
Separate Model from Catalyst
Separate Model from CatalystSeparate Model from Catalyst
Separate Model from Catalyst
 
はてブ砲をくらったときのお話
はてブ砲をくらったときのお話はてブ砲をくらったときのお話
はてブ砲をくらったときのお話
 
2014-10-27 #ssmjp 腹を割って話そう (運用xセキュリティ)
2014-10-27 #ssmjp 腹を割って話そう (運用xセキュリティ)2014-10-27 #ssmjp 腹を割って話そう (運用xセキュリティ)
2014-10-27 #ssmjp 腹を割って話そう (運用xセキュリティ)
 
今日から始めるDigitalOcean
今日から始めるDigitalOcean今日から始めるDigitalOcean
今日から始めるDigitalOcean
 
科研費データベースの分野分類とトピック分類の比較分析
科研費データベースの分野分類とトピック分類の比較分析科研費データベースの分野分類とトピック分類の比較分析
科研費データベースの分野分類とトピック分類の比較分析
 
科研費分野-トピック分類マトリックスへの主成分分析の適用
科研費分野-トピック分類マトリックスへの主成分分析の適用科研費分野-トピック分類マトリックスへの主成分分析の適用
科研費分野-トピック分類マトリックスへの主成分分析の適用
 
C# LINQ ~深く知って、使いまくろう~
C# LINQ ~深く知って、使いまくろう~C# LINQ ~深く知って、使いまくろう~
C# LINQ ~深く知って、使いまくろう~
 
はじめてのWi-Fiクラック
はじめてのWi-FiクラックはじめてのWi-Fiクラック
はじめてのWi-Fiクラック
 
インターネッツの繋がるしくみ(物理層編) #sa_study
インターネッツの繋がるしくみ(物理層編) #sa_studyインターネッツの繋がるしくみ(物理層編) #sa_study
インターネッツの繋がるしくみ(物理層編) #sa_study
 
Ansible & Cumulus Networks - Simplify Network Automation
Ansible & Cumulus Networks - Simplify Network AutomationAnsible & Cumulus Networks - Simplify Network Automation
Ansible & Cumulus Networks - Simplify Network Automation
 
DockerとKubernetesが作る未来
DockerとKubernetesが作る未来DockerとKubernetesが作る未来
DockerとKubernetesが作る未来
 
WordPressプラグイン開発の めんどうな作業は執事(Jenkins)にお任せ
WordPressプラグイン開発の めんどうな作業は執事(Jenkins)にお任せWordPressプラグイン開発の めんどうな作業は執事(Jenkins)にお任せ
WordPressプラグイン開発の めんどうな作業は執事(Jenkins)にお任せ
 
〜 デザイン脳×プログラミング脳 〜 デザイナーとプログラマーの72時間戦争
〜 デザイン脳×プログラミング脳 〜 デザイナーとプログラマーの72時間戦争〜 デザイン脳×プログラミング脳 〜 デザイナーとプログラマーの72時間戦争
〜 デザイン脳×プログラミング脳 〜 デザイナーとプログラマーの72時間戦争
 
ノリとその場の勢いでPocを作った話
ノリとその場の勢いでPocを作った話ノリとその場の勢いでPocを作った話
ノリとその場の勢いでPocを作った話
 
WordPress の .htaccess って何者?
WordPress の .htaccess って何者?WordPress の .htaccess って何者?
WordPress の .htaccess って何者?
 
とある診断員とAWS
とある診断員とAWSとある診断員とAWS
とある診断員とAWS
 
フリーでやろうぜ!セキュリティチェック!
フリーでやろうぜ!セキュリティチェック!フリーでやろうぜ!セキュリティチェック!
フリーでやろうぜ!セキュリティチェック!
 
Azureを使って手軽にブラウザテストの自動化をはじめよう
Azureを使って手軽にブラウザテストの自動化をはじめようAzureを使って手軽にブラウザテストの自動化をはじめよう
Azureを使って手軽にブラウザテストの自動化をはじめよう
 
Kubernetesを触ってみた
Kubernetesを触ってみたKubernetesを触ってみた
Kubernetesを触ってみた
 

Similar to 優しいWAFの作り方

Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
Hari K T
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
som_nangia
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
wilburlo
 

Similar to 優しいWAFの作り方 (20)

Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
Practical Celery
Practical CeleryPractical Celery
Practical Celery
 
AngularJS Tips&Tricks
AngularJS Tips&TricksAngularJS Tips&Tricks
AngularJS Tips&Tricks
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
Elegant APIs
Elegant APIsElegant APIs
Elegant APIs
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
Quality Use Of Plugin
Quality Use Of PluginQuality Use Of Plugin
Quality Use Of Plugin
 
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
 
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
 
Api Design
Api DesignApi Design
Api Design
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Hooks WCSD12
Hooks WCSD12Hooks WCSD12
Hooks WCSD12
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 

優しいWAFの作り方

  • 1. YAPC::Asia 2009 2009/09/10 dann techmemo@gmail.com Angelos github.com/dann dann
  • 2. Angelos github.com/dann dann
  • 3. Angelos github.com/dann dann
  • 4. Angelos github.com/dann dann
  • 5. Angelos github.com/dann dann
  • 6. request Engine response ( with Plack) miyagawa++, tokuhirom++ Component Dispatcher Manager URL to Controller Component load & search Angelos github.com/dann dann
  • 7. Angelos github.com/dann dann
  • 8. sub build_engine { my $self = shift; my $request_handler = $self->request_handler; $request_handler ||= $self->build_request_handler; return Angelos::PSGI::Engine->new( interface => { Server Gateway module => $self->server, .... }, psgi_handler => $request_handler, ); Server Gateway } psgi handler Angelos github.com/dann dann
  • 9. use Mouse; use Angelos::Types qw( ServerGateway );   has 'interface' => ( Server Gateway     is => 'ro',     isa => ServerGateway,     coerce => 1, ); Server Gateway   psgi handler (coderef) has 'psgi_handler' => ( is => 'rw', );   sub run {     my $self = shift;     $self->interface->run( $self->psgi_handler ); } Angelos github.com/dann dann
  • 10. package Angelos::PSGI::ServerGatewayBuilder; use strict; use warnings; use Plack::Loader; Plack::Loader ServerGateway sub build { my ( $class, $module, $args ) = @_; my $server_gateway = Plack::Loader->load( $module, %{$args} ); $server_gateway; } Angelos github.com/dann dann
  • 11. PSGI env ... WAF Request sub { (with Plack::Request) my $env = shift; my $req = Angelos::Request->new($env); my $res = $self->handle_request($req); my $psgi_res = $self->finalize_response($res); return $psgi_res; } ... PSGI response Angelos github.com/dann dann
  • 12. sub handle_request { req Dsipatcher my ( $self, $req ) = @_; eval { $self->DISPATCH($req); }; if ( my $e = Exception::Class->caught() ) { $self->HANDLE_EXCEPTION($e); } # response return $self->context->res; } Angelos github.com/dann dann
  • 13. request Dispatcher sub DISPATCH { my ( $self, $req ) = @_; dispatch my $dispatch = $self->dispatcher->dispatch($req); ... # dispatch $dispatch->run; # response $c->res; } Angelos github.com/dann dann
  • 14. <URL to Controller> sub dispatch { HTTP::Router request my ( $self, $request ) = @_; route (ikasam_a++) my $match = $self->router->match($request); my $dispatch = $self->dispatch_class->new( match => $match ); return $dispatch; } dispatch Angelos github.com/dann dann
  • 15. # matching controller my $controller = $match->params->{controller}; my $controller_instance = $self- >find_controller_instance( Component Manager { context => $c, Controller controller => $controller, } ); Controller action ... $controller_instance->_dispatch_action( $action, $params ); Angelos github.com/dann dann
  • 16. Angelos github.com/dann dann
  • 17. Angelos github.com/dann dann
  • 18. Angelos github.com/dann dann
  • 19. Angelos github.com/dann dann
  • 20. Angelos github.com/dann dann
  • 21. Angelos github.com/dann dann
  • 22. Angelos github.com/dann dann
  • 23. sub _dispatch_action { my ( $self, $action, $params ) = @_; Hook ... eval { $self->ACTION( $self->context, $action, $params ); }; ... } Angelos github.com/dann dann
  • 24. before 'ACTION' => sub { my ( $self, $c, $action, $params ) = @_; $self->__action_start_time( time() ); }; after 'ACTION' => sub { my ( $self, $c, $action, $params ) = @_; $self->__action_end_time( time() ); my $elapsed = $self->__action_end_time - $self- >__action_start_time; my $message = "action processing time:naction: $action ntime : $elapsed secsn"; $self->log->info($message); }; Angelos github.com/dann dann
  • 25. Angelos github.com/dann dann
  • 26. Angelos github.com/dann dann
  • 27. Angelos github.com/dann dann