Created
September 2, 2010 09:02
-
-
Save memowe/562076 to your computer and use it in GitHub Desktop.
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/env perl | |
use Mojolicious::Lite; | |
use File::Basename; | |
use utf8; | |
plugin charset => {charset => 'utf-8'}; | |
get '/' => 'home'; | |
get '/edit' => 'edit'; | |
post '/edit' => sub { | |
my $self = shift; | |
# update | |
my $name = $self->param('name'); | |
$self->session(name => $name); | |
# message | |
$self->flash( | |
message => "OK, $name!", | |
redirect_url => $self->url_for('home'), | |
); | |
$self->redirect_to('message'); | |
} => 'update'; | |
get '/message' => 'message'; | |
# show sourcecode of this file | |
get '/source' => sub { shift->render_static('../' . basename $0) } => 'source'; | |
app->start; | |
__DATA__ | |
@@ home.html.ep | |
% layout 'default'; | |
% my $name = session('name') // 'Unbekannt'; | |
<h1>Hi <%= $name %>!</h1> | |
<p><a href="<%= url_for 'edit' %>">Namen ändern</a></p> | |
@@ edit.html.ep | |
% layout 'default'; | |
% my $name = session('name') // 'Unbekannt'; | |
<form action="<%= url_for 'update' %>" method="post"> | |
<p> | |
<input type="text" name="name" value="<%= $name %>"> | |
<input type="submit" value="Ändern!"> | |
</p> | |
</form> | |
@@ message.html.ep | |
% layout 'default'; | |
<p><strong><%= flash 'message' %></strong></p> | |
<p><a href="<%= url_for 'home' %>">Start</a></p> | |
@@ layouts/default.html.ep | |
<!doctype html> | |
<html> | |
<head> | |
<title>Ich erkenne Dich wieder!</title> | |
% if (my $url = flash 'redirect_url') { | |
<meta http-equiv="Refresh" content="5; URL=<%= $url %>"> | |
% } | |
</head> | |
<body> | |
%== content | |
<hr><address> | |
© Mirko "memowe" Westermeier – | |
<a href="<%= url_for 'source' %>">Quelltext</a> | |
</address> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment