By setting the MOJO_RELOAD environment variable you can just live edit every single file, web application development has never been this simple.$ cpanp install Mojo ... no prereqs needed, so installation will be very fast ... $ mojolicious generate app MyMojoliciousApp [mkdir] /Users/sri/my_mojolicious_app/bin [write] /Users/sri/my_mojolicious_app/bin/mojolicious [chmod] my_mojolicious_app/bin/mojolicious 744 [mkdir] /Users/sri/my_mojolicious_app/lib [write] /Users/sri/my_mojolicious_app/lib/MyMojoliciousApp.pm [mkdir] /Users/sri/my_mojolicious_app/lib/MyMojoliciousApp [write] /Users/sri/my_mojolicious_app/lib/MyMojoliciousApp/Example.p +m [mkdir] /Users/sri/my_mojolicious_app/t [write] /Users/sri/my_mojolicious_app/t/basic.t [mkdir] /Users/sri/my_mojolicious_app/public [write] /Users/sri/my_mojolicious_app/public/404.html [exist] /Users/sri/my_mojolicious_app/public [write] /Users/sri/my_mojolicious_app/public/index.html [mkdir] /Users/sri/my_mojolicious_app/templates/example [write] /Users/sri/my_mojolicious_app/templates/example/welcome.phtm +l $ cd my_mojolicious_app $ bin/mojolicious daemon Server available at http://127.0.0.1:3000.
Unlinke other frameworks Mojolicious won't try to hide the dispatcher logic from you.$ MOJO_RELOAD=1 bin/mojolicious daemon Server available at http://127.0.0.1:3000.
Controllers are plain old Perl classes without any magic.package MyMojoliciousApp; use strict; use warnings; use base 'Mojolicious'; # This method will run for each request sub dispatch { my ($self, $c) = @_; # Try to find a static file $self->static->dispatch($c); # Use routes if we don't have a response code yet $self->routes->dispatch($c) unless $c->res->code; # Nothing found unless ($c->res->code) { $self->static->serve($c, '/404.html'); $c->res->code(404); } } # This method will run once at server start sub startup { my $self = shift; # The routes my $r = $self->routes; # Default route $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1); } 1;
By default Mojo::Template (also known as "phtml") will be used to render templates.package MyMojoliciousApp::Example; use strict; use warnings; use base 'Mojolicious::Controller'; # This is a templateless action sub test { my ($self, $c) = @_; # Response object my $res = $c->res; # Code $res->code(200); # Headers $res->headers->content_type('text/html'); # Content my $url = $c->url_for; $url->path->parse('/index.html'); $res->body(qq/<a href="$url">Forward to a static document.<\/a>/); } # This action will render a template sub welcome { my ($self, $c) = @_; # Render the template $c->render; } 1;
Mojo itself also got some big updates, here's the complete changelog.% my $c = shift; <h2>Welcome to the Mojolicious Web Framework!</h2> This page was generated from a template at templates/example/test.phtm +l, <a href="<%= $c->url_for(action => 'test') %>">click here</a> to move forward to a templateless action.
- Added the Mojolicious Web Framework example.Like what you see here? Now would be the perfect time to get involved in the project!
- Added upload and GET/POST parameter helpers to Mojo::Message.
- Hooks for upload progress and stuff added.
- Refactored transfer encoding code into Mojo::Filter and Mojo::Filter::Chunked.
- Added callbacks for start line and header generators.
- Added workaround for missing IO::Seekable support in older versions of File::Temp (Perl 5.8).
- script/mojo.pl got renamed to bin/mojo.
- Mojo::Cache got renamed to Mojo::File because there will be a cache module named MojoX::Cache, and that could cause confusion later on.
- Fixed many escaping related bugs around Mojo::URL.
- Fixed 100-Continue support in Mojo::Server::Daemon and Mojo::Client.
- Countless small bugs fixed and tests added.
In reply to Mojo 0.7 released (Perl on Rails in 150 lines of code) by sri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |