The Mojolicious Web Framework ============================= Introduction ------------ * Mojolicious - "the Web in a Box!" - http://mojolicious.org * On CPAN: http://search.cpan.org/dist/Mojolicious/ . * A self-contained web-development framework that only depends on perl 5 and its core modules. * As a result: implements a lot of functionality that exists in many other CPAN distributions in slightly different ways. * Licence: http://opensource.org/licenses/artistic-license-2.0.php[Artistic 2.0] (open-source, mostly BSD-style). Code Examples ------------- ----------------------- # Using Mojolicious::Lite will enable "strict" and "warnings" use Mojolicious::Lite; # Route with placeholder get '/:foo' => sub { my $self = shift; $self->render_text('Yea baby!'); }; # Start the Mojolicious command system shagadelic; ----------------------- More complex example, written by me for Insurgent Software and http://github.com/insurgentsoftware/socialmap/tree/master/dev/mojo-user-auth/[available on github] under a yet undecided open-source licence: ----------------------- #!/usr/bin/env perl use strict; use warnings; use InsurgentSoftware::UserAuth::User; use InsurgentSoftware::UserAuth::App; use Mojolicious::Lite; use MojoX::Session::Cookie; use CGI qw(); use KiokuDB; # Silence app->log->level('error'); my $dir = KiokuDB->connect( "dbi:SQLite:dbname=./insurgent-auth.sqlite", create => 1, columns => [ email => { data_type => "varchar", is_nullable => 1, }, ], ); get '/' => sub { my $self = shift; return $self->render( template => "index", layout => 'insurgent', title => "Main", ); } => "index"; my $app = InsurgentSoftware::UserAuth::App->new( { dir => $dir, } ); my %actions_params = ( 'get' => [ ['/register/', "register",], ['/login/' , "login",], ['/account' , "account_page",], ['/confirm-register' , "confirm_register",], ['/password-reset' , "password_reset",], ['/handle-password-reset' , "handle_password_reset",], ], 'post' => [ ['/register-submit/', "register_submit",], ['/login-submit/' , "login_submit",], ['/account/change-info' , "change_user_info_submit",], ['/password-reset-submit' , "password_reset_submit",], ['/handle-password-reset-submit' , "handle_password_reset_submit",], ], ); while (my ($verb, $actions) = each(%actions_params)) { foreach my $action (@$actions) { my ($url, $action_name) = @$action; __PACKAGE__->can($verb)->( $url => sub { my $controller = shift; return $app->with_mojo($controller, $action_name); } => $action_name ); } } sub logout { my $self = shift; delete($self->session->{'login'}); $self->render_text( "
The form below allows you to reset your password. Please enter the E-mail with which you registered.
<%== $password_reset_form %> @@ handle_password_reset.html.ep % layout 'insurgent';The form below allows you to reset your password. Please enter your new password.
<%== $handle_password_reset_form %> @@ layouts/insurgent.html.ep