Skip to content

Instantly share code, notes, and snippets.

@yko
Created December 8, 2010 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yko/733217 to your computer and use it in GitHub Desktop.
Save yko/733217 to your computer and use it in GitHub Desktop.
# This action will render a template
sub welcome {
my $c = shift;
# Set url to current. Change to whatever you want
my $path = $c->url_for('current');
# Create and set up match object
my $m = Mojolicious::Routes::Match->new($c, $path);
# Find $path in routes
$m->match($c->app->routes);
# $m->endpoint now contain endpoint (last matched) route
# if path was successfully matched
# Render template "example/welcome.html.ep" with message
$c->render(message => 'Current route name is: '
. $c->match->endpoint->name
. "\n"
. 'Custom path matched route: '
. ($m->endpoint ? $m->endpoint->name : 'NO MATCH'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment