Your SlideShare is downloading. ×
  • Like
Kansai.pm 10周年記念 Plack/PSGI 入門
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

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

  • 8,737 views
Published

 

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

Views

Total Views
8,737
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
65
Comments
0
Likes
10

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 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