Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created July 1, 2013 19:35
Show Gist options
  • Save brianmed/5903844 to your computer and use it in GitHub Desktop.
Save brianmed/5903844 to your computer and use it in GitHub Desktop.
Programmatically redirect
#!/opt/perl
use Mojolicious::Lite;
# Documentation browser under "/perldoc"
plugin 'PODRenderer';
get '/' => sub {
my $self = shift;
$self->render('index');
};
hook before_dispatch => sub {
my $c = shift;
my $url = $c->req->url->to_abs;
if ($url =~ m/yes/) {
$c->redirect_to("/");
}
};
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'Welcome';
Welcome to the Mojolicious real-time web framework!
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment