macbookairにplenvをインストール
今回は、perlのバージョン管理ツールである、 plenvをインストールしていき、cpanmでMojoliciousインストールして、サンプルを動かすところまで、やっていこうと思います。
環境
- macbookair Late 2012
- OSX 10.8.2
- Xcode4.6
インストール
homebrewでplenvをインストール
plenvはtokuhiromさんが制作しているツールです。なんとかSignalsとかじゃないんですね。(言語がちがうけど)
Homebrewにあるのでそこからいれます。
githubにリポジトリがあがっていて、インストール方法として、cpan, Honebrew ,githubからクローンする方法が掲載されています。簡単ですね。
$ brew install plenv Warning: Your Xcode (4.5.2) is outdated Please install Xcode 4.6. ==> Downloading https://github.com/tokuhirom/plenv/tarball/1.1.0 ######################################################################## 100.0% ==> Caveats To enable shims add to your profile: if which plenv > /dev/null; then eval "$(plenv init -)"; fi ==> Summary 🍺 /usr/local/Cellar/plenv/1.1.0: 24 files, 288K, built in 6 seconds
入りました。
次に、おすきなシェルのリソースファイルに設定を追記します
ぼくは、こちらを参考にしました。
そして
$ source .bashrc
とか、シェルに再ログインしたりしておきます。
plenvを使ってみる
早速、perlをインストールしてみます。
$ plenv available perl-5.17.8 perl-5.16.2 perl-5.14.3 perl-5.12.5 perl-5.10.1 perl-5.8.9 perl-5.6.2 perl5.005_04 perl5.004_05 perl5.003_07
現時点でインストールできるバージョンの一覧がでてきます。
plenv の引数のコマンドはタブで補完は効かないんですね。
それではperlをインストールしていきます。折角なので、新しいやつを。
$ plenv install perl-5.17.8
5分くらい待って、完了。
cpanmをインストール
次にcpanmをインストールしていきます。
Rubyでいうgemみたいなやつですね。
plenv install-cpanm Installing cpanm to current perl % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 331k 100 331k 0 0 31808 0 0:00:10 0:00:10 --:--:-- 67146 You are running cpanm from the path where your current perl won't install executables to. Because of that, cpanm --self-upgrade won't upgrade the version of cpanm you're running. cpanm path : - Install path : /usr/local/bin It means you either installed cpanm globally with system perl, or use distro packages such as rpm or apt-get, and you have to use them again to upgrade cpanm. ! ! Can't write to /Library/Perl/5.12 and /usr/local/bin: Installing modules to /Users/typosterr/perl5 ! To turn off this warning, you have to do one of the following: ! - run me as a root or with --sudo option (to install to /Library/Perl/5.12 and /usr/local/bin) ! - Configure local::lib your existing local::lib in this shell to set PERL_MM_OPT etc. ! - Install local::lib by running the following commands ! ! cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib) ! --> Working on App::cpanminus Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.5021.tar.gz ... OK Configuring App-cpanminus-1.5021 ... OK Building and testing App-cpanminus-1.5021 ... OK Successfully installed App-cpanminus-1.5021 1 distribution installed
入りました。
$ cpanm mojo ! Finding mojo on cpanmetadb failed. --> Working on mojo Fetching http://www.cpan.org/authors/id/S/SR/SRI/Mojolicious-3.84.tar.gz ... OK Configuring Mojolicious-3.84 ... OK Building and testing Mojolicious-3.84 ... OK Successfully installed Mojolicious-3.84 1 distribution installed
ここで、以下のコマンドを実行 rbenvと一緒ですね><
$ plenv rehash
これで、morboとか使えるようになりました。
$ morbo usage: /Users/typosterr/.plenv/versions/5.16.2/bin//morbo [OPTIONS] [APPLICATION] morbo script/myapp morbo myapp.pl morbo -w /usr/local/lib -w public myapp.pl These options are available: -h, --help Show this message. -l, --listen <location> Set one or more locations you want to listen on, defaults to the value of MOJO_LISTEN or "http://*:3000". -v, --verbose Print details about what files changed to STDOUT. -w, --watch <directory/file> Set one or more directories and files to watch for changes, defaults to the application script as well as the "lib" and "templates" directories in the current working directory. $
では、このサイトを参考に(ドットインストールでもいいんですが、、)簡単なアプリケーションを作っていこうと思います。
では、適当なディレクトリを作成して
use Mojolicious::Lite; get '/' => sub { shift->render(text => 'Hello World!') }; app->start;
をmyApp.plという名前で保存します。
命令が簡潔すぎて、内部の実装が気になるところです。
これを
$ morbo myApp.pl
とすると
[Fri Feb 1 23:43:16 2013] [info] Listening at "http://*:3000". Server available at http://127.0.0.1:3000.
こんな感じで、ローカルにサーバがたちあがるので、
ブラウザで、上記URLの
http://127.0.0.1:3000
にアクセスすると
おなじみのHello worldが出力されます。
ログはこんな感じです。
[Fri Feb 1 23:40:08 2013] [info] Listening at "http://*:3000". Server available at http://127.0.0.1:3000. [Fri Feb 1 23:40:18 2013] [debug] Your secret passphrase needs to be changed!!! [Fri Feb 1 23:40:18 2013] [debug] GET / (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17). [Fri Feb 1 23:40:18 2013] [debug] Routing to a callback. [Fri Feb 1 23:40:18 2013] [debug] 200 OK (0.000560s, 1785.714/s).
簡単でした。
今後も、少しずつやっていこうと思います。
最後までお読みいただき、ありがとうございました。
追記
- (2013/02/19)誤字を修正しました。