Last active
August 29, 2015 14:10
-
-
Save Code-Hex/0a03bbf8ad7899ba6e8b to your computer and use it in GitHub Desktop.
Mojolicious::Lite の勉強(基礎から)
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; | |
# Documentation browser under "/perldoc" | |
plugin 'PODRenderer'; | |
get '/' => sub { | |
my $c = shift; | |
$c->stash->{message} = "Hello Mojo!"; | |
$c->stash->{test} = "Test Mojo..."; | |
$c->stash->{count} = "Count Mojo..."; | |
$c->stash(list => ["Potate","Carot","Radish"]); | |
$c->stash->{like} = "I like ..."; | |
$c->stash(array => ["Tomato","Onion","Banana"]); | |
$c->stash->{num} = "Random numbers ..."; | |
$c->stash(number => [0,2,5,3,1,5,6,3,4,2]); | |
$c->render('index'); | |
}; | |
get '/result' => sub { | |
my $c = shift; | |
my $name = $c->req->param('name'); # input の name | |
$c->stash->{name} = $name; | |
$c->render('result'); | |
}; | |
app->start; | |
__DATA__ | |
@@ index.html.ep | |
<!DOCTYPE html> | |
<html> | |
<head><title><%= title %></title></head> | |
<body> | |
<p><%= $message %></p> | |
<p><%= $test %></p> | |
<p><%= $count %></p> | |
<ul> | |
% for my $entry (@$list) { | |
<li><%= $entry %></li> | |
% } | |
</ul> | |
<p><%= $like %></p> | |
% my $cnt = 1; | |
<p> | |
% for my $vegetables (@$array) { | |
<%= $vegetables %> <%= $cnt++ %>, | |
% } | |
</p> | |
<p><%= $num %></p> | |
<p> | |
% for my $nums (@$number) { | |
<%= $nums %> | |
% } | |
</p> | |
<form action='/result'> | |
<input type='text' name='name'> | |
<input type='submit' name='送信'> | |
</form> | |
</body> | |
</html> | |
@@ result.html.ep | |
<!DOCTYPE html> | |
<html> | |
<head><title><%= title %></title></head> | |
<body> | |
<p>You sent message is "<%= $name %>"</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
次はGET POSTやるよー!