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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

plackdo, plack-like web interface on perl6

1,086

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,086
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
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
  • \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
  • Transcript

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

    ×