Skip to content

Instantly share code, notes, and snippets.

@sharifulin
Created December 22, 2009 15:56
Show Gist options
  • Save sharifulin/261811 to your computer and use it in GitHub Desktop.
Save sharifulin/261811 to your computer and use it in GitHub Desktop.
The Mojolicious example of routes (simple CRUD model)
#!/usr/bin/perl
use common::sense;
use lib '../lib';
$ENV{MOJO_APP} ||= 'App';
use Mojolicious::Commands; Mojolicious::Commands->start;
package App;
use common::sense;
use base 'Mojolicious';
sub startup {
my $self = shift;
my $r = $self->routes;
$r->route('/')->to('test#list');
$r->route('/open')->via('post')->to('test#open');
$r->route('/view/:id', id => qr/\d+/)->via('get')->to('test#view' );
$r->route('/close/:id', id => qr/\d+/)->via('get')->to('test#close');
}
package App::Test;
use common::sense;
use base 'Mojolicious::Controller';
sub list { shift->render_text('List') }
sub open { shift->render_text('Open') }
sub view { my $self = shift; $self->render_text('View ' . $self->stash('id')) }
sub close { my $self = shift; $self->render_text('Close ' . $self->stash('id')) }
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment