CPAN の初期設定(初回起動時)の際に http_proxy と ftp_proxy を設定してもミラーサイトへアクセスできず、取り敢えずオフラインで初期設定画面を飛ばしたいと思ったら、ちょっとハマったため、備忘録。

恐らく、初期設定画面にて問答無用でデフォルト設定のまま [Enter] 押下して待てば抜けると思いますが、かなり時間がかかると思います。


■ パッケージのインストール

# yum -y install perl-CPAN


■ CPAN 初期設定

# cpan

cpan コマンド初回実行後、初期設定が走るので、最短で飛ばしたい方は以下を実施。
=========================
Sorry, we have to rerun the configuration dialog for CPAN.pm due to
some missing parameters. Configuration will be written to
 <</root/.cpan/CPAN/MyConfig.pm>>


CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes] no ← 入力

 <install_help>

Warning: You do not have write permission for Perl library directories.

To install modules, you need to configure a local Perl library directory or
escalate your privileges.  CPAN can help you by bootstrapping the local::lib
module or by configuring itself to use 'sudo' (if available).  You may also
resolve this problem manually if you need to customize your setup.

What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
 [local::lib] ← そのまま [Enter] 押下

 :
 :  ← この間、複数問い合わせがあるので、そのまま [Enter] 押下
 :

 <connect_to_internet_ok>
If no urllist has been chosen yet, would you prefer CPAN.pm to connect
to the built-in default sites without asking? (yes/no)? [yes]  no ← 入力


Now you need to choose your CPAN mirror sites.  You can let me
pick mirrors for you, you can select them from a list or you
can enter them by hand.

Would you like me to automatically choose some CPAN mirror
sites for you? (This means connecting to the Internet) [yes]  no ← 入力


Would you like to pick from the CPAN mirror list? [yes] no ← 入力

Now you can enter your own CPAN URLs by hand. A local CPAN mirror can be
listed using a 'file:' URL like 'file:///path/to/cpan/'

CPAN.pm needs at least one URL where it can fetch CPAN files from.

Please enter your CPAN site: [] ← そのまま [Enter] 押下

 :
 :  ← 上記質問が、あと4回あるので、そのまま [Enter] 押下
 :

Giving up.

New urllist
Skipping local::lib bootstrap because 'urllist' is not configured.

commit: wrote '/root/.cpan/CPAN/MyConfig.pm'

You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.9800)
Enter 'h' for help.
=========================


■ CPAN 起動後の設定とモジュールのインストール

上記の設定では使いものにならないので、proxy設定とモジュールのインストールを行います。


proxy設定

cpan> o conf http_proxy <例) http://proxy.local:8080>
cpan> o conf proxy_user <Proxy ユーザー名>
cpan> o conf proxy_pass <Proxy パスワード>
cpan> o conf commit



ミラーサイトの設定

cpan> o conf urllist http://ftp.riken.jp/lang/CPAN/
cpan> o conf commit

モジュールのインストール

cpan> install <モジュール名>


■ モジュールがインストールされているかの確認

以下、どれかを実行すれば導入済みか確認できるので、念の為、実行しておくことをオススメします。
一番わかり易いのは、Linux コマンドでエラー出力とならないか確認するのがいいですかね。


Linux コマンドからの確認

# perldoc -m <モジュール名>

モジュールが見つからない場合は、「No module found for "< モジュール名 >".」 と表示されます。


CPAN コマンドからの確認

下記、インストールコマンドを実行して、導入済みとの表示を確認する。

cpan> install <モジュール名>
<モジュール名> is up to date (X.X.XX).


ただし、モジュールによっては yum で引っ張ってくるものもあるので、注意してください。
DBI/DBD、LWP::UserAgent、Archive::Zip などは yum install で入れ込みます。

[DBI/DBD]
# yum -y install perl-DBI perl-DBD-Pg

[LWP::UserAgent]
# yum -y install perl-libwww-perl

[Archive::Zip]
# yum -y install perl-Archive-Zip

上記インストール後は、perldoc コマンドでエラーが出力されないことを確認すればOKです。



以上