4
4

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.

PerlアプリでBuild.PLを作って依存するCPANをインストールする

Posted at

目的

  • Perlアプリを作ったので公開したい(第三者に渡したい)
  • 依存するCPANがたくさんあるので、ちゃんとインストールしてほしい

使うもの

  • perlbrew
    • 自分のマシンに入ってるCPANを一度アンインストールして、クリーンな状態からやり直すのはイヤだったので、独立した環境が欲しかった
    • 参考にしたのは perlbrewで構築するモダンなPerl環境
  • Module::Build
    • Build.PLを使いたかった
    • Makefile.PLでもよかった気がするが、アプリ自体のコンパイルは今回想定していないし、試してない

手順

perlbrew で perl をインストール

$ curl -kL http://install.perlbrew.pl | bash
$ source ~/perl5/perlbrew/etc/bashrc

これで perlbrew 側の perl が使われるようになる。

$ perlbrew available

インストールできるPerlのバージョンが表示される。

$ perlbrew install 5.21.9

でインストールをする。かなり時間がかかる。

perl にオプションを渡したいときは、

$ perlbrew install 5.21.9 -Dusethreads

のようにここでオプションを渡す。

$ perlbrew list
  perl-5.21.9

とするとインストール済みのバージョンが表示される。

$ perlbrew switch 5.21.9

で実際に使用するよう切り替える。

$ perlbrew list
* perl-5.21.9

使用中のバージョンには*マークがつく。

もしアンインストールしたいときは uninstall すればいいが、インストール済みのCPANなども一緒に消えるので注意。

$ perlbrew uninstall perl-5.21.9

perlbrew で cpanm を有効にする

$ perlbrew install-cpanm

Build.PLを用意する

$ cpanm Module::Build

をして別途インストールしておく必要がある。

Build.PLのファイルを作る。

$ vi Build.PL

内容は、こんな感じ。

use Module::Build;
my $build = Module::Build->new(
     module_name => 'Test::Web',
     license => 'perl',
     requires => {
                  'perl'           => '5.6.1',
                  'Mojolicious'    => '6.01'
                 },
  );
$build->create_build_script;

実行

$ perl Build.PL

で足りていないCPANがあるとエラーが出て、Build installdeps を実行しろというメッセージが出る。

perlbrewでインストールした直後だとCPANが全然入ってないので、CPANをrequiresにした場合は必ずエラーになるはず。

生成された Build ファイルを言われた通りに実行する。

$ ./Build installdeps

perlbrewのCPANにインストールされる。

これで目的のPerlアプリを動かしてみて、CPANが足りていなければエラーになるので、そのCPANをBuild.PLに追加する。
何回か繰り返して、必要なCPANが全てBuild.PLに記載されたら終わり。
Perlアプリと一緒にBuild.PLも配布すればいい。

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?