長らく離れていたが最近やるようになったので、ちょっと整理をすることにする
http://www.perlbrew.pl/ pythonbrewがあるようにperlにもある。こっちが本家かも知れないけど
curl -kL http://install.perlbrew.pl | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 102 1022 102 1022 0 0 504 0 0:00:02 0:00:02 --:--:-- 5084 ## Download the latest perlbrew ## Installing perlbrew The perlbrew is installed as: ~/perl5/perlbrew/bin/perlbrew You may trash the downloaded /tmp/perlbrew-1415 from now on. Perlbrew environment initiated under ~/perl5/perlbrew Append the following piece of code to the end of your ~/.bash_profile and start a new shell, perlbrew should be up and fully functional from there: source ~/perl5/perlbrew/etc/bashrc For further instructions, simply run `perlbrew` to see the help message. Happy brewing! ## Installing patchperl ## Done.
とりあえずこれをはっつけておけばなんとか使えるはず
perlbrew <command> [options] [arguments] Commonly used commands: available インストール可能なperlバージョン一覧 init Initialize perlbrew environment. install Install perl list List installed perls use Use the specified perl in current shell switch Permanently use the specified perl as default mirror Pick a preffered mirror site off Permanently turn off perlbrew version Display version help Read more detail instructions
あとはlistとswitchさえ覚えておけばとりあえずはどうにかなるだろう
# thread使いたいのなら。使えなくてもいいんならこのオプションはいらない # test不要な場合は --notest をつければよい perlbrew install --notest perl-5.12.3 -Duseithreads
便利なのでインストールしておく。$HOME/perl5/perlbrew/bin/cpanm にインストールされる。local::libもついてくる模様
perlbrew install-cpanmhttp://mt.endeworks.jp/d-6/2010/08/perlbrew.html とかわかりやすい
モジュールをアンインストールする場合
詳細はhttp://search.cpan.org/~xaicron/App-pmuninstall/li...参照
cat ./perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux-thread-multi/auto/Mojolicious/.packlist | xargs rmのように.packlistに記述されているファイルを削除でもいいけど、ツールを使いところなのでインストールしておく
cpanm App::pmuninstall普通は
# -f 問い合わせなし # -v verbose pm-uninstall Mojoliciousのように使うとよい
詳細はhttp://search.cpan.org/~xaicron/App-pmuninstall/li...参照
pythonでいうvirtualenvのような感じ?
cpamn local::lib使い方は
perl -Mlocal::libとすれば
export PERL_LOCAL_LIB_ROOT="/home/kurt/perl5"; export PERL_MB_OPT="--install_base /home/kurt/perl5"; export PERL_MM_OPT="INSTALL_BASE=/home/kurt/perl5"; export PERL5LIB="/home/kurt/perl5/lib/perl5/x86_64-linux-thread-multi:/home/kurt/perl5/lib/perl5"; export PATH="/home/kurt/perl5/bin:$PATH";などと出力されるので
eval $(perl -Mlocal::lib)としておけばよい。local::libに引数を与えるとそのディレクトリに対してインストールすることが可能。簡単な切り替え方法などはhttp://unknownplace.org/memo/2010/03/01/1/に書いている
local::libの実行結果を.bashrcなどに書いておくのもありだが、そうしたくないケースも無いことも無いのでそういう場合はscriptに
use Findbin qw($Bin); use local::lib qw($Bin);などのようにlocal::lib対象ディレクトリを引数に指定した状態でuseするとよい
とりあえずlocal::libの設定を無効にしたい場合
eval $(perl -Mlocal::lib=--deactivate-all) # or eval $(perl -Mlocal::lib=--deactivate,/path/to/dir)
インストールされているモジュールの一覧を取得
perl -MExtUtils::Installed -E 'say for ExtUtils::Installed->new->modules'以下のように出力結果をファイルに保存して、cpanmに渡せば別環境で同じモジュールをインストールすることが可能とか思った
perl -MExtUtils::Installed -E 'say for ExtUtils::Installed->new->modules' > module-list.txt cat module-list.txt | cpanmhttp://d.hatena.ne.jp/ZIGOROu/20090416/1239863572詳しい
インストールされているモジュールの最新版を知ることができる
cpanm App::cpanoutdated実行すると以下のように表示される
cpan-outdated J/JD/JDHEDDEN/threads-1.85.tar.gz J/JD/JDHEDDEN/threads-shared-1.40.tar.gz Z/ZE/ZEFRAM/Time-HiRes-1.9724.tar.gz S/SA/SADAHIRO/Unicode-Collate-0.78.tar.gzcpanmを組み合わせれば表示されたモジュールを最新版にupdateすることができる
cpan-outdated | cpanm
作ったパッケージをPAUSEにアップロードする
cpanm CPAN::Uploadercpan-uploadというコマンドがインストールされるのでそれを使えばよい
cpan-upload --user=<USER> ~/path/to/package.tar.gz$HOME/.pause というファイルを置いておけばオプションなしでもいけそう
user <USER> password <PASS>
https://pause.cpan.org にログインして作成したモジュールをアップしなくてもよくなる。
http://search.cpan.org/~neilb/cpan-upload/cpan-upl...
http://search.cpan.org/~neilb/cpan-upload/cpan-upl...
cpan-upload -verbose -mailto aaa@bbb -user xxxx -password xxxxx App-CLI-Extension-0.1.tar.gzとするだけでよい。結果が以下のように表示される
cpan-upload v2.2 Using FTP to upload files to PAUSE uploading file "App-CLI-Extension-0.1.tar.gz" registering upload with PAUSE web server POSTing upload for App-CLI-Extension-0.1.tar.gz PAUSE add message sent ok [200] 1 file uploaded successfully.ちゃんと登録後、メールが来てたり、CPANのアップロード後の状況を確認できるログ表示画面にもアップロードできていることが確認できる
Test::Perl::Criticのテストを行ってくれるサイト。モジュール作る前にチェックしておくとよい
http://perlcritic.com/
ちなみにPerl::Criticをインストールするとperlcriticというコマンドが付属するのでそっちもつかえると思う
http://perlcritic.com/
ちなみにPerl::Criticをインストールするとperlcriticというコマンドが付属するのでそっちもつかえると思う
module-setupなどでモジュールを作成するとperlcriticのテストケースも自動で作成される。このモジュールがあるとテストが自動されるわけだが、かなり厳しいのでそういう場合はxt/perlcriticrcに
[TestingAndDebugging::ProhibitNoStrict] allow=refs # for mkdir $dir, 0777 [-ValuesAndExpressions::ProhibitLeadingZeros] # we do eval $asset_pl a lot [-BuiltinFunctions::ProhibitStringyEval] # none use strict [TestingAndDebugging::RequireUseStrict] equivalent_modules = Mojo::Base Mojolicious::Plugin DBIx::Skinny DBIx::Skinny::Row # none use warnings [TestingAndDebugging::RequireUseWarnings] equivalent_modules = Mojo::Base Mojolicious::Plugin DBIx::Skinny DBIx::Skinny::Rowなどと書いておく。該当箇所には
## no criticと書いておくのがちょっとしたルール。http://search.cpan.org/~thaljef/Perl-Critic/lib/Pe...みるとなんとなくわかるかも
Perl::Tidyをインストールするとついてくるツール。きれいにフォーマットしてくれる。最近のperlだと普通にインストールされているかも
# -o /path/to/file を指定すると出力先を指定できる。指定なしの場合は元のファイル名.tidyみたいなファイル名になる perltidy /path/to/fileきれいなpodも出力できる
perltidy --html /path/to/file
cpanm App::CLI::Extension cpanm HOLLY/App-CLI-Extension-1.3.tar.gz cpanm /path/to/archive.tar.gz cpanm http://search.cpan.org/CPAN/authors/id/H/HO/HOLLY/App-CLI-Extension-1.3.tar.gz
pmsetupの後継的なやつ(っていうかだいぶ前にでてたらしい)。CPANPLUSをインストールしているのなら
cpanm Module::Setupでインストール可能。まとめはのちほど。
- http://blog.yappo.jp/yappo/archives/000608.html
- http://perl-users.jp/articles/advent-calendar/2009...
module-setup --init module-setup --init --flavor-class=XS xs最低限こんだけはしとくこと
ExtUtils::MakeMakerの後継。ちょっとしたhackや使い方は
- http://perl-users.jp/articles/advent-calendar/2010...
- http://search.cpan.org/dist/Module-Install/lib/Mod... preamble,postambleはMakefileに命令文を追加できるので覚えておく
cpanm install Module::Install
dummy http serverをmake testの時に起動させる用途で使う。内部はTest::TCPつかっているのかな。*.tなファイルで使う
use Test::More; use Test::Fake::HTTPD; use HTTP::Response; use JSON::Any; use LWP::UserAgent; my $httpd = run_http_server { return HTTP::Response->new(200, "ok", ["Content-Type" => "application/json"], JSON::Any->new->encode({message: "hello"})); }; my $httpd = run_http_server { $fake_res }; my $ua = LWP::UserAgent->new; my $content = $ua->get($httpd->endpoint); # あとは自分の好きなテスト
もうひとつhttpなテストするときのねた。こっちはdummy http serverを起動しないパターン
- perlbrew
- local::lib
cpanm install \ Perl::Tidy \ Perl::Critic \ Module::Install \ Module::Install::AuthorTests \ Module::Install::ReadmePodFromPod \ Module::Install::Repository \ Module::Install::GithubMeta \ Test::Spelling \ Test::Perl::Critic \ Test::Pod
もはや古いのもあるだろうけど
- Class::Accessor
- Class::Data::Inheritable
- Class::Data::Accessor
- Class::Trigger
- DBD::Mock
- Devel::NYTprof
- FindBin::Real
- IPC::Cmd
- IPC::Run
- IPC::Open2
- IPE::Open3
- Path::Class
- Proc::PID::File
- Parallel::ForkManager Parallel::Preforkというものもある
- Term::Prompt
- Sub::Install
- Class::C3(NEXTのかわりね) 5.10.0からはmro "c3"とするといいみたい。でその架け橋となるのがMRO::Compat
- UNIVERSAL::require
- Module::Pluggable
- Log::Dispatch::Config
- Regexp::Common
タグ
最新コメント