ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Mojolicious
Mojolicious
Catalyst
welcome to dependency hell
Mojolicious
vs
cpan Mojo
only core dependencies
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"
mojolicious generate
 lite_app new_project
[exist] /private/tmp
[write] /private/tmp/new_project
[chmod] new_project 744
./new_project daemon
Yea baby!
where does it come
      from
#!/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>
what is it good for
 why bother - why another framework
extremely quick and
      dirty
     ideal for prototyping
@@ 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>
can scale out
and become nice and clean
some nice features
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};
routing

? get ¡®/foo¡¯ => (agent qr/iPhone/) => sub {
? post ¡®/foo¡¯ => sub { #all treated the same }
? any => sub { #catch all }
? ladder sub { return 1;} #authentication
output format

? $self->render_json($data)
? $self->render_text(¡°Hi there!¡±)
? $self->render(handler => [your handler])
and once you grow out
    of the lite_app
mojolicious in?ate
  new_project
have fun prototyping
Lenz Gschwendtner
    @norbu09

More Related Content

Mojolicious