Created
December 22, 2009 15:56
-
-
Save sharifulin/261811 to your computer and use it in GitHub Desktop.
The Mojolicious example of routes (simple CRUD model)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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