Your SlideShare is downloading. ×
Schenker - DSL for quickly creating web applications in Perl
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

Schenker - DSL for quickly creating web applications in Perl

2,952

Published on

Yokohama.pm in YAPC::Asia 2009 arrival party …

Yokohama.pm in YAPC::Asia 2009 arrival party
http://yokohama.pm.org/2009/08/yokohamapm-in-yapcasia-2009-1.html

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,952
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
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

Transcript

  • 1. Jiro Nishiguchi( 西口次郎 ) id:spiritloose [email_address] 2009/09/09 Yokohama.pm 出張版 in YAPC::Asia 2009 前夜祭 Schenker a DSL for quickly creating web applications in Perl.
  • 2. $self
    • PAUSE ID: JIRO
    • 3. http://search.cpan.org/~jiro/
    • 4. Image::ObjectDetect
    • 5. Text::Migemo
    • 6. etc...
    • 7. http://d.hatena.ne.jp/spiritloose/
  • 8. What's Schenker?
    • A DSL for quickly creating web applications in Perl
    • 9. Inspired by Ruby's Sinatra
  • 10. What's Sinatra? # myapp.rb require 'sinatra' get '/' do 'hello, world!' end
  • 11. Schenker package MyApp; use Schenker; get '/' => sub { 'hello, world!'; }; どう見てもパク(ry
  • 12. Similar frameworks
    • Mojolicious::Lite
    • 13. http://search.cpan.org/dist/Mojo/
    • 14. Dancer
    • 15. http://search.cpan.org/dist/Dancer/
  • 16. Requirements
    • Schenker
    • 17. -> HTTP::Engine + HTTP::Engine::Middleware
    • 18. (feature Plack + Plack::Middleware)
    • 19. Sinatra
    • 20. -> Rack + Rack::Middleware
  • 21. What's HTTP::Engine? Web Server(Apache, Lighttpd and etc) ↓ HTTP::Engine .= Rack(Ruby) .= WSGI(Python) ↓ Web Application Framework(Catalyst, Rails, Django and etc)
  • 22. SYNOPSIS $ cat > myapp.pl package MyApp; use Schenker; get '/' => sub { 'Hello, world!'; }; $ ./myapp.pl & && firefox http://localhost:4567/
  • 23. Easy!
    • No helpers
    • 24. No configuration
  • 25. Schenker supports
  • 30. Command line options ./myapp.pl --help Usage: ./hoge.pl [OPTIONS] -h, --help display this help -H, --host set the host -p, --port=PORT set the port -e, --environment=ENV set the environment -s, --server=SERVER HTTP::Engine interface === snip ===
  • 31. Configuration configure development => sub { set port => 8080; set host => '127.0.0.1'; set server => 'AnyEvent'; enable 'sessions'; disable 'run'; };
  • 32. Routing get '/' => sub {}; post '/' => sub {}; put '/' => sub {}; Delete '/' => sub {}; get '/' => host => 'example.com' => sub {}; get '/' => agent => qr/MobileSafari/ => sub {};
  • 33. Method override <form action=”/” method=”post”> <input type=”hidden” name=”_method” value=”put” /> post '/' => sub {}; put '/' => sub {};
  • 34. Paramaters get '/' => sub { params->{foo}; param('foo'); };
  • 35. Nested paramaters # index.tt <form action=&quot;./&quot; method=&quot;post&quot;> <input type=&quot;text&quot; name=&quot;entry[title]&quot; /> <textarea name=&quot;entry[body]&quot;></textarea> </form> # myapp.pl params->{entry}; # { title => '', body => '' }
  • 36. Path paramaters get '/user/:user' => sub { my $args = shift; &quot;hello, $args->{user}!&quot;; };
  • 37. Encoding set encode => { encode => 'utf-8', decode => 'utf-8' }; get '/user/:name' => sub { my $args = shift; ok utf8::is_utf8($args->{name}); ok utf8::is_utf8(params->{foo}); };
  • 38. View
    • Template-Toolkit
    • 39. Text::MicroTemplate
  • 40. Template-Toolkit tt_options WRAPPER => 'layout.tt'; get '/tt' => sub { tt 'index'; # views/index.tt };
  • 41. In-file Template get '/' => sub { stash name => 'Michael Schenker'; tt 'index'; }; __END__ @@ index hello, [% name %]!
  • 42. TT with PadWalker get '/hello/:name' => sub { my $args = shift; tt 'index'; }; __END__ @@ index hello, [% args.name %]!
  • 43. Text::MicroTemplate get '/mt' => sub { mt 'index' # views/index.mt };
  • 44. Helpers helper foo => sub { &quot;foo$_[0]&quot;; }; get '/' => sub { foo('bar') }; [% foo('bar') %] <?= foo('bar') ?>
  • 45. Before filters Before sub { stash now => DateTime->now; }; get '/' =>sub { stash->{now}; }; [% now %]
  • 46. Functions get '/' => sub { request; # HTTP::Engine::Request response; # HTTP::Engine::Response status 200; body 'hello, world!'; headers 'X-Hoge' => 'hoge'; back; # Referer };
  • 47. Example: Image File get '/qrcode' => sub { my $text = params->{text}; content_type 'image/png'; GD::Barcode::QRcode->new($text)->plot->png; };
  • 48. Example: Send file get '/' => sub { send_file 'image.jpg'; }; get '/' => sub { send_file 'image.jpg', filename => 'image.jpg'; };
  • 49. Halting get '/' => sub { halt; do_something(); # NOTREACHED }; get '/' => sub { redirect 'http://www.yahoo.co.jp/'; do_something(); # NOTREACHED };
  • 50. Error Handling define_error MyError => sub { status 500; tt 'myerror'; }; get '/' => sub { raise MyError; do_something(); # NOTREACHED };
  • 51. Sessions enable 'sessions'; get '/' => sub { session; # HTTP::Session session->get('foo'); session->set(foo => 'bar'); };
  • 52. Sample Application
    • Rails scaffold like CRUD interface
    • 53. with DBIx::Class
    • 54. http://github.com/spiritloose/schenker-sample/
    • 55. Runs on CGI, FastCGI, mod_perl, AnyEvent, POE...
    • 56. Includes configuration file (eg: httpd.conf)
  • 57. TODO
  • 61. Thanks!
      References
    • http://github.com/spiritloose/Schenker
    • 62. http://www.sinatrarb.com/
    • 63. http://d.hatena.ne.jp/spiritloose/

×