仕事に詰まって現実逃避。
元ネタはここ。
perldoc
が付いてなかったのが不満だったのと、単独での実行はいらない事と、親パスまでは決め打ちで良い事から、改造。
plenv
入れてあるので、その perl にて。
-
plenv
以外の使用を前提としない。 - 元の
perl
は、cpanm
,local::lib
が入っていること - 箱作る所だけ、下のスクリプト。
- 使用は、
plenv
まかせ。-
plenv shell
とか、plenv uninstall
とか、
-
- 外部コマンドのソースからのインストール時には、このスクリプトで作成した
perl
以外のperl
でインストールを。-
pod2man
あたりでトラブルの危険 -
Makefile
とか直接弄るんでもいいけど
-
実行
$ plenv versions
system
* 5.20.1 (set by PLENV_VERSION environment variable)
$ perl /PATH/TO/venv.pl oppai
$ plenv versions
system
* 5.20.1 (set by PLENV_VERSION environment variable)
oppai
$ plenv shell oppai
$ cpanm Acme::Oppai
$ plenv rehash
$ perldoc Acme::Oppai
# (略)
$ perl -MAcme::Oppai -le 'print Acme::Oppai->new->massage;'
_ ∩
( ゜∀゜)彡 おっぱい!おっぱい!
( ⊂彡
| |
し ⌒J
$ plenv uninstall oppai
ソース
venv.pl
# !/usr/bin/env perl
use strict;
use warnings;
use Config;
use File::Path qw(make_path);
die if ! defined $ENV{PLENV_ROOT} ;
die if ! defined $ARGV[0] ;
my $new_path = join q{/}, $ENV{PLENV_ROOT}, q{versions}, $ARGV[0] ;
my $new_bin = join q{/}, $new_path, q{bin} ;
my $new_perl = join q{/}, $new_bin, q{perl} ;
my $new_doc = join q{/}, $new_bin, q{perldoc} ;
my $new_cpanm = join q{/}, $new_bin, q{cpanm} ;
my $new_lib_dir = join q{/}, $new_path, q{lib}, q{perl5} ;
my $orig_bin = $Config{bin} ;
my $orig_perl = $Config{perlpath} ;
my $orig_doc = join q{/}, $orig_bin, q{perldoc} ;
my $orig_cpanm = join q{/}, $orig_bin, q{cpanm} ;
die if -T $orig_perl ;
die if -l $orig_perl ;
die if ! -f $orig_doc ;
die if ! -f $orig_cpanm ;
die if qx{$orig_doc -l local::lib} !~ m{^/.*?/lib\.pm$} ;
make_path $new_bin if ! -d $new_bin;
{
open my $fh, q{>}, $new_perl ;
print {$fh} <<"EOF" ;
# !/bin/sh
exec $orig_perl -Mlocal::lib=$new_path "\$\@"
EOF
close $fh ;
chmod 0755, $new_perl ;
}
{
open my $fh, q{>}, $new_cpanm ;
print {$fh} <<"EOF" ;
# !/bin/sh
exec $orig_cpanm --local-lib=$new_path "\$\@"
EOF
close $fh ;
chmod 0755, $new_cpanm ;
}
{
open my $fh, q{>}, $new_doc ;
print {$fh} <<"EOF" ;
# !/bin/sh
export PERL5LIB=$new_lib_dir
exec $orig_doc "\$\@"
EOF
close $fh ;
chmod 0755, $new_doc ;
}