mojolicious

24
Mojolicious

Upload: lenz-gschwendtner

Post on 12-May-2015

2.866 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mojolicious

Mojolicious

Page 2: Mojolicious
Page 3: Mojolicious

Catalystwelcome to dependency hell

Page 4: Mojolicious
Page 5: Mojolicious

vs

Page 6: Mojolicious

cpan Mojoonly core dependencies

Page 7: Mojolicious

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"

Page 8: Mojolicious

mojolicious generate lite_app new_project

[exist] /private/tmp [write] /private/tmp/new_project [chmod] new_project 744

Page 9: Mojolicious

./new_project daemon

Page 10: Mojolicious

Yea baby!

Page 11: Mojolicious

where does it come from

Page 12: Mojolicious

#!/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>

Page 13: Mojolicious

what is it good forwhy bother - why another framework

Page 14: Mojolicious

extremely quick and dirty

ideal for prototyping

Page 15: Mojolicious

@@ 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>

Page 16: Mojolicious

can scale outand become nice and clean

Page 17: Mojolicious

some nice features

Page 18: Mojolicious

my $client = Mojo::Client->new;

my $url = $couch_user_url."?key="'.$self->session->{'name'}.'"';

my $view = $client->get($url)->success->json->{rows}->[0]->{doc};

query CouchDB

Page 19: Mojolicious

routing

• get ‘/foo’ => (agent qr/iPhone/) => sub {

• post ‘/foo’ => sub { #all treated the same }

• any => sub { #catch all }

• ladder sub { return 1;} #authentication

Page 20: Mojolicious

output format

• $self->render_json($data)

• $self->render_text(“Hi there!”)

• $self->render(handler => [your handler])

Page 21: Mojolicious

and once you grow out of the lite_app

Page 22: Mojolicious

mojolicious inflate new_project

Page 23: Mojolicious

have fun prototyping

Page 24: Mojolicious

Lenz Gschwendtner@norbu09