SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Plackdo
         or
how to play with perl6
     Nobuo Danjou , @lopnor
Self Introduction

• Nobuo Danjou
• living in Komaba, Tokyo
• Freerance programmer
• http://soffritto.org/, @lopnor
• This is my Second Time in Taipei!
What’s Plackdo?


• rough port of Plack to rakudo / perl 6
What’s Rakudo?

• a perl 6 implementation
• http://rakudo.org/
• http://github.com/rakudo
What’s Plack?
• «PSGI is an interface between Perl
  web applications and web servers,
  and Plack is a Perl module and
  toolkit that contains PSGI
  middleware, helpers and adapters
  to web servers.»
  http://plackperl.org/
What’s PSGI?
my $app = sub {
   my $env = shift;
   return [
      200,
      [ ‘Content-Type’ => ‘text/plain’ ],
      [ ‘Hello World’ ],
   ];
};
Web on perl 6

• some implementations
• november (wiki on perl6)
• web (plack like interface and template
  engines)
• .... and others
Why Plack to Perl 6?

• to learn perl 6
• you can be the EARLY ADAPTER NOW!
• you need some playground
• making web application is good playground
Why this talk?

• YAPC::Asia every year
• perl 6 talks every year
• but did nothing every year!
• rakudo star released!
• you can easily start now!
plackdo history

• start thinking about it in Sep
  2010(YAPC::Asia)
• started implementation in Nov 2010
  (Siberian Railway)
• ported my blog to plackdo in Jan 2011
how it works
sub (%env) {
    return [
       200,
       [ ‘Content-Type’ => ‘text/plain’ ],
       [ %env.perl ],
    ];
 };
PSGI
sub {
    my $env = shift;
    return [
       200,
       [ ‘Content-Type’ => ‘text/plain’ ],
       [ ‘Hello World’ ],
    ];
 };
P6SGI
sub (%env) {
    return [
       200,
       [ ‘Content-Type’ => ‘text/plain’ ],
       [ %env.perl ],
    ];
 };
how it works


$ PERL6LIB=blib/lib plackdup
how it works


     demo

               show codes here
sockets

• using parrot sockets
• rakudo/t/spec/S32-io/IO-Socket-INET.pl
 • not tested now (it fails)
echo server
#!/usr/bin/env perl6
use v6;

# constants
sub PF_INET {2}
sub SOCK_STREAM {1}
sub TCP {6}

sub MAIN ($port = '5000', :$host = '0.0.0.0') {
  my $server = IO::Socket::INET.socket( PF_INET, SOCK_STREAM,
TCP );
  $server.bind($host, $port);
  $server.listen;
  while my $conn = $server.accept {
     while my $str = $conn.recv {
       $conn.send($str);
     }
     $conn.close;
  }
  $server.close;
}

# vim: ft=perl6 :
IO::Socket::INET

method bind($host, $port) {
  $!PIO.bind($!PIO.sockaddr($host, $port));
  return self;
}
Plackdo::Socket
method bind(Str $host, Int $port) {
  my $sockaddr = self.sockaddr($host, $port);
  my $status = 0;

    try {
       $!PIO.bind(pir::descalarref__PP($sockaddr));
       CATCH {
          default { $status = 1; }
       }
    }
    return $status;
}
Plackdo::Socket
method sockaddr(Str $host, Int $port) {
  Q:PIR {
     .local pmc self, pio, host, port, sockaddr
     self = find_lex 'self'
     pio = getattribute self, '$!PIO'
     host = find_lex '$host'
     port = find_lex '$port'
     sockaddr = pio.'sockaddr'(host, port)
     %r = sockaddr
  };
}
http server


• adding http specific codes onto echo server
• basically copied from HTTP::Server::PSGI
                                   show codes here
parsing requests

• Plackdo::HTTP::Message
• based on HTTP::Message on perl 5
• using grammar on perl 6   show codes here
Middlewares

• copied from Plack::Middleware
• AccessLog
• Static
• Conditional                     show codes here
testing

• Plackdo::Test
 • forking server inside
 • mocking http response without forking
forking

• no forking in rakudo core currently
• use zavolaj
• multi-platform problem        show codes here
distributing

• ufo
• neutro
• http://modules.perl6.org/
making blog

• input
• storing entries
• html
• rss
using databases


• MiniDBI, MiniDBD::mysql
• libmysqlclient via zavolaj, nci
using libraries


• zavolaj
• nci (Native Call Interface) on parrot
html building


• XML::Writer
• building RSS in same way
XML::Writer
my $html = html => [
   head => [
      title => [‘my first html’],
   ],
   body => [‘hello world’],
];
XML::Writer.serialize($html);
rakudo things

• rakudo* was released every month (2010)
• next rakudo* will be released in April
• you can get rakudo (not star) from github
parrot things


• parrot development is very active
• interfaces change so often
to adjust to changes


• implement core of your apps by your hand
• give feedbacks to developer community
pir


• parrot intermediate representation
• pir is fast!
pir


my $res = Q:PIR {
   ....
};
my todo

• error handling
• Session management
• better mysql client (MiniDBD::mysql)
• Text::Markdown
conclusion

• if you want to reinvent wheels,
  consider do it with rakudo
• it will help you understand more deeply
  your first language.
that’s all


• Thank you!
• PLEASE COME TO JAPAN after the
  nuclear problem ended (in HAPPY END)!

Weitere ähnliche Inhalte

Was ist angesagt?

PHP Performance SfLive 2010
PHP Performance SfLive 2010PHP Performance SfLive 2010
PHP Performance SfLive 2010De Cock Xavier
 
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlNova Patch
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPAdam Englander
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLitecharsbar
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 
Perl web app 테스트전략
Perl web app 테스트전략Perl web app 테스트전략
Perl web app 테스트전략Jeen Lee
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.Workhorse Computing
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101bokonen
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationWorkhorse Computing
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門lestrrat
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEThiago Rondon
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPAdam Englander
 

Was ist angesagt? (20)

PHP Performance SfLive 2010
PHP Performance SfLive 2010PHP Performance SfLive 2010
PHP Performance SfLive 2010
 
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHP
 
Findbin libs
Findbin libsFindbin libs
Findbin libs
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
Perl web app 테스트전략
Perl web app 테스트전략Perl web app 테스트전략
Perl web app 테스트전략
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 
Git::Hooks
Git::HooksGit::Hooks
Git::Hooks
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POE
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
 

Ähnlich wie plackdo, plack-like web interface on perl6

Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Junichi Ishida
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2http403
 
Node js quick tour v2
Node js quick tour v2Node js quick tour v2
Node js quick tour v2Wyatt Fang
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2tianyi5212222
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversTatsuhiko Miyagawa
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Alberto Perdomo
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsDerek Anderson
 
Ruby プログラマのための Perl ウェブアプリケーション開発入門 (Perl web development guide for Rubyist )
Ruby プログラマのための Perl ウェブアプリケーション開発入門 (Perl web development guide for Rubyist )  Ruby プログラマのための Perl ウェブアプリケーション開発入門 (Perl web development guide for Rubyist )
Ruby プログラマのための Perl ウェブアプリケーション開発入門 (Perl web development guide for Rubyist ) Kensuke Nagae
 
How to Begin Developing Ruby Core
How to Begin Developing Ruby CoreHow to Begin Developing Ruby Core
How to Begin Developing Ruby CoreHiroshi SHIBATA
 
How to Begin to Develop Ruby Core
How to Begin to Develop Ruby CoreHow to Begin to Develop Ruby Core
How to Begin to Develop Ruby CoreHiroshi SHIBATA
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?Inada Naoki
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment Evaldo Felipe
 

Ähnlich wie plackdo, plack-like web interface on perl6 (20)

PSGI/Plack OSDC.TW
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
About Clack
About ClackAbout Clack
About Clack
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2
 
Node js quick tour v2
Node js quick tour v2Node js quick tour v2
Node js quick tour v2
 
Node js quick-tour_v2
Node js quick-tour_v2Node js quick-tour_v2
Node js quick-tour_v2
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCats
 
Ruby プログラマのための Perl ウェブアプリケーション開発入門 (Perl web development guide for Rubyist )
Ruby プログラマのための Perl ウェブアプリケーション開発入門 (Perl web development guide for Rubyist )  Ruby プログラマのための Perl ウェブアプリケーション開発入門 (Perl web development guide for Rubyist )
Ruby プログラマのための Perl ウェブアプリケーション開発入門 (Perl web development guide for Rubyist )
 
How to Begin Developing Ruby Core
How to Begin Developing Ruby CoreHow to Begin Developing Ruby Core
How to Begin Developing Ruby Core
 
How to Begin to Develop Ruby Core
How to Begin to Develop Ruby CoreHow to Begin to Develop Ruby Core
How to Begin to Develop Ruby Core
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 

plackdo, plack-like web interface on perl6

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n