さくらレンタルサーバPerl環境
また必要になった時のためにまとめておく。
0.binディレクトリ
$ mkdir ~/bin
1.cpanminus
気になっていた cpanminus を初めて入れた。
$ cd ~/bin $ wget http://xrl.us/cpanm $ chmod +x cpanm
2.perlbrew
さくらのデフォルトはPerl5.8.9と、ちょっと古めの安定版だったので、perlbrew を使って最新のPerl5.12.1を入れる。
perlbrew も初めて。
参考:perlbrew + cpanminus + local::lib で環境構築 - Webtech Walker
ありがとうございます。
$ cd ~/bin $ wget http://xrl.us/perlbrew $ chmod +x perlbrew $ ./perlbrew install ... Next, if this is the first time you've run perlbrew installation, run: /home/rightgo09/perl5/perlbrew/bin/perlbrew init $ ~/perl5/perlbrew/bin/perlbrew init ... Well-done! Congratulations! Please add the following line to the end of your ~/.bashrc source /home/rightgo09/perl5/perlbrew/etc/bashrc $ cat >> ~/.bashrc << \EOF > source /home/rightgo09/perl5/perlbrew/etc/bashrc > EOF $ cat > ~/.bash_profile << \EOF > if [ -f ~/.bashrc ]; then > . ~/.bashrc > fi > EOF $ perlbrew install perl-5.12.1 Attempting to load conf from /home/rightgo09/perl5/perlbrew/Conf.pm Fetching perl-5.12.1 as /home/rightgo09/perl5/perlbrew/dists/perl-5.12.1.tar.gz Installing perl-5.12.1 into /home/rightgo09/perl5/perlbrew/perls/perl-5.12.1 This could take a while. You can run the following command on another shell to track the status: tail -f /home/rightgo09/perl5/perlbrew/build.log (cd /home/rightgo09/perl5/perlbrew/build; tar xzf /home/rightgo09/perl5/perlbrew/dists/perl-5.12.1.tar.gz;cd /home/rightgo09/perl5/perlbrew/build/perl-5.12.1;rm -f config.sh Policy.sh;sh Configure -de -Dprefix=/home/rightgo09/perl5/perlbrew/perls/perl-5.12.1;make;make test && make install) >> '/home/rightgo09/perl5/perlbrew/build.log' 2>&1 Installing perl-5.12.1 failed. See /home/rightgo09/perl5/perlbrew/build.log to see why. If you want to force install the distribution, try: perlbrew --force install perl
あれっ。
まさかのテスト失敗。
メッセージどおりのログファイルからエラー箇所を探す。
$ tail ~/perl5/perlbrew/build.log ... Failed 1 test out of 1696, 99.94% okay. ../cpan/Sys-Syslog/t/syslog.t $ less ~/perl5/perlbrew/build.log ... cpan/Sys-Syslog/t/syslog.......................................# Failed test '[inet ] syslog() called with level 'info' (string)' # at t/syslog.t line 165. # got: 'no connection to syslog available # - getservbyname failed for syslog/tcp and syslogng/tcp # - udp connect: nobody listening at t/syslog.t line 164 # ' # expected: '' FAILED at test 141
どうも syslog とばすための TCP/UDP ソケットが作れない的なエラーなのかなー。
でもなんでここの info() レベルだけ失敗してるんだろ?
少しだけ粘って挫折。
メッセージどおり、force インストール。
$ perlbrew --force install perl-5.12.1 Attempting to load conf from /home/rightgo09/perl5/perlbrew/Conf.pm Use the previously fetched perl-5.12.1.tar.gz Installing perl-5.12.1 into /home/rightgo09/perl5/perlbrew/perls/perl-5.12.1 This could take a while. You can run the following command on another shell to track the status: tail -f /home/rightgo09/perl5/perlbrew/build.log (cd /home/rightgo09/perl5/perlbrew/build; tar xzf /home/rightgo09/perl5/perlbrew/dists/perl-5.12.1.tar.gz;cd /home/rightgo09/perl5/perlbrew/build/perl-5.12.1;rm -f config.sh Policy.sh;sh Configure -de -Dprefix=/home/rightgo09/perl5/perlbrew/perls/perl-5.12.1;make;make test;make install) >> '/home/rightgo09/perl5/perlbrew/build.log' 2>&1 Installed perl-5.12.1 as perl-5.12.1 successfully. Run the following command to switch to it. perlbrew switch perl-5.12.1 $ perlbrew switch perl-5.12.1 $ which perl /home/rightgo09/perl5/perlbrew/bin/perl $ perl -v This is perl 5, version 12, subversion 1 (v5.12.1) built for i386-freebsd $ which perldoc /home/rightgo09/perl5/perlbrew/bin/perldoc
ok。
3.CPANモジュール
じゃあ、早速モジュールのインストール。
WebAPIを簡単に使うために、WebService::Simple を入れる。
ありがとうございます。
$ perldoc WebService::Simple No documentation found for "WebService::Simple". $ cpanm WebService::Simple ... successful! $ perldoc WebService::Simple No documentation found for "WebService::Simple".
あれ?
入ったんじゃないのか?
さっきものすごく成功しました!って出てたぞ。
$ find . -name Simple.pm ./perl5/perlbrew/perls/perl-5.12.1/lib/site_perl/5.12.1/WebService/Simple.pm
うん、やっぱり入ってる。
perldoc も新しく入れた方が使われてるし、というか、perldoc ってどこに見に行ってるんだ?
ネットで調べてみる。
404 Not Found
-l
モジュールを探してインストール場所を表示。
この時perldocは自分のバージョンのperlの@INCパスを使うので、
perlを複数インストールしてある場合は注意する。
ありがとうございます。
そうか、@INC か。
それがなんかおかしいんかな。
$ perl -e 'print "$_\n" for @INC' /home/rightgo09/perl5/perlbrew/perls/perl-5.12.1/lib/site_perl/5.12.1/i386-freebsd /home/rightgo09/perl5/perlbrew/perls/perl-5.12.1/lib/site_perl/5.12.1 /home/rightgo09/perl5/perlbrew/perls/perl-5.12.1/lib/5.12.1/i386-freebsd /home/rightgo09/perl5/perlbrew/perls/perl-5.12.1/lib/5.12.1 .
なんだよちゃんとライブラリパスあってんじゃんかよ。
えーじゃあモジュール使えるのは使えるのかな。
$ perl -MWebService::Simple my $ws = WebService::Simple->new; base_url is required at - line 1
怒られたってことは使えてるんだろうな。
えーもうわけわかんねー、休もう。
。。。。
で、もう一回sshでログインしたら直りました。
なんだろ、直後はperldocできないとかあんのかな。
$ perldoc WebService::Simple perperlbrew::perls::perl-5.12.1::lib::sitelperl::5.12.1::WebService::Simple(3) NAME WebService::Simple - Simple Interface To Web Services APIs ... $ perldoc -l WebService::Simple /home/rightgo09/perl5/perlbrew/perls/perl-5.12.1/lib/site_perl/5.12.1/WebService/Simple.pm
あとはDB接続用のあれ。
O/Rマッパはいまはいれないぜ。
素の接続が早いんだぜ。
$ cpanm DBI $ cpanm DBD::mysql
こっちは問題なし。
というか、この DBD::mysql で毎回泣かされるんだけど、今回は何もなくてよかったのだろうか。
一応 build.log 見たけど、恐ろしく skip されていたぜ…。
…まあ大丈夫かな。
$ perl -MDBI $dbh = DBI->connect('DBI:mysql:database=rightgo09;host=mysqlxxx.db.sakura.ne.jp', 'rightgo09','xxxxxxxxxxxx') or die; print "ok [$dbh]\n"; $dbh->disconnect; ok [DBI::db=HASH(0x283a4890)]
つながった。
とりあえずこんなとこか。