Created
July 1, 2013 19:35
-
-
Save brianmed/5903844 to your computer and use it in GitHub Desktop.
Programmatically redirect
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
#!/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