It looks like you generated a Mojo app, but added a Mojolicious::Lite
function to the my_mojo_app.pm file.
This won't work. a Mojo app also doesn't understand templates.
What you want is to generate an application skeleton with the
mojolicious command, either
mojolicious generate app
or
mojolicious generate lite-app (probably this)
There are 3 flavors of apps that can be generated by the commands in
this module:
1 - A Mojo app - you have a single "handler" function that gets a
Mojo::Transaction object; this is pretty low-level, and you work
directly with the HTTP objects - no template logic is built in, but it
does give you a script that can run as a daemon, FastCGI or CGI script.
Don't use this.
2 - a Mojolicious app - Mojolicious is a higher-level (M)VC framework
built on top of Mojo; it has conventions for template rendering and
serving static files (from a directory called "static" by default, or it
can be configured), and other niceties. It
3 - a Mojolicious::Lite app - Mojolicious::Lite provides a layer of
syntactic sugar on top of Mojolicious that is ideal for writing
single-file scripts, but still lets you access all the power of the
Mojolicious framework. It allows you to use syntax like:
'/' => sub {
my $self = shift;
$self->render('index');
}
The mojo command generates the first kind, the mojolicious command
generates the 2 other kinds.
- Dotan
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
--
Sebastian Riedel
http://blog.kraih.com
http://mojolicious.org
http://twitter.com/kraih
> If I put my lite app in the root folder, then templates and public
> works, so it seems solved my problem (but I am not sure if this is the
> correct way to do it).
actually - yep. That's one way to do it :)
If you are playing around with Mojolicious you should start with
Mojolicious::Lite.
Let's walk through a small example:
rhaen@deploy:~/example$ mojolicious generate lite_app hello_world.pl
[exist] /home/rhaen/example
[write] /home/rhaen/example/hello_world.pl
[chmod] hello_world.pl 744
Now you have a basic application which is ready to serve webpages. You
can fire up a webserver by running the command:
./hello_world.pl daemon
Wohoo - you can access your webserver at http://localhost:3000
Now let's have a small look inside the file "hello_world.pl"
-----------8<--------------code snippet------------8<--------
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => 'index';
[...]
@@ layouts/funky.html.ep
<!doctype html><html>
<head><title>Funky!</title></head>
<body><%== content %></body>
</html>
-----------8<--------------code snippet------------8<--------
there are some templates included already. Change them, start the
server again and see how the content of the templates can be changed
easily! You can inflate the templates into a structure - the
./hello_world.pl command will handle this for you.
rhaen@deploy:~/works$ ./hello_world.pl inflate
[mkdir] /home/rhaen/works/templates/layouts
[write] /home/rhaen/works/templates/layouts/funky.html.ep
[exist] /home/rhaen/works/templates
[write] /home/rhaen/works/templates/index.html.ep
Voila - now you have the template structure you were looking for! The
inflated files will be served before the files inside the __DATA__
section. So if you want to change your index.html.ep - please do that
inside the filesystem.
Now you have enough to get started. Visit the wiki pages of the
project (http://github.com/kraih/mojo/wiki) and try the existing
guides.
Have fun!
--
Ulrich Habel
blog: http://blog.pkgbox.org
home: http://www.pkgbox.org