CPANでGD::Barcode::NW7をインストール

NW7でバーコード生成をする為に、CPANのモジュールを入れる。

さっそくインストール

# cpan
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support available (try 'install Bundle::CPAN')

cpan> install GD::Barcode::NW7

すると、Warningが出た。

System call "/usr/bin/wget -O - "ftp://ftp.perl.org/pub/CPAN/authors/01mailrc.txt.gz"  > /root/.cpan/sources/authors/01mailrc.txt"
returned status 1 (wstat 256)
Warning: expected file [/root/.cpan/sources/authors/01mailrc.txt.gz] doesn't exist
No external ftp command available

どうやら、ダウンロード先URLが ftp://ftp.perl.org/pub/CPAN になっていて、そこにダウンロード対象のモジュールが無いみたい。

CPANの設定を確認してみる

cpan> o conf
CPAN::Config options from /etc/perl/CPAN/Config.pm:
    commit             Commit changes to disk
    defaults           Reload defaults from disk
    init               Interactive setting of all options

    build_cache        10
    build_dir          /root/.cpan/build
    cache_metadata     1
    cpan_home          /root/.cpan
    cpan_version_check 1
    dontload_hash
    ftp                /usr/bin/ftp
    ftp_proxy
    getcwd             cwd
    gpg                /usr/bin/gpg
    gzip               /bin/gzip
    histfile           /root/.cpan/histfile
    histsize           100
    http_proxy
    inactivity_timeout 0
    index_expire       1
    inhibit_startup_message 0
    keep_source_where  /root/.cpan/sources
    lynx
    make               /usr/bin/make
    make_arg
    make_install_arg
    makepl_arg         INSTALLDIRS=site
    ncftp
    ncftpget
    no_proxy
    pager              /usr/bin/less
    prerequisites_policy ask
    scan_cache         atstart
    shell              /bin/bash
    tar                /bin/tar
    term_is_latin      1
    unzip              /usr/bin/unzip
    urllist
    wget               /usr/bin/wget

urllist が空でした。
urllist が空の場合は、ダウンロード先URLは ftp://ftp.perl.org/pub/CPAN になるようです。

ダウンロード先URLを追加

以下のサイトから国内のダウンロード先URLを選んで追加する。
http://www.cpan.org/SITES.html

cpan> o conf urllist push ftp://ftp.nara.wide.ad.jp/pub/CPAN/
cpan> o conf commit
commit: wrote /etc/perl/CPAN/Config.pm

再度、NW7をインストール

cpan> install GD::Barcode::NW7

サンプルを動かしてみる。

nw7.pl というファイル名でサンプルを作成してバーコードを生成してみる。

# vi nw7.pl

中身はコレ。

#!/use/bin/perl

use GD::Barcode::NW7;
$data = '1234567890123';
binmode STDOUT;
print GD::Barcode::NW7->new($data)->plot->png;
# perl nw7.pl
Can't locate object method "Small" via package "GD::Font" (perhaps you forgot to load "GD::Font"?) at /usr/local/share/perl/5.8.8/GD/Barcode/NW7.pm line 83.

GD::Font が入ってないみたいですね。

libgd-gd2-perl をインストール

Debianなのでapt-getで。

# apt-get install libgd-gd2-perl
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
以下のパッケージが新たにインストールされます:
  libgd-gd2-perl
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 58 個。
218kB のアーカイブを取得する必要があります。
展開後に追加で 586kB のディスク容量が消費されます。
取得:1 http://ftp.debian.org etch/main libgd-gd2-perl 1:2.34-1 [218kB]
218kB を 2s で取得しました (93.3kB/s)
未選択パッケージ libgd-gd2-perl を選択しています。
(データベースを読み込んでいます ... 現在 14610 個のファイルとディレクトリがインストールされています。)
(.../libgd-gd2-perl_1%3a2.34-1_i386.deb から) libgd-gd2-perl を展開しています...
libgd-gd2-perl (2.34-1) を設定しています ...
#

再度、サンプルを実行

# perl nw7.pl

今度はうまくいったので、画像に出力してみる。

# perl nw7.pl > nw7.png

無事、PerlでNW7のバーコードを生成できました~

24
3月
2010

CPANの初期設定

仕事でPerl使う事があり、開発環境のDebianでCPANの設定をしてみる。

cpan は既に入っているようなので、 cpan コマンドを実行。

# cpan

cpanコマンドが使えない場合は、

# perl -MCPAN -e shell

「マニュアル設定しますか?」という質問に「no」と回答すると初期設定は完了。

# cpan

/etc/perl/CPAN/Config.pm initialized.

CPAN is the world-wide archive of perl resources. It consists of about
100 sites that all replicate the same contents all around the globe.
Many countries have at least one CPAN site already. The resources
found on CPAN are easily accessible with the CPAN.pm module. If you
want to use CPAN.pm, you have to configure it properly.

If you do not want to enter a dialog now, you can answer 'no' to this
question and I'll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing 'o conf init' at the cpan prompt.)

Are you ready for manual configuration? [yes] no

設定が失敗したら

以下のように設定ファイルを削除して、再度cpanを実行すれば、最初から設定が出来る。

# rm /etc/perl/CPAN/Config.pm
24
3月
2010