33
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

perlbrew や cpanm と carton

Posted at

perlbrew

perlbrew

perlbrewは非アドミン環境(ローカル環境)にperlの本体をインストールすることができるツール。OSに付属するperlから(インストールされているライブラリを含む)依存することないperlの環境を作ることができる

とりあえずは perlbrew で最新版の perl の環境を作る

$ perlbrew available
  perl-5.19.8
  perl-5.18.2
...
  perl5.003_07

$ perlbrew install perl-5.18.2
...
perl-5.18.2 is successfully installed.
$ perlbrew switch perl-5.18.2

cpanm

[cpanm]
(http://search.cpan.org/~miyagawa/App-cpanminus-1.7001/lib/App/cpanminus.pm)

cpanminus(コマンドはcpanm)はCPANモジュールをget, unpack, build して install までやってくれる便利なツール。依存関係とかも考慮してくれるのでインストールしたいモジュールを指定することであとはよしなにしてくれる神ツール。

perlbrew 環境下における cpanm はperlbrewのコマンドでインストール可能

$ perlbrew install-cpanm
$ cpanm
Usage: cpanm [options] Module [...]

Try `cpanm --help` or `man cpanm` for more options.

carton

carton

cartonは開発するアプリケーション単位で必要なPerlモジュールを一括管理、インストール(デプロイ)を行ってくれるこれまた神ツール。特定のディレクトリ以下にアプリケーションで必要なPerlモジュールの構成を構築してくれる。
アプリケーションが使用するPerlモジュール定義を記述するファイルを cpanfile と呼びます。

インストール

$ cpanm Carton

ついでに... carton 環境下で Plack 動かしてみる

$ cat cpanfile
requires 'Plack';

こんなシンプルなcpanfileをつくる ( cpanfile の詳しい使い方はまた今度勉強する.)

空の作業ディレクトリを作って carton コマンド実行する.

$ carton
Installing modules using /Users/keisyu/work/MyApp/cpanfile     # つくった cpanfile を読み込んでPlackモジュールを依存モジュールとともにインストール
Successfully installed File-ShareDir-Install-0.08
Successfully installed Devel-StackTrace-1.31
...
Successfully installed Stream-Buffered-0.02
Successfully installed Plack-1.0030
23 distributions installed
Complete! Modules were installed into /Users/keisyu/work/MyApp/local  # モジュールは作業ディレクトリ直下のlocalディレクトリに全部入ったよ。
$ ls
cpanfile          cpanfile.snapshot local   # cpanfile.snapshot は依存関係も含めたインストールしたモジュールのバージョンも含めた詳細情報を記録されてる。

PSGIのHello world

use strict;
use warnings;

my $app = sub {
    my $env = shift;

    return [
        200,
        [ 'Content-Type'  => 'text/html'],
        [ 'Hello PSGI World!!']
    ];
};

って感じのHelloWorldファイルを作って

$ carton exec -- plackup hello.psgi
HTTP::Server::PSGI: Accepting connections at http://0:5000/

でOK. http://localhost:5000/ でちゃんと動いた. (そりゃそうだ)
plackはcartonで入れたんだから当然

$ plackup hello.psgi
zsh: command not found: plackup

では動かない。 carton exec -- にてlocal以下のモジュールを使うようにしないとね。

33
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?