Schenker - DSL for quickly creating web applications in Perl

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite & 1 Event

    Schenker - DSL for quickly creating web applications in Perl - Presentation 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
      • http://search.cpan.org/~jiro/
      • Image::ObjectDetect
      • Text::Migemo
      • etc...
      • http://d.hatena.ne.jp/spiritloose/
    3. What's Schenker?
      • A DSL for quickly creating web applications in Perl
      • Inspired by Ruby's Sinatra
    4. What's Sinatra? # myapp.rb require 'sinatra' get '/' do 'hello, world!' end
    5. Schenker package MyApp; use Schenker; get '/' => sub { 'hello, world!'; }; どう見てもパク(ry
    6. Similar frameworks
      • Mojolicious::Lite
      • http://search.cpan.org/dist/Mojo/
      • Dancer
      • http://search.cpan.org/dist/Dancer/
    7. Requirements
      • Schenker
      • -> HTTP::Engine + HTTP::Engine::Middleware
      • (feature Plack + Plack::Middleware)
      • Sinatra
      • -> Rack + Rack::Middleware
    8. What's HTTP::Engine? Web Server(Apache, Lighttpd and etc) ↓ HTTP::Engine .= Rack(Ruby) .= WSGI(Python) ↓ Web Application Framework(Catalyst, Rails, Django and etc)
    9. SYNOPSIS $ cat > myapp.pl package MyApp; use Schenker; get '/' => sub { 'Hello, world!'; }; $ ./myapp.pl & && firefox http://localhost:4567/
    10. Easy!
      • No helpers
      • No configuration
    11. Schenker supports
      • Configurations
      • Routing
      • Controller
      • Views
      • No models (use your favorite modules)
    12. 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 ===
    13. Configuration configure development => sub { set port => 8080; set host => '127.0.0.1'; set server => 'AnyEvent'; enable 'sessions'; disable 'run'; };
    14. Routing get '/' => sub {}; post '/' => sub {}; put '/' => sub {}; Delete '/' => sub {}; get '/' => host => 'example.com' => sub {}; get '/' => agent => qr/MobileSafari/ => sub {};
    15. Method override <form action=”/” method=”post”> <input type=”hidden” name=”_method” value=”put” /> post '/' => sub {}; put '/' => sub {};
    16. Paramaters get '/' => sub { params->{foo}; param('foo'); };
    17. 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 => '' }
    18. Path paramaters get '/user/:user' => sub { my $args = shift; &quot;hello, $args->{user}!&quot;; };
    19. 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}); };
    20. View
      • Template-Toolkit
      • Text::MicroTemplate
    21. Template-Toolkit tt_options WRAPPER => 'layout.tt'; get '/tt' => sub { tt 'index'; # views/index.tt };
    22. In-file Template get '/' => sub { stash name => 'Michael Schenker'; tt 'index'; }; __END__ @@ index hello, [% name %]!
    23. TT with PadWalker get '/hello/:name' => sub { my $args = shift; tt 'index'; }; __END__ @@ index hello, [% args.name %]!
    24. Text::MicroTemplate get '/mt' => sub { mt 'index' # views/index.mt };
    25. Helpers helper foo => sub { &quot;foo$_[0]&quot;; }; get '/' => sub { foo('bar') }; [% foo('bar') %] <?= foo('bar') ?>
    26. Before filters Before sub { stash now => DateTime->now; }; get '/' =>sub { stash->{now}; }; [% now %]
    27. Functions get '/' => sub { request; # HTTP::Engine::Request response; # HTTP::Engine::Response status 200; body 'hello, world!'; headers 'X-Hoge' => 'hoge'; back; # Referer };
    28. Example: Image File get '/qrcode' => sub { my $text = params->{text}; content_type 'image/png'; GD::Barcode::QRcode->new($text)->plot->png; };
    29. Example: Send file get '/' => sub { send_file 'image.jpg'; }; get '/' => sub { send_file 'image.jpg', filename => 'image.jpg'; };
    30. Halting get '/' => sub { halt; do_something(); # NOTREACHED }; get '/' => sub { redirect 'http://www.yahoo.co.jp/'; do_something(); # NOTREACHED };
    31. Error Handling define_error MyError => sub { status 500; tt 'myerror'; }; get '/' => sub { raise MyError; do_something(); # NOTREACHED };
    32. Sessions enable 'sessions'; get '/' => sub { session; # HTTP::Session session->get('foo'); session->set(foo => 'bar'); };
    33. Sample Application
      • Rails scaffold like CRUD interface
      • with DBIx::Class
      • http://github.com/spiritloose/schenker-sample/
      • Runs on CGI, FastCGI, mod_perl, AnyEvent, POE...
      • Includes configuration file (eg: httpd.conf)
    34. TODO
      • Release
      • PSGI, Plack
      • Documentation
      • Extending Schenker
    35. Thanks!
        References
      • http://github.com/spiritloose/Schenker
      • http://www.sinatrarb.com/
      • http://d.hatena.ne.jp/spiritloose/
    SlideShare Zeitgeist 2009

    + Jiro NishiguchiJiro Nishiguchi Nominate

    custom

    418 views, 1 favs, 1 embeds more stats

    Yokohama.pm in YAPC::Asia 2009 arrival party
    http:/ more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 418
      • 371 on SlideShare
      • 47 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 1
    Most viewed embeds
    • 47 views on http://d.hatena.ne.jp

    more

    All embeds
    • 47 views on http://d.hatena.ne.jp

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events