Kansai.pm 10周年記念 Plack/PSGI 入門
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Kansai.pm 10周年記念 Plack/PSGI 入門

on

  • 10,426 views

 

Statistics

Views

Total Views
10,426
Views on SlideShare
10,354
Embed Views
72

Actions

Likes
10
Downloads
65
Comments
0

5 Embeds 72

http://www.slideshare.net 59
http://a0.twimg.com 7
http://us-w1.rockmelt.com 3
http://www.iweb34.com 2
http://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Kansai.pm 10周年記念 Plack/PSGI 入門 Presentation Transcript

  • 1. CGI mod_perl Catalyst FastCGI standalone CGI mod_perl Jifty FastCGI standalone
  • 2. Catalyst CGI mod_perl PSGI Adaptor FastCGI standalone Jifty
  • 3. use strict; sub psgi_app {     my $env = shift;     return [         200,         [ "Content-Type" => "text/plain" ],         [ "Hello, ", "World!" ]     ]; } # .psgi &psgi_app;
  • 4. use strict; use File::Spec; sub psgi_app {     my $env = shift;     my $path = File::Spec->catfile( "/path/to/docs", $env->{PATH_INFO} );     if (-f $path) { my $fh;         if (! open( $fh, '<', $path ) ) {             return [                 500, [ "Content-Type" => "text/plain" ], [ "Server Error" ]             ];         }         return [ 200, [ "Content-Type" => "text/plain" ], $fh ];     } else {         return [ 404, [ "Content-Type" => "text/plain" ], [ "File not found" ] ];     } } # .psgi &psgi_app;
  • 5. > plackup -a myapp.psgi HTTP::Server::PSGI: Accepting connections at http:// 0:5000/
  • 6. > plackup -a myapp.psgi -s HANDLER
  • 7. > plackup -a myapp.psgi -E ENV
  • 8. > plackup -a myapp.psgi -S /path/to/socket
  • 9. > plackup -e “sub { ... }” -I/path/to/lib -MModuleName
  • 10. # Apache2 <Location /> SetHandler perl-script PerlResponseHandler Plack::Handler::Apache2 PerlSetVar psgi_app /path/to/app.psgi </Location>
  • 11. # Run as a standalone daemon plackup -s FCGI --listen /tmp/fcgi.sock --daemonize --nproc 10
  • 12. #!/usr/bin/env plackup ... CGI code ...
  • 13. # myapp.psgi use strict; use Plack::Middleware::Foo; use Plack::Middleware::Bar; use Plack::Middleware::Baz; my $app = sub { ... }; $app = Plack::Middlewre::Foo->wrap($app); $app = Plack::Middlewre::Bar->wrap($app); $app = Plack::Middlewre::Baz->wrap($app); $app;
  • 14. # myapp.psgi use strict; use Plack::Middleware::Foo; use Plack::Middleware::Bar; use Plack::Middleware::Baz; my $app = sub { ... }; $app = Plack::Middlewre::Foo->wrap($app); $app = Plack::Middlewre::Bar->wrap($app); $app = Plack::Middlewre::Baz->wrap($app); $app;
  • 15. # myapp.psgi use strict; use Plack::Builder; builder {     enable "Foo";     enable "Bar";     enable "Bar";     sub { [ 200, [ "Content-Type" => "text/plain" ], [ "Hello World" ] }; };
  • 16. #!/usr/bin/env perl use strict; use warnings; use MyApp; MyApp->setup_engine('PSGI'); my $app = sub { MyApp->run(@_) };
  • 17. use strict; use AnyEvent; sub {     my $env = shift;     #     return sub {         my $start_response = shift;         my $writer = $start_response->([ 200, [ "Content-Type" => "text/plain" ] ]);         my $count = 1;         my $w; $w = AE::timer 1, 10, sub {             $writer->write( "Timer $countn" );             if ($count++ > 10) {                 undef $w;             }         };     } }
  • 18. Q4M App client client client client
  • 19. Event Server Q4M App client client client client
  • 20. use strict; use Plack::Request; sub {     my $env = shift;     my $req = Plack::Request->new( $env );     my $path = $req->path_info;     my $param = $req->parma('param');     my $res = $req->new_response( 200 );     return $res->finalize(); };
  • 21. accept app listen spawn
  • 22. accept app listen spawn
  • 23. accept app listen spawn accept app
  • 24. accept app listen spawn accept app
  • 25. listen spawn accept app
  • 26. start_server --port=80 plackup -a myapp.psgi -s Starman
  • 27. /var/lib/mycompany/sitename.mycompany.com/MyApp /etc/service/sitename.mycompany.com run ( MyApp/deploy/run config.yaml env/ logs
  • 28. AppX lib extlib Catalyst 5.7 AppY lib extlib Catalyst 5.8
  • 29. cpanm --installdeps --local-lib-contained=extlib .
  • 30. http://github.com/lestrrat/daemontools-plack-runner
  • 31. daemontools Server::Starter perl extlib plackup myapp.psgi Framework