2. meta
I’m not a mojolicious expert
I will talk about how to start
I will talk about what to expect
I will hint at how to continue
3. agenda
Mojolicious::Lite
routes and placeholders
templates and layouts
graduating from ::Lite to Mojolicious proper
Mojo as client
4. mojolicious -
what? who?
“real-time web application framework”
written by Sebastian Riedel (sri) &c
who also wrote Catalyst
current core: ams, tempire, mramberg
10. getting started
# GET /
get '/' => sub {
my $self = shift;
$self->render(text => 'Hello');
};
# 200 OK, text/html, Hello
11. placeholder
# /hello/Lars
get '/hello/:name' => sub {
my $self = shift;
my $name = $self->param(‘name’);
$self->render(text => “Hello $name”);
};
# 200 OK, text/html, Hello Lars
12. url parameters
# /hello/Lars?greet=Hej
get '/hello/:name' => sub {
my $self = shift;
my $name = $self->param(‘name’);
my $greet = $self->param(‘greet’);
$self->render(text => “$greet $name”);
} => ‘greeting’;
# 200 OK, text/html, Hej Lars
13. placeholders and routes,
next level
slurpy placeholders
wildcard placeholders
formats (‘.html’, ‘.txt’)
bridging routes
conditional routes
14. stash
nonpresistent data store
keep data for the duration of the request
carries data from action code to template
with a bunch of reserved keys
format, text, template, ...
$self->stash(name => ‘Lars’);
18. template selection
explicit template name in render() call
$self->render(template => ‘hello’);
name in stash
$self->stash(template => ‘hello’);
defaults to name of router
get ‘/welcome’ => ‘hello’;
19. auto render
no need to call render() yourself
if you don’t, mojo will do it for you
get ‘/’ => ‘index’;
__DATA__
@@ index.html.ep
21. templates, next level
includes
partial templates
404, 500 pages
blocks
template inheritance
...
22. sessions
built in
data stored in cookies, client-side
cookie signed to prevent tampering
you can use something else, if you want
23. growing out of ::Lite
inflate inline templates into proper files
move routes into application class
move action code into controller class
testing with Test::Mojo
24. but wait, there’s more!
Mojo::UserAgent
nice web client
Mojo::DOM
excellent HTML/XML parser
ojo
for one-liners