Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mojolicious

3,335 views

Published on

  • Be the first to comment

Mojolicious

  1. 1. Mojolicious
  2. 2. Catalyst welcome to dependency hell
  3. 3. vs
  4. 4. cpan Mojo only core dependencies
  5. 5. catalyst.pl new_project created "new_project" created "new_project/script" created "new_project/lib" [ snip ] created "new_project/script/new_project_server.pl" created "new_project/script/new_project_test.pl" created "new_project/script/new_project_create.pl"
  6. 6. mojolicious generate lite_app new_project [exist] /private/tmp [write] /private/tmp/new_project [chmod] new_project 744
  7. 7. ./new_project daemon
  8. 8. Yea baby!
  9. 9. where does it come from
  10. 10. #!/usr/bin/env perl use Mojolicious::Lite; get '/' => 'index'; get '/:groovy' => sub { my $self = shift; $self->render_text($self->param('groovy'), layout => 'funky'); }; app->start; __DATA__ @@ index.html.ep % layout 'funky'; Yea baby! @@ layouts/funky.html.ep <!doctype html><html> <head><title>Funky!</title></head> <body><%== content %></body> </html>
  11. 11. what is it good for why bother - why another framework
  12. 12. extremely quick and dirty ideal for prototyping
  13. 13. @@ index.html.ep <!doctype html><html> <head><title>EPP test client</title></head> <body> % if ($result) { <h2>EPP greeting</h2> <pre> <%= $greet %> </pre> <h2>EPP command results</h2> % foreach my $res (@{$result->{results}}) { <pre> <%= $res %> </pre> % } % } <form method="post"> <textarea rows="20" cols="40" name="command"> <%= $command %> </textarea> <br /> <input type="submit" name="submit" value="send command" /> </form> </body> </html>
  14. 14. can scale out and become nice and clean
  15. 15. some nice features
  16. 16. query CouchDB my $client = Mojo::Client->new; my $url = $couch_user_url. "?key="'.$self->session->{'name'}.'"'; my $view = $client->get($url)->success->json->{rows}->[0]-> {doc};
  17. 17. routing • get ‘/foo’ => (agent qr/iPhone/) => sub { • post ‘/foo’ => sub { #all treated the same } • any => sub { #catch all } • ladder sub { return 1;} #authentication
  18. 18. output format • $self->render_json($data) • $self->render_text(“Hi there!”) • $self->render(handler => [your handler])
  19. 19. and once you grow out of the lite_app
  20. 20. mojolicious inflate new_project
  21. 21. have fun prototyping
  22. 22. Lenz Gschwendtner @norbu09

×