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のバーコードを生成できました~
