plackdo, plack-like web interface on perl6
Upcoming SlideShare
Loading in...5
×
 

plackdo, plack-like web interface on perl6

on

  • 1,247 views

 

Statistics

Views

Total Views
1,247
Views on SlideShare
1,247
Embed Views
0

Actions

Likes
1
Downloads
10
Comments
0

0 Embeds 0

No embeds

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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

plackdo, plack-like web interface on perl6 plackdo, plack-like web interface on perl6 Presentation Transcript

  • Plackdo orhow 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 workssub (%env) { return [ 200, [ ‘Content-Type’ => ‘text/plain’ ], [ %env.perl ], ]; };
  • PSGIsub { my $env = shift; return [ 200, [ ‘Content-Type’ => ‘text/plain’ ], [ ‘Hello World’ ], ]; };
  • P6SGIsub (%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 perl6use v6;# constantssub 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::INETmethod bind($host, $port) { $!PIO.bind($!PIO.sockaddr($host, $port)); return self;}
  • Plackdo::Socketmethod 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::Socketmethod 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::Writermy $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!
  • pirmy $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)!