概要
- Perlbrewのインストール
- Perlのインストール
- cpanmのインストール
- Mojoliciousのインストール
- Herokuに載せる為のパッケージインストール
- Herokuにデプロイ(Git)
Perlbrewのインストール
$ curl -kL https://raw.github.com/gugod/App-perlbrew/13f760afd72762bbf253bf3070efee12b9a33cef/perlbrew > perlbrew
$ perl perlbrew install
The perlbrew is installed as:
~/perl5/perlbrew/bin/perlbrew
You may trash the downloaded /usr/local/bin/perlbrew from now on.
Perlbrew environment initiated under ~/perl5/perlbrew
Append the following piece of code to the end of your ~/.zshenv and start a new shell, perlbrew should be up and fully functional from there:
source ~/perl5/perlbrew/etc/bashrc
For further instructions, simply run `perlbrew` to see the help message.
Happy brewing!
はい、楽しみましょう(・∀・)!
ってことで、次はお使いのシェルにperlbrewのPATHをカキコφ(`д´)カキカキ
$ echo "source ~/perl5/perlbrew/etc/bashrc" >> ~/.bashrc
$ echo "source ~/perl5/perlbrew/etc/bashrc" >> ~/.zshrc
$ source ~/.bashrc
$ source ~/.zshrc
変更を反映させたら、Perlのインスコ。
今回はMacのPerlのバージョンが低かったので、5.14.2を入れます。
Perlインストール
$ sudo perlbrew install perl-5.14.2
Fetching perl-5.14.2 as /Users/suyama/perl5/perlbrew/dists/perl-5.14.2.tar.bz2
Installing /Users/suyama/perl5/perlbrew/build/perl-5.14.2 into ~/perl5/perlbrew/perls/perl-5.14.2
This could take a while. You can run the following command on another shell to track the status:
tail -f ~/perl5/perlbrew/build.log
# ここで止まります。20分くらい?
Installed /Users/suyama/perl5/perlbrew/build/perl-5.14.2 as perl-5.14.2 successfully. Run the following command to switch to it.
perlbrew switch perl-5.14.2
30分くらいかかりましたc(`Д´と⌒c)つ彡 ヤダヤダ
お疲れ様でした。
本当にインスコされたのか確認します。
$ perlbrew list
perl-5.14.2
確認が出来たら、インスコした Perlを使えるように設定します。
$ perlbrew switch perl-5.14.2
$ perlbrew list
* perl-5.14.2
*がついていたらOK.
一応バージョン確認
$ perl -v
This is perl 5, version 14, subversion 2 (v5.14.2) built for darwin-2level
Cpanmのインストール
はい、次はcpanのモジュールをインスコします。
Mojoliciousのインスコをcpanmで行いたいからです。
$ perlbrew install-cpanm
cpanm is installed to
/Users/suyama/perl5/perlbrew/bin/cpanm
cpanmが動くかチェック
$ cpanm JSON
これが通ったら、インスコ準備完了ってことです。
いざ。
Mojoliciousのインストール
$ sudo cpanm Mojolicious
Password:
--> Working on Mojolicious
Fetching http://www.cpan.org/authors/id/S/SR/SRI/Mojolicious-3.95.tar.gz ... OK
Configuring Mojolicious-3.95 ... OK
Building and testing Mojolicious-3.95 ... OK
Successfully installed Mojolicious-3.95
1 distribution installed
インスコできました(・∀・)!
それでは、適当なワーキングディレクトリに以下を作成。ハローワールドしますよーHello(^^)!
$ mkdir hellomojo
$ cd hellomojo
$ touch myapp.pl
$ chmod +x myapp.pl
$ vim myapp.pl
# !/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
$self->render('index');
};
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>
コードは以上の通り。もっと簡単にもできますが、それは次回以降。
サーバーを動かします。morboコマンドを使うようです。
$ morbo myqpp.pl
[Mon Apr 22 13:35:24 2013] [info] Listening at "http://*:3000".
Server available at http://127.0.0.1:3000.
[Mon Apr 22 13:35:57 2013] [debug] Your secret passphrase needs to be changed!!!
[Mon Apr 22 13:35:57 2013] [debug] GET / (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31).
[Mon Apr 22 13:35:57 2013] [debug] Routing to a callback.
[Mon Apr 22 13:35:57 2013] [debug] 200 OK (0.001101s, 908.265/s).
・
・
・
はい、アクセスしまーす(∞*・3・*)ノガンバッテー
真っ白な画面の左上に地味に、Hello worldって出てたらOK!
herokuに載せる準備
ちょっと面倒くさいです。
このパッケージを全力で利用します(;`ー´)o/ ̄ ̄~>゚))彡
Toolbelt
ひとまずtoolbeltを入れてない場合は、入れましょう。
ここからどうぞ。
ファイル作成など
次に先ほどのディレクトリのmyapp.plと同じ階層に、Makefile.PLとPerlokuを作成します。
$ heroku login
Enter your Heroku credentials.
Email:
$ touch Makefile.PL
$ touch Perloku
$ chmod +x Perloku
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'myapp.pl',
VERSION => '1.0',
AUTHOR => 'Funyamora Funya <hogehoge@hogenne.com>',
EXE_FILES => ['myapp.pl'],
PREREQ_PM => {'Mojolicious' => '2.0'},
test => {TESTS => 't/*.t'}
);
# !/bin/sh
./myapp.pl daemon -l http://*:$PORT -m production
必要なファイルは出来ました。
これらをherokuにのっけます!
手順は普通です。
herokuにデプロイ(Git)
まずは、herokuにアプリ作成をし、先ほど挙げたパッケージを読み込ませます。
$ heroku create -s cedar --buildpack http://github.com/judofyr/perloku.git
Creating shielded-fjord-8979... done, stack is cedar
BUILDPACK_URL=http://github.com/judofyr/perloku.git
http://shielded-fjord-8979.herokuapp.com/ | git@heroku.com:shielded-fjord-8979.git
Git remote heroku added
一応確認
$ git remote
heroku
あとは、通常通りです。
$ git add .
$ git commit -m ""
Aborting commit due to empty commit message.
$ git push heroku master
Warning: Permanently added the RSA host key for IP address 'xxx.xxx.xxx.xxx' to the list of known hosts.
error: src refspec master does not match any.
error: failed to push some refs to 'git@heroku.com:hoge-katana-funya,8111.git'
これはコミット忘れかもってことで、コミットしてもう一度。
$ git commit -m ""
Aborting commit due to empty commit message.
あー たまにやるミスです(私が)
"" の中を埋めなきゃだめなんだ。
では
$ git commit -m "initial commit"
[master (root-commit) db7199b] initial
3 files changed, 17 insertions(+)
create mode 100644 Makefile.PL
create mode 100755 Perloku
create mode 100755 myapp.pl
良い感じ。
$ git push heroku master
errorメッセージが出てなければうまく行った感じになります◎
viewの確認は、Herokuで割り当てられているURLにアクセスしてみて下さい。
白い背景に上で入力した文字が出ていればOKです。
見事、HerokuにMojoliciousで作ったコードを載っけられました。
ref) サンプルコードによるPerl入門
ref) Sebastian Riedel about Perl and the Web
ref) https://github.com/judofyr/perloku