Created
June 8, 2011 16:20
-
-
Save Akron/1014751 to your computer and use it in GitHub Desktop.
Sample Mojo-App with route-Shortcut
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
package Mojolicious::Plugin::Test; | |
use Mojo::Base 'Mojolicious::Plugin'; | |
sub register { | |
my ($plugin, $mojo) = @_; | |
$mojo->routes->add_shortcut( | |
'test' => sub { | |
my $route = shift; | |
$route->name('test'); | |
# What are the wildcards? | |
$route->to( | |
cb => sub { | |
my $c = shift; | |
$c->render_data( | |
'Yeah ... '. | |
$c->url_for('test')->to_abs . | |
' vs '. | |
$c->url_for('current')->to_abs | |
); | |
} | |
); | |
} | |
); | |
}; | |
package Application; | |
use Mojo::Base 'Mojolicious'; | |
sub startup { | |
my $mojo = shift; | |
$mojo->plugin('test'); | |
my $r = $mojo->routes; | |
$r->route('/:user/:foo/')->test; | |
}; | |
package main; | |
Application->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment