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!
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 ],
];
};
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 :