[macOS General] Perl: cpanm とモジュールをインストールする
動かしてみたいサンプルスクリプトが Perl モジュールを要求したので、インストールしてみました。
[markdown]
手順としては、Mac に限らないはず。
## 状況
` DBIx/Simple.pm` が必要なよう。
“`prettyprinted
% perl view2kobito.pl
Can’t locate DBIx/Simple.pm in @INC (@INC contains: /Library/Perl/5.16/darwin-thread-multi-2level /Library/Perl/5.16 /Network/Library/Perl/5.16/darwin-thread-multi-2level /Network/Library/Perl/5.16 /Library/Perl/Updates/5.16.2 /System/Library/Perl/5.16/darwin-thread-multi-2level /System/Library/Perl/5.16 /System/Library/Perl/Extras/5.16/darwin-thread-multi-2level /System/Library/Perl/Extras/5.16 .) at view2kobito.pl line 6.
BEGIN failed–compilation aborted at view2kobito.pl line 6.
“`
> * [Perl – Kobito.appのDBファイルの中身を見る – Qiita](http://qiita.com/soh-i@github/items/ee7b7d026df28d07b12c)
## cpanm とモジュールのインストール
たしか `cpanm` というのを使うはずということで、Google 先生に聞いてみる。
> * [perlモジュールのinstallにcpanmを使う|perl|@OMAKASE](http://www.omakase.org/perl/cpanm.html)
> * [cpanmによるローカル環境構築 / 開発環境構築 – サンプルコードによるPerl入門 ~ Perlで楽しくプログラミングを学ぼう ~](http://d.hatena.ne.jp/perlcodesample/20101027/1278596435)
プロジェクトディレクトリに `/bin` を作って、そこにおいてみる。
“`prettyprinted
% mkdir bin
% cd bin
% curl -LOk http://xrl.us/cpanm
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 216 0 216 0 0 481 0 –:–:– –:–:– –:–:– 482
0 0 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0
100 120 100 120 0 0 64 0 0:00:01 0:00:01 –:–:– 140
100 262k 100 262k 0 0 104k 0 0:00:02 0:00:02 –:–:– 485k
% chmod +x cpanm
“`
コマンド実行。
ユーザディレクトリに `~/perl5` を作って、そこに設置してくれたそう。
“`prettyprinted
% bin/cpanm DBIx::Simple
!
! Can’t write to /Library/Perl/5.16 and /usr/local/bin: Installing modules to /Users/****/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.16 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 DBIx::Simple
Fetching http://www.cpan.org/authors/id/J/JU/JUERD/DBIx-Simple-1.35.tar.gz … OK
Configuring DBIx-Simple-1.35 … OK
Building and testing DBIx-Simple-1.35 … OK
Successfully installed DBIx-Simple-1.35
1 distribution installed
“`
確認してみる。
“`prettyprinted
~/perl5
├── lib
│ └── perl5
│ ├── DBIx
│ │ ├── Simple
│ │ │ ├── Comparison.pod
│ │ │ ├── Examples.pod
│ │ │ └── Result
│ │ │ └── RowObject.pm
│ │ └── Simple.pm
│ └── darwin-thread-multi-2level
│ ├── auto
│ │ └── DBIx
│ │ └── Simple
│ └── perllocal.pod
└── man
└── man3
├── DBIx::Simple.3pm
├── DBIx::Simple::Comparison.3pm
├── DBIx::Simple::Examples.3pm
└── DBIx::Simple::Result::RowObject.3pm
11 directories, 9 files
“`
## 設定を追加する
`.bash_profile` や `.zshenv` あたりに設定を加える。
“`bash:~/.zshenv
export PERL_CPANM_OPT=”–local-lib=~/perl5″
export PATH=$HOME/perl5/bin:$PATH;
export PERL5LIB=$HOME/perl5/lib/perl5:$PERL5LIB;
“`
以上で使えるようになりました。
問題は本来の目的を果たせていないこと。。。
またいつか調べよう。
[/markdown]