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
420
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
Remix on Hono on Cloudflare Workers
yusukebe
1
300
僕がつくった48個のWebサービス達
yusukebe
20
17k
Honoの来た道とこれから
yusukebe
20
3.2k
JS RPCを理解する
yusukebe
5
680
Honoとhtmx
yusukebe
6
1.8k
Cloudflare Workersの環境を再現することについて
yusukebe
7
1k
Hono v4
yusukebe
11
4.8k
Hono v3 and v4
yusukebe
4
3.8k
The power of Web-standards
yusukebe
4
1.7k
Other Decks in Programming
See All in Programming
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
360
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1k
Macとオーディオ再生 2024/11/02
yusukeito
0
380
Jakarta EE meets AI
ivargrimstad
0
710
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
940
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
RubyLSPのマルチバイト文字対応
notfounds
0
120
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Featured
See All Featured
Visualization
eitanlees
145
15k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
A Philosophy of Restraint
colly
203
16k
Designing the Hi-DPI Web
ddemaree
280
34k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Designing for Performance
lara
604
68k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
How to Ace a Technical Interview
jacobian
276
23k
Bash Introduction
62gerente
608
210k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
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"'ʹԠ༻ग़དྷΔ ঃʑʹֶΔϑϨʔϜϫʔΫ
Ωʔϫʔυ ͚Δ͜ͱͰ͔Δ গͣͭ͠Ζ͏
ऴΘΓ ࣭͝ݸผʹʂ