Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mojoliciousでつくる! Webアプリ入門
Search
Yusuke Wada
May 07, 2023
Programming
0
450
Mojoliciousでつくる! Webアプリ入門
2013/09/21
YAPC::Asia 2013
Yusuke Wada a.k.a. yusukebe
Yusuke Wada
May 07, 2023
Tweet
Share
More Decks by Yusuke Wada
See All by Yusuke Wada
MCP with Cloudflare Workers
yusukebe
2
310
Remix on Hono on Cloudflare Workers
yusukebe
3
490
僕がつくった48個のWebサービス達
yusukebe
21
18k
Honoの来た道とこれから
yusukebe
20
4.9k
JS RPCを理解する
yusukebe
5
760
Honoとhtmx
yusukebe
6
1.9k
Cloudflare Workersの環境を再現することについて
yusukebe
7
1k
Hono v4
yusukebe
11
5.1k
Hono v3 and v4
yusukebe
4
4k
Other Decks in Programming
See All in Programming
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
0
110
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
3
3k
Flatt Security XSS Challenge 解答・解説
flatt_security
0
790
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
240
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.8k
Rubyでつくるパケットキャプチャツール
ydah
0
260
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
Linux && Docker 研修/Linux && Docker training
forrep
14
2.7k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
ASP.NET Core の OpenAPIサポート
h455h1
0
140
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
650
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
13k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
980
Making the Leap to Tech Lead
cromwellryan
133
9k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Docker and Python
trallard
43
3.2k
The World Runs on Bad Software
bkeepers
PRO
66
11k
Optimizing for Happiness
mojombo
376
70k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Transcript
.PKPMJDJPVTͰͭ͘Δʂ 8FCΞϓϦೖ :"1$"TJB :VTVLF8BEBBLBZVTVLFCF Some papix photos are in
this slides. Thanks to papix!
ΠϯτϩμΫγϣϯ
ࣗݾհ w ా༟հੜ w ܚጯٛक़େ੍ֶ࡞ϝσΟΞݚڀՊमྃ w גࣜձࣾϫσΟοτදऔక w גࣜձࣾΦϞϩΩऔక݉࠷ߴٕज़ऀ w
IUUQZVTVLFCFDPNPS!ZVTVLFCF
ϝΠϯϫʔΫ
͍͔͚
1FSMେن8FCαʔϏε ͰΘΕ͍ͯΔ͕ ॳ৺ऀ͕8FCΞϓϦʹೖ͢Δࢿྉ͕গͳ͍ʁ
͋͑ͯڈΛৼΓฦΔ ʮ৽͍͠ʯΛੜΈग़ͨ͢Ίͷ8FCΞϓϦ։ൃͱͦͷपล
ԿΛͭ͘Δ͔͔ͬͨ ͦͷͨΊͷ ࣮ʹ͍ͭͯ ຊͷओ
ରΦʔσΟΤϯε w 8FCΞϓϦέʔγϣϯΛͭ͘Γ͍ͨํ w ΞΠσΞ͋Δ͕࣮Ͱ͖ͳ͍ͬͯํ w ࠷ۙͷ8"'ʹ͍ͭͯΓ͍ͨํ w 8FC"QQMJDBUJPO'SBNFXPSL8"' w
.PKPMJDJPVTΛͬͨ۩ମతͳΞϓϦߏΛ Γ͍ͨํ
ํ ͨΓલʹ͍ͬͯΔ֓೦ɺ࣮ɺΩʔϫʔυ טΈࡅ͍ͯղઆ (PPHMF$1"/ͰݕࡧͰ͖ΔΑ͏ʹʂ ࣮͘͢͝पล͔Β͔Γʹ͍͘ʁ
ΞδΣϯμ w ྫɿ͍ΞϓϦʹ͍ͭͯ w 8FCΞϓϦέʔγϣϯͱ'SBNFXPSL w .PKPMJDJPVTͷհ w .PKPMJDJPVT-JUFΛ͏ w
ΑΓ࣮ફతͳΞϓϦ w $1"/ϞδϡʔϧͱͷΈ߹Θͤͱ w ࠓޙ
ྫɿ͍ΞϓϦʹ͍ͭͯ
໊લʹԠ͍ͯ݁͡ՌΛग़͢ w ͍݁Ռ·ͣछྨ w ྑ͍ࣄ͕ى͜ΔͰ͠ΐ͏ w ग़ձ͍͕͋Δ͔ʁ w ෆʹͳΓ·͢ w
ೖྗ͞Ε໊ͨલʹରͯ͠ඞͣಉ݁͡Ռ w ZVTVLFCFʮग़ձ͍͕͋Δ͔ʁʯ
ϋογϡؔ my $name = "yusukebe"; my $max = 3; my
$number = 0; # จࣈྻΛҰจࣈͣͭղ for my $char (split //, $name) { # จࣈʹରԠ͢ΔΛಘΔ $number += ord $char; } # ఆ͞ΕΔ࠷େͰׂͬͨ༨ΓΛಘΔ my $result = $number % $max; print "$result\n"; จࣈྻ ݻఆͰׂΔ ༨Γ͕݁Ռ
εΫϦϓτͰ࣮ݱ͢Δ Α͏அϝ˓ΧʔΈ͍ͨͳʁ
8FCΞϓϦέʔγϣϯͱ'SBNFXPSL
8FCΞϓϦέʔγϣϯΛఆٛ͢Δ 8FC͕୭͔ͱಛతͳ ΠϯλϥΫγϣϯ Λ͢Δ߹ 8FCΞϓϦέʔγϣϯ
8FCͷΠϯλϥΫγϣϯ 8FC ΞϓϦέʔγϣϯ Ϣʔβʔ ྫ͑ࣗͷ໊લΛ ೖྗ͢Δ ͍ͷ݁ՌΛݟΔ +4ͷಈ࡞ ֎෦ͷ8FC"1* ϛυϧΣΞFUD
ϒϥβ ϓϩάϥϜ εϚϗΞϓϦ
8FC"QQMJDBUJPO'SBNFXPSL w ௨শ8"'ʢϫοϑʣ w ྫ͑3VCZPO3BJMT w 8FCΞϓϦέʔγϣϯΛͭ͘ΔͨΊͷ w .7$Ϟσϧʹجͮ͘߹͕ଟ͍ .7$ͬͯͳΜͧʔʁ
.PEFM 7JFX $POUSPMMFS .7$ .7$Ͱ͋Δҙຯʁ
.7$Ҏલ
Կ͕Πέͯͳ͍ͬͯʁ w ৭ʑࠞͬͯ͡Δ w ϔομʔग़ྗ w ϩδοΫॲཧ w )5.-ͷඳը w
ϑΝΠϧ͝ͱʹϧʔςΟϯά͢Δ w ॏෳ͕ى͜Δ ˎ$(*σϓϩΠํ๏ͷ ҰͭͳͷͰ$(*ࣗମ͕ ྑ͘ͳ͍Θ͚Ͱͳ͍
۪ʹDHJΛॻ͘ͱ use CGI qw/param header/; my $name = param('name'); my
@list = qw/ྑ͍ࣄ͕ى͜ΔͰ͠ΐ͏ ग़ձ͍͕͋Δ͔ʁ ෆʹͳΓ·͢/; my $num = 0; $num += ord ($_) for split //, $name; my $index = $num % scalar @list; my $message = $list[$index]; print header('text/html; charset=utf-8'); print "<html><body>"; print "<center><b>$message</b></center>"; print "</body></html>";
)5.-͚ͩͰͤ͞Δͱ use CGI qw/param header/; use Text::MicroTemplate qw/render_mt/; use Data::Section::Simple
qw/get_data_section/; my $name = param('name'); my @list = qw/ྑ͍ࣄ͕ى͜ΔͰ͠ΐ͏ ग़ձ͍͕͋Δ͔ʁ ෆʹͳΓ·͢/; my $num = 0; $num += ord ($_) for split //, $name; my $index = $num % scalar @list; my $message = $list[$index]; my $template = get_data_section('index.mt'); my $html = render_mt($template, $message)->as_string(); print header('text/html; charset=utf-8'); print $html; __DATA__ @@ index.mt <html> <body> <center><b><?= $_[0] ?></b></center> </body> </html>
ʹͳΔ͕ ݟ௨͕͠Α͘ͳΔʂ ͞ΒʹςϯϓϨʔτΛϑΝΠϧʹ͚Δͱ ϝϯςφϯεੑɺ࠶ར༻ੑͷ্ ੑϑϨʔϜϫʔΫ͕ٵऩͯ͘͠ΕΔʁ
ͱΓ͋͑ͣ.7$Ͱߟ͑Δҙຯ w ࠞࡏ͍ͯ͠Δݻ·ΓΛׂͰ͚Δ w ཧղΛ͢ΕʹͳΔ͕։ൃޮ্͕͕Δ
͚Δͱ͔Δ͜ͱ
Γ͚ํ 3PVUFS $POUSPMMFS .PEFM-PHJD %#03.BQQFS
7JFX4UBUJDpMFT ϏδωεϩδοΫΛѻ͏ ग़ྗݟͨʹؔ͢Δ෦ ݸผͷϦΫΤετʹجͮ͘ॲཧ σʔλϕʔεʹ·ͭΘΔ 63-.&5)0%ʹԠͯ͡ৼΓ͚Δ
ׂΛ͚Δ͜ͱ ϑϨʔϜϫʔΫతࢥߟ
ॲཧͷྲྀΕ 3PVUFS $POUSPMMFS .PEFM-PHJD %#03.BQQFS 7JFX ϦΫΤετ σΟεύον Ϟσϧݺͼग़͠ %#ݺͼग़͠
%#݁Ռฦ٫ ݁Ռ ϨϯμϦϯά )5.-ͳͲ Ϩεϙϯε
1FSMͷ8"'ୡ w $BUBMZTU w %BODFS w "NPO w ,PTTZ w
1JDLMFT w 7PTPO w .PKPMJDJPVT w ࣗ࡞8"'
ࣗ࡞8"'ͱطଘ8"' w .7$ʁΛ࣮ݱ͢ΔϞδϡʔϧଗ͍ͬͯΔ w 1MBDL3FRVFTU w 3PVUFS4JNQMF w 5FYU9TMBUF w
ͨͩΞϓϦΛॻ͖ͳ͕Β8"'Ωπ͍ w ษڧ༻ʹंྠͷ࠶ൃ໌ଟ͍ʹܴ w ͰͱΓ͋͑ͣ8"'Λ͍·͠ΐ͏Ͷ—
.PKPMJDJPVTͷհ
.PKPMJDJPVT w ଐʹݴ͏ʮܰྔ8"'ʯͷҰछ w ࠷৽7FSʮʯ݄࣌ w ࡞ऀʮ4FCBTUJBO3JFEFMʯࢯ
ಛ7$͚ͩαϙʔτ w 3PVUJOH$POUSPMMFS w σϑΥϧτͰ.PKP5FNQMBUFΛ͏7JFX w ͷΈαϙʔτ͠ʮ.PEFMʯର֎ .PKP#BTFͦͷଞͰΫϥεͭͬͨ͘Γ03.BQQFS ͬͨΓͯࣗ͠ྗͰ࣮ͯ͠Ͷ͍̇ͬͯ͏ ٯʹͦΕ͕͍͍
.PEFM-PHJD8FC͔ΒΓ͖͢
ಛ/PUGVMMTUBDLCVUGVMMTUBDL 3VCZPO3BJMT %#Λѻ͏·Ͱશͯ͜ΕҰͭͰग़དྷΔ ϑϧελοΫ .PKPMJDJPVT )551ͷ3FRVFTU6TFS"HFOU·Ͱ .PKPMJDJPVTͰ͏ϥΠϒϥϦ͕શͯࣗ࡞ ϑϧελοΫ ίΞҎ֎ͷ$1"/Ϟδϡʔϧʹґଘ͠ͳ͍ʂ
None
DQBON.PKPMJDJPVT
.PKPMJDJPVTͳΒҰൃ
ಛͦͷଞ w Ξοϓσʔτ͕සൟ $self->render_json( $ref ); # 4.00 Ͱഇࢭ #
=> $self->render( json => $ref ); ͨͩ͠ґଘ͕ແ͍ͷͰ.PKPMJDJPVT͚͍ͩͬͯΕΑ͍ w .PKPMJDJPVT-JUFΛ͑ϑΝΠϧҰͭͰ w ͢Ε$(*Ͱಈ࡞Մೳ w 1FSMҎ্ඞਢɺҎ্Λਪ w ։ൃ༻αʔόNPSCPɺຊ൪༻IZQOPUPBE w ͪΖΜ14(*ޓ
খ͞ͳΞϓϦ͔Βେ͖ͳ8FCΞϓϦ·Ͱ ঃʑʹֶΔϑϨʔϜϫʔΫ .PKPMJDJPVT-JUF .PKPMJDJPVT $1"/ϞδϡʔϧͷΈ߹Θͤ
.PKPMJDJPVT-JUFΛ͏
NPKPίϚϯυʹΑΔεέϧτϯ $ mojo generate lite_app myapp.pl .PKPMJDJPVT-JUF
͡Ίͯͷ.PKPMJDJPVT-JUF #!/usr/bin/env perl use Mojolicious::Lite; get '/' => sub {
my $self = shift; $self->stash->{message} = 'Hello Mojo!'; $self->render('index'); }; app->start; __DATA__ @@ index.html.ep <html> <body> <p><%= $message %></p> </body> </html> $POUSPMMFSʹ֘ 7JFXʢςϯϓϨʔτʣ 3PVUJOHͯ͠Δ
্ཱͪ͛ํ $ morbo -l "http://*:5000" myapp.pl NPSCPΛ͏ $ plackup -p
5000 myapp.pl QMBDLVQͰ্ཱͪ͛Δ
)FMMP8PSME͔ΒֶͿ get '/' => sub {}; ϧʔςΟϯάͱίϯτϩʔϥ (&5IUUQMPDBMIPTU get '/entry/:id'
=> sub { my $entry_id = $self->stash->{id}; }; post '/entry' => sub {}; 1045IUUQMPDBMIPTUFOUSZ (&5IUUQMPDBMIPTUFOUSZ
)FMMP8PSME͔ΒֶͿ get '/' => sub { my $self = shift;
$self->stash->{message} = 'Hello Mojo'; ...; } ςϯϓϨʔτʹσʔλΛ͢ $self->render('index'); # index.html.ep Λඳը ...; <p><%= $message %></p> ςϯϓϨʔτͷهड़ͱϨϯμʔ
ͪΖΜ͍ΞϓϦʂ
4IPSUMJWFDPEJOH
#!/usr/bin/env perl use Mojolicious::Lite; use utf8; ...; get '/' =>
sub { my $self = shift; $self->render('index'); }; ...; @@ index.html.ep <p>໊લΛೖྗ͍ͯͩ͘͠͞</p> <form action="/result"> <input type="text" name="name" /> <input type="submit" value="͏" /> </form> τοϓϖʔδΛඳը
...; get '/result' => sub { my $self = shift;
my $name = $self->req->param('name'); my @list = qw/ྑ͍ࣄ͕ى͜ΔͰ͠ΐ͏ ग़ձ͍͕͋Δ͔ʁ ෆʹͳΓ·͢/; my $num = 0; $num += ord ($_) for split //, $name; my $index = $num % scalar @list; $self->stash->{message} = $list[$index]; $self->stash->{name} = $name; $self->render('result'); }; ...; @@ result.html.ep <p><%= $name %>͞Μͷ݁Ռʮ<%= $message %>ʯ</p> ݁ՌΛग़ྗ
$POUSPMMFSͰͷૢ࡞ w શͯʮTFMGʯͷϝιουΛѻ͏ my $value = $self->req->param('key'); $self->render('entry'); $self->render( json
=> { key => $value } ); .PKPMJDJPVT$POUSPMMFSΛܧঝ͢ΔͷͰͦͷυΩϡϝϯτΛಡΊ0,ʂ $self->redirect_to('/');
.PKP5FNQMBUFपΓ w 1FSMJTIUFNQMBUFT1FSMॻ͚Δʂ % for my $entry (@$entries) { <h2><%=
$entry->{title} %></h2> % } .PKP5FNQMBUF.PKPMJDJPVT1MVHJO%FGBVMU)FMQFS w ςϯϓϨʔτ͚IFMQFS @@ index.html.ep % layout 'default'; Hi, <%= $name %> @@ layouts/default.html.ep <html> <body><%= content %></body> </html>
.PKPMJDJPVT-JUFΞϓϦΛ֦ு͢Δ w QVCMJD੩తϑΝΠϧΛஔ͘ w UFNQMBUFTςϯϓϨʔτϑΝΠϧΛಠཱ ./ !"" myapp.pl !"" public/
# !"" css/ # !"" favicon.ico # !"" images/ # %"" js/ %"" templates/ !"" layouts/ # %"" default.html.ep %"" root/ %"" index.html.ep
ΑΓ࣮ફతͳΞϓϦ
.PKPMJDJPVT-JUFͩͱϑΝΠϧ͕Ͱ͔͘ͳΔΑʔ ͦ͜Ͱ-JUF͡Όͳ͍.PKPMJDJPVTΞϓϦʂ ϞδϡʔϧΛ͍͍ײ͡ʹ͚ͯͭ͘ΕΔ
.PKPMJDJPVTΞϓϦΛͭ͘Δίπ w NPKPHFOFSBUFBQQ.Z"QQͰແ͘ .Z"QQ8FCΈ͍ͨͳωʔϜεϖʔεͰ NPKPHFOFBSBUFBQQ6SBOBJ8FC w ͳͥͳΒ6SBOBJ͕8FC͚ͩͰͳ͍͔ w 6SBOBJ.PEFM6SBOBJ-PHJD w
6SBOBJ$-*
͍͍ͩͨ͜Μͳߏ ./ !"" Uranai/ # !"" DB/ # # %""
Schema.pm # !"" DB.pm # !"" Model/ # # %"" OneModel.pm # !"" Web/ # # %"" Controller/ # # %"" Root.pm # %"" Web.pm %"" Uranai.pm %#ϨΠϠʔ5FOHFUD ϏδωεϩδοΫ1FSM.PEVMF 8FCϨΠϠʔ ओʹ$POUSPMMFSͱϧʔςΟϯά 6SBOBJQNͰύεղܾͱઃఆϩʔυΛ࣮
-JUF͔ΒͷҠߦ #!/usr/bin/env perl use Mojolicious::Lite; get '/' => sub {
my $self = shift; $self->stash->{message} = 'Hello Mojo!'; $self->render('index'); }; app->start; __DATA__ @@ index.html.ep <html> <body> <p><%= $message %></p> </body> </html> MJC6SBOBJ8FCQN MJC6SBOBJ8FC$POUSPMMFS .PKPMJDJPVT$POUSPMMFSΛܧঝ UFNQMBUFT .PKP5FNQMBUFʹ४ͣΔ
͢ΜͳΓҠߦग़དྷΔʂ
͍ΞϓϦΛ࣮ͯ͠ΈΔ
࣮ํ w ͍ͷϩδοΫ෦Λ.PEFMͱͯ͠Γग़͢ w 6SBOBJ.PEFM6SBOBJ w ͦΕΛ$POUSPMMFS͔Βదٓݺͼग़͢ w 7JFX.PKPMJDJPVT-JUFͱಉ͡ͷΛ ผϑΝΠϧʹ͢Δ
6SBOBJ.PEFM6SBOBJ package Uranai::Model::Uranai; use Mouse; has 'list' => ( is
=> 'ro', isa => 'ArrayRef[Str]', default => sub { [qw/ྑ͍ࣄ͕ى͜ΔͰ͠ΐ͏ ग़ձ͍͕͋Δ͔ʁ ෆʹͳΓ·͢ /]} ); sub uranau { my ($self, $name) = @_; my $num = 0; $num += ord ($_) for split //, $name; my $index = $num % scalar @{$self->list()}; return $self->list->[$index]; } __PACKAGE__->meta->make_immutable();
.PEFM$-*͔Β͑Δ use Uranai::Model::Uranai; use feature 'say'; my $uranai = Uranai::Model::Uranai->new;
say $uranai->uranau('yusukebe'); ͬͯ͜ͱ୯ମͰςετग़དྷΔʂ
6SBOBJ8FC$POUSPMMFS3PPU package Uranai::Web::Controller::Root; use Mojo::Base 'Mojolicious::Controller'; use Uranai::Model::Uranai; sub index
{ my $self = shift; $self->render('index'); } sub result { my $self = shift; my $name = $self->req->param('name'); return $self->redirect_to('/') unless $name; my $uranai = Uranai::Model::Uranai->new; my $message = $uranai->uranau($name); $self->stash->{message} = $message; $self->render('result'); } 1;
ΞϓϦΛͭ͘Δϑϩʔ w .PEFMΛॻ͘ w ςετ͢Δ w 3PVUJOH$POUSPMMFSΛॻ͘ w ςϯϓϨʔτΛॻ͘ w
ςεταʔόΛىಈ͓ͯ͘͠ w ϒϥβͰ֬ೝ w ܁Γฦ͠
$1"/ϞδϡʔϧͱͷΈ߹Θͤͱ
.PKPMJDJPVT͚ͩͰΓͳ͍ w $1"/ϞδϡʔϧΛΈ߹Θͤͯͭ͘Δ w -JLF-&(0CMPDLT .PKPMJDJPVT 03.BQQFS 'PSN7BMJEBUPS 'JMM*O'PSN FUD
VTF'PSN7BMJEBUPS-JUF w ೖྗͷଥੑΛνΣοΫ͢Δ w ྫɿϝʔϧΞυϨεɺ༣ศ൪߸ɺจࣈ FormValidator::Lite->load_constraints(qw/Japanese Email/); my $validator =
FormValidator::Lite->new($self->req); my $res -> $validator->check( name => [qw/NOT_NULL/], mail => [qw/EMAIL/], { mails => [qw/mail mail_confirm/] } => ['DUPLICATION'] ); if($validator->has_error) { $self->stash->{messages} = $validator->get_error_messages(); return $self->render; } ...;
VTF5FOH w σʔλϕʔεΛૢ࡞͢Δ03.BQQFS w ͱͬͯγϯϓϧ w $POUSPMMFS͔Βૢ࡞ͤͣ.PEFM͔Β৮Δ my $teng =
Teng::Schema::Loader->load( dbh => $dbh, namespace => 'Uranai::DB', ); my $row = $teng->insert(result => { text => '͋ͳͨ݁ࠗग़དྷ·ͤΜ', });
%#Λ༻͍͍ͨΞϓϦͷԠ༻ w ݻఆͩͬͨͭͷબࢶΛ૿ͤΔΑ͏ʹ͍ͨ͠
ͪͳΈʹͬͨ͜ͱ CREATE TABLE result ( id INT UNSIGNED AUTO_INCREMENT, text
VARCHAR(200) NOT NULL, created_at DATETIME NOT NULL, PRIMARY KEY (`id`) ); %#Λͭͬͯ͘ lib/Uranai/DB.pm lib/Uranai/DB/Schema.pm 5FOHͷ%#εΩʔϚͭͬͯ͘ lib/Uranai/Model/Uranai.pm .PEFM͔Βૢ࡞͢ΔΑ͏ʹͯ͠ lib/Uranai/Controller/Root.pm $POUSPMMFS͔Βݺͼग़͢ templates/root/index.html.ep 7JFXͷมߋ t/01_model.t ؆୯ͳςετॻ͍ͯ Ͱ͖ͨʂ
ͦͷଞ࣮ફͰͬͯΔϞδϡʔϧ w )5.-'JMM*O'PSN-JUF w %BUB7BMJEBUPS w .PVTF w 42-.BLFS w
$BSUPO w %FWFM/:51SPG%FWFM,:51SPG w 5FTUNZTRME w )BSSJFU w $JOOBNPO w 4FSWFS4UBSUFS w 4UBSNBO4UBSMFU w FUD 5IBOLTUPHSFBU.PEVMF"VUIPSTʂ
5JQT
%&-&5&165Λٖࣅతʹαϙʔτͤ͞Δ $self->hook( before_dispatch => sub { my $c = shift;
if($c->req->method eq 'POST' && $c->req->param('_method')) { my $methods = [qw/GET POST PUT DELETE/]; if ( grep { $_ eq uc $c->req->param('_method') } @$methods ) { $c->req->method( $c->req->param('_method') ); } } } ); my $r = $self->routes; $r->delete('/entry/:id')-> to( controller => 'Entry', action => 'delete' );
IFMQFSͰ'JMM*O'PSNΛ͓खܰʹ # Uranai::Web $self->helper( render_fill => sub { my ($self,
$name) = @_; my $html = $self->render(template => $name, partial => 1); return $self->render( text => HTML::FillInForm::Lite->fill(\$html, $self->req->params), format => 'html' ); } ); # Uranai::Web::Controller::* sub form { my $self = shift; ...; if ($validator->error) { $self->stash->{messages} = $validator->get_error_messages(); return $self->render_fill('form'); } }
6SBOBJDPOpH # Uranai sub config { my $mode =
$ENV{PLACK_ENV} || 'development'; my $fname = File::Spec->catfile( Uranai->base_dir() , $mode . '.pl' ); my $config = undef; if( -f $fname ){ $config = do $fname or die "Cannnot load configuration file: $fname"; }else{ die "Cannot find configuration file: $fname"; } return $config; }
.PKPMJDJPVTͷηογϣϯʹ͍ͭͯ w σϑΥϧτΫϥΠΞϯτʹΫοΩʔͱͯ͠อ࣋ w ؾʹೖΒͳ͍߹ w 1MBDL.JEEMFXBSF4FTTJPO w ࣗ࡞ηογϣϯཧ
ࠓޙ
հͨ͜͠ͱ w 8"'ͱ.7$తͳߏʹ͍ͭͯ w ׂΛదʹ͚Δ͜ͱͰεοΩϦͱ w ରԠ͢Δ.PKPMJDJPVTΛ࣮ͬͨ w ͍ΞϓϦΛྫʹ͋͛ͨ
8FCΞϓϦΛͭ͘Δʹʁ w ྫ͑ࠓճͷ͍ΞϓϦ w .PKPMJDJPVT-JUFͰ࣮ͯ͠ΈΔ w ग़དྷͨʂԶͬͯεήʔମݧͦͷ w .PKPMJDJPVTΞϓϦͰ֦ுͯ͠ΈΔ w
ग़དྷͨʂԶͬͯεήʔମݧͦͷ w 5FOHΛֶश͍͠ͷύλʔϯΛ૿͢ w ग़དྷͨʂԶͬͯεήʔମݧͦͷ
Զͬͯεήʔମݧ গͣͭ͠ಈ͍͔ͯΔ
ѻΘͳ͔ͬͨओͳ w ΑΓποίΜͩ.PKPMJDJPVTͷ͍ํ w ςετ5FTU.PSF5FTU.PKP w ੜʹ͍ۙ%#42-ૢ࡞ w ͦͷଞϛυϧΣΞNFNDBDIFE3FEJT w
σϓϩΠαʔόߏΞϓϦαʔό w ύϑΥʔϚϯεܭଌɺνϡʔχϯά w 1FSMҎ֎ͷ͜ͱ+BWB4DSJQU$44)5.-
·ͱΊ
.PKPMJDJPVTͰ͡ΊΑ͏ w ബ͍8"'Ώ͑ཧղ͍͢͠ w .PKPMJDJPVT-JUFͷΑ͏ʹগͣͭͭ͘͠ΕΔ w ଞͷ8"'ʹԠ༻ग़དྷΔ ঃʑʹֶΔϑϨʔϜϫʔΫ
Ωʔϫʔυ ͚Δ͜ͱͰ͔Δ গͣͭ͠Ζ͏
ऴΘΓ ࣭͝ݸผʹʂ