SlideShare a Scribd company logo
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)!

More Related Content

What's hot (20)

ODP
PHP Performance SfLive 2010
De Cock Xavier
 
PDF
Modern Getopt for Command Line Processing in Perl
Nova Patch
 
PDF
Perl6 grammars
Andrew Shitov
 
PDF
Get your teeth into Plack
Workhorse Computing
 
PDF
Zend con 2016 - Asynchronous Prorgamming in PHP
Adam Englander
 
PDF
Findbin libs
Workhorse Computing
 
PPT
On UnQLite
charsbar
 
PDF
Metadata-driven Testing
Workhorse Computing
 
PDF
Perl6 in-production
Andrew Shitov
 
PDF
Hypers and Gathers and Takes! Oh my!
Workhorse Computing
 
PDF
Perl web app 테스트전략
Jeen Lee
 
PDF
The $path to knowledge: What little it take to unit-test Perl.
Workhorse Computing
 
PDF
2010 Smith Scripting101
bokonen
 
PDF
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
PDF
Memory Manglement in Raku
Workhorse Computing
 
KEY
Kansai.pm 10周年記念 Plack/PSGI 入門
lestrrat
 
PDF
Git::Hooks
Mikko Koivunalho
 
PDF
YAPC::Brasil 2009, POE
Thiago Rondon
 
PDF
BSDM with BASH: Command Interpolation
Workhorse Computing
 
PDF
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
Adam Englander
 
PHP Performance SfLive 2010
De Cock Xavier
 
Modern Getopt for Command Line Processing in Perl
Nova Patch
 
Perl6 grammars
Andrew Shitov
 
Get your teeth into Plack
Workhorse Computing
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Adam Englander
 
Findbin libs
Workhorse Computing
 
On UnQLite
charsbar
 
Metadata-driven Testing
Workhorse Computing
 
Perl6 in-production
Andrew Shitov
 
Hypers and Gathers and Takes! Oh my!
Workhorse Computing
 
Perl web app 테스트전략
Jeen Lee
 
The $path to knowledge: What little it take to unit-test Perl.
Workhorse Computing
 
2010 Smith Scripting101
bokonen
 
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
Memory Manglement in Raku
Workhorse Computing
 
Kansai.pm 10周年記念 Plack/PSGI 入門
lestrrat
 
Git::Hooks
Mikko Koivunalho
 
YAPC::Brasil 2009, POE
Thiago Rondon
 
BSDM with BASH: Command Interpolation
Workhorse Computing
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
Adam Englander
 

Similar to plackdo, plack-like web interface on perl6 (20)

KEY
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
KEY
Plack - LPW 2009
Tatsuhiko Miyagawa
 
PDF
Perl family: 15 years of Perl 6 and Perl 5
Michal Jurosz
 
PPTX
PSGI and Plack from first principles
Perl Careers
 
KEY
PSGI/Plack OSDC.TW
Tatsuhiko Miyagawa
 
KEY
Le PERL est mort
apeiron
 
KEY
Psgi Plack Sfpm
som_nangia
 
KEY
Psgi Plack Sfpm
wilburlo
 
KEY
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
PDF
Brno Perl Mongers 28.5.2015 - Perl family by mj41
Michal Jurosz
 
KEY
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
ODP
Modern Web Development with Perl
Dave Cross
 
PDF
What's new In Perl?
acme
 
PPT
2016年のPerl (Long version)
charsbar
 
PDF
AnyEvent and Plack
Masahiro Honma
 
PDF
Continuing Evolution of Perl: Highlights of ActivePerl 5.14
ActiveState
 
PDF
24 uses for perl6
Simon Proctor
 
KEY
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
PDF
Кратко о Rakudo
Andrew Shitov
 
PDF
Gazelle - Plack Handler for performance freaks #yokohamapm
Masahiro Nagano
 
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
Plack - LPW 2009
Tatsuhiko Miyagawa
 
Perl family: 15 years of Perl 6 and Perl 5
Michal Jurosz
 
PSGI and Plack from first principles
Perl Careers
 
PSGI/Plack OSDC.TW
Tatsuhiko Miyagawa
 
Le PERL est mort
apeiron
 
Psgi Plack Sfpm
som_nangia
 
Psgi Plack Sfpm
wilburlo
 
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
Brno Perl Mongers 28.5.2015 - Perl family by mj41
Michal Jurosz
 
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
Modern Web Development with Perl
Dave Cross
 
What's new In Perl?
acme
 
2016年のPerl (Long version)
charsbar
 
AnyEvent and Plack
Masahiro Honma
 
Continuing Evolution of Perl: Highlights of ActivePerl 5.14
ActiveState
 
24 uses for perl6
Simon Proctor
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
Кратко о Rakudo
Andrew Shitov
 
Gazelle - Plack Handler for performance freaks #yokohamapm
Masahiro Nagano
 
Ad

plackdo, plack-like web interface on perl6

  • 1. Plackdo or how to play with perl6 Nobuo Danjou , @lopnor
  • 2. Self Introduction • Nobuo Danjou • living in Komaba, Tokyo • Freerance programmer • http://soffritto.org/, @lopnor • This is my Second Time in Taipei!
  • 3. What’s Plackdo? • rough port of Plack to rakudo / perl 6
  • 4. What’s Rakudo? • a perl 6 implementation • http://rakudo.org/ • http://github.com/rakudo
  • 5. 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/
  • 6. What’s PSGI? my $app = sub { my $env = shift; return [ 200, [ ‘Content-Type’ => ‘text/plain’ ], [ ‘Hello World’ ], ]; };
  • 7. Web on perl 6 • some implementations • november (wiki on perl6) • web (plack like interface and template engines) • .... and others
  • 8. 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
  • 9. 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!
  • 10. 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
  • 11. how it works sub (%env) { return [ 200, [ ‘Content-Type’ => ‘text/plain’ ], [ %env.perl ], ]; };
  • 12. PSGI sub { my $env = shift; return [ 200, [ ‘Content-Type’ => ‘text/plain’ ], [ ‘Hello World’ ], ]; };
  • 13. P6SGI sub (%env) { return [ 200, [ ‘Content-Type’ => ‘text/plain’ ], [ %env.perl ], ]; };
  • 14. how it works $ PERL6LIB=blib/lib plackdup
  • 15. how it works demo show codes here
  • 16. sockets • using parrot sockets • rakudo/t/spec/S32-io/IO-Socket-INET.pl • not tested now (it fails)
  • 17. 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 :
  • 18. IO::Socket::INET method bind($host, $port) { $!PIO.bind($!PIO.sockaddr($host, $port)); return self; }
  • 19. 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; }
  • 20. 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 }; }
  • 21. http server • adding http specific codes onto echo server • basically copied from HTTP::Server::PSGI show codes here
  • 22. parsing requests • Plackdo::HTTP::Message • based on HTTP::Message on perl 5 • using grammar on perl 6 show codes here
  • 23. Middlewares • copied from Plack::Middleware • AccessLog • Static • Conditional show codes here
  • 24. testing • Plackdo::Test • forking server inside • mocking http response without forking
  • 25. forking • no forking in rakudo core currently • use zavolaj • multi-platform problem show codes here
  • 26. distributing • ufo • neutro • http://modules.perl6.org/
  • 27. making blog • input • storing entries • html • rss
  • 28. using databases • MiniDBI, MiniDBD::mysql • libmysqlclient via zavolaj, nci
  • 29. using libraries • zavolaj • nci (Native Call Interface) on parrot
  • 30. html building • XML::Writer • building RSS in same way
  • 31. XML::Writer my $html = html => [ head => [ title => [‘my first html’], ], body => [‘hello world’], ]; XML::Writer.serialize($html);
  • 32. rakudo things • rakudo* was released every month (2010) • next rakudo* will be released in April • you can get rakudo (not star) from github
  • 33. parrot things • parrot development is very active • interfaces change so often
  • 34. to adjust to changes • implement core of your apps by your hand • give feedbacks to developer community
  • 35. pir • parrot intermediate representation • pir is fast!
  • 36. pir my $res = Q:PIR { .... };
  • 37. my todo • error handling • Session management • better mysql client (MiniDBD::mysql) • Text::Markdown
  • 38. conclusion • if you want to reinvent wheels, consider do it with rakudo • it will help you understand more deeply your first language.
  • 39. that’s all • Thank you! • PLEASE COME TO JAPAN after the nuclear problem ended (in HAPPY END)!

Editor's Notes