Skip to content

Instantly share code, notes, and snippets.

@gypark
Created February 22, 2012 19:46
Show Gist options
  • Save gypark/1886853 to your computer and use it in GitHub Desktop.
Save gypark/1886853 to your computer and use it in GitHub Desktop.
수정한 ~/perl5/perlbrew/etc/bashrc
export PERLBREW_BASHRC_VERSION=0.41
[[ -z "$PERLBREW_ROOT" ]] && export PERLBREW_ROOT="$HOME/perl5/perlbrew"
[[ -z "$PERLBREW_HOME" ]] && export PERLBREW_HOME="$HOME/.perlbrew"
if [[ ! -n "$PERLBREW_SKIP_INIT" ]]; then
if [[ -f "$PERLBREW_HOME/init" ]]; then
. "$PERLBREW_HOME/init"
fi
fi
__perlbrew_reinit () {
if [[ ! -d "$PERLBREW_HOME" ]]; then
mkdir -p "$PERLBREW_HOME"
fi
echo '# DO NOT EDIT THIS FILE' >| "$PERLBREW_HOME/init"
command perlbrew env $1 >> "$PERLBREW_HOME/init"
. "$PERLBREW_HOME/init"
__perlbrew_set_path
}
__perlbrew_set_path () {
[[ -n $(alias perl 2>/dev/null) ]] && unalias perl 2>/dev/null
export PATH_WITHOUT_PERLBREW="$(perl -e 'print join ":", grep { index($_, $ENV{PERLBREW_ROOT}) } split/:/,$ENV{PATH};')"
if [[ -z "$PERLBREW_PATH" ]]; then
export PERLBREW_PATH="$PERLBREW_ROOT/bin"
fi
export PATH="$PERLBREW_PATH:$PATH_WITHOUT_PERLBREW"
export MANPATH_WITHOUT_PERLBREW="$(perl -e 'print join ":", grep { index($_, $ENV{PERLBREW_ROOT}) } split/:/,$ENV{MANPATH};')"
if [ -n "$PERLBREW_MANPATH" ]; then
export MANPATH="$PERLBREW_MANPATH:$MANPATH_WITHOUT_PERLBREW"
else
export MANPATH="$MANPATH_WITHOUT_PERLBREW"
fi
}
__perlbrew_set_path
# local::lib와 혼용을 위한 설정
# 아래 두 변수의 값을 자신의 환경에 맞춰 적어줌
_LOCAL_LIB_INC="$HOME/local/perl/lib/perl5"
_LOCAL_LIB_ROOT="$HOME/local/perl"
# local::lib 에 의한 설정을 제거
__unset_local_lib () {
export PERL5LIB="$PERL5LIB"
eval $(perl -I$_LOCAL_LIB_INC -Mlocal::lib=--deactivate-all,$_LOCAL_LIB_ROOT)
}
# local::lib 설정 적용
__set_local_lib () {
eval $(perl -I$_LOCAL_LIB_INC -Mlocal::lib=--deactivate-all,$_LOCAL_LIB_ROOT)
export _MY_PERL5LIB="$PERL5LIB"
eval $(perl -I$_LOCAL_LIB_INC -Mlocal::lib=$_LOCAL_LIB_ROOT)
if [ -n "$_MY_PERL5LIB" ]; then
export PERL5LIB="$(perl -e 'print join ":", $ENV{_MY_PERL5LIB}, grep { index($_, $ENV{_MY_PERL5LIB}) } split/:/,$ENV{PERL5LIB};')"
fi
unset _MY_PERL5LIB
}
perlbrew () {
local exit_status
local short_option
export SHELL
if [[ $1 == -* ]]; then
short_option=$1
shift
else
short_option=""
fi
case $1 in
(use)
if [[ -z "$2" ]] ; then
if [[ -z "$PERLBREW_PERL" ]] ; then
echo "Currently using system perl"
else
echo "Currently using $PERLBREW_PERL"
fi
else
code=$(command perlbrew env $2);
if [ -z "$code" ]; then
exit_status=1
else
OLD_IFS=$IFS
IFS="$(echo -e "\n\r")"
for line in $code; do
eval $line
done
IFS=$OLD_IFS
__unset_local_lib
__perlbrew_set_path
fi
fi
;;
(switch)
if [[ -z "$2" ]] ; then
command perlbrew switch
else
__unset_local_lib
perlbrew use $2
__perlbrew_reinit $2
fi
;;
(off)
unset PERLBREW_PERL
eval `perlbrew env`
__perlbrew_set_path
__set_local_lib
echo "perlbrew is turned off."
;;
(switch-off)
unset PERLBREW_PERL
__perlbrew_reinit
__set_local_lib
echo "perlbrew is switched off."
;;
(*)
command perlbrew $short_option "$@"
exit_status=$?
;;
esac
hash -r
return ${exit_status:-0}
}
--- bashrc.original 2012-02-23 01:48:35.000000000 +0900
+++ bashrc 2012-02-23 04:40:10.000000000 +0900
@@ -39,6 +39,28 @@
}
__perlbrew_set_path
+# local::lib와 혼용을 위한 설정
+# 아래 두 변수의 값을 자신의 환경에 맞춰 적어줌
+_LOCAL_LIB_INC="$HOME/local/perl/lib/perl5"
+_LOCAL_LIB_ROOT="$HOME/local/perl"
+
+# local::lib 에 의한 설정을 제거
+__unset_local_lib () {
+ export PERL5LIB="$PERL5LIB"
+ eval $(perl -I$_LOCAL_LIB_INC -Mlocal::lib=--deactivate-all,$_LOCAL_LIB_ROOT)
+}
+
+# local::lib 설정 적용
+__set_local_lib () {
+ eval $(perl -I$_LOCAL_LIB_INC -Mlocal::lib=--deactivate-all,$_LOCAL_LIB_ROOT)
+ export _MY_PERL5LIB="$PERL5LIB"
+ eval $(perl -I$_LOCAL_LIB_INC -Mlocal::lib=$_LOCAL_LIB_ROOT)
+ if [ -n "$_MY_PERL5LIB" ]; then
+ export PERL5LIB="$(perl -e 'print join ":", $ENV{_MY_PERL5LIB}, grep { index($_, $ENV{_MY_PERL5LIB}) } split/:/,$ENV{PERL5LIB};')"
+ fi
+ unset _MY_PERL5LIB
+}
+
perlbrew () {
local exit_status
local short_option
@@ -70,6 +92,7 @@
eval $line
done
IFS=$OLD_IFS
+ __unset_local_lib
__perlbrew_set_path
fi
fi
@@ -79,6 +102,7 @@
if [[ -z "$2" ]] ; then
command perlbrew switch
else
+ __unset_local_lib
perlbrew use $2
__perlbrew_reinit $2
fi
@@ -88,12 +112,14 @@
unset PERLBREW_PERL
eval `perlbrew env`
__perlbrew_set_path
+ __set_local_lib
echo "perlbrew is turned off."
;;
(switch-off)
unset PERLBREW_PERL
__perlbrew_reinit
+ __set_local_lib
echo "perlbrew is switched off."
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment