Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions libexec/plenv-install-cpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
#
# Summary: Install cpm
#
# Usage: plenv install-cpm
#
# Install cpm to current perl version
#
set -e
[ -n "$PLENV_DEBUG" ] && set -x

if [ -z "$PLENV_ROOT" ]; then
PLENV_ROOT="${HOME}/.plenv"
fi

function parse_options ()
{
OPTIONS=();
ARGUMENTS=();
local arg option index;
for arg in "$@";
do
if [ "${arg:0:1}" = "-" ]; then
if [ "${arg:1:1}" = "-" ]; then
OPTIONS[${#OPTIONS[*]}]="${arg:2}";
else
index=1;
while option="${arg:$index:1}"; do
[ -n "$option" ] || break;
OPTIONS[${#OPTIONS[*]}]="$option";
index=$(($index+1));
done;
fi;
else
ARGUMENTS[${#ARGUMENTS[*]}]="$arg";
fi;
done
};

usage() {
# We can remove the sed fallback once plenv 0.4.0 is widely available.
plenv-help install-cpm 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
[ -z "$1" ] || exit "$1"
}

unset VERBOSE

# CURRENT=$(cd $(dirname $0) && pwd)
# PERL_BUILD=$CURRENT/perl-build

# exec $PERL_BUILD $*
parse_options "$@"
for option in "${OPTIONS[@]}"; do
case "$option" in
"h" | "help" )
usage 0
;;
* )
usage 1
;;
esac
done

PLENV_INSTALL_CPANM=${PLENV_INSTALL_CPANM:--p}
curl ${PLENV_INSTALL_CPANM} -L http://git.io/cpm | plenv exec perl - install -g App::cpm
plenv rehash
28 changes: 28 additions & 0 deletions plenv.d/rehash/rehash_cpm.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -e

CPM_SHIM_PATH="$SHIM_PATH/cpm"

command -p cat > "$CPM_SHIM_PATH" <<SH
#!/usr/bin/env bash
set -e
[ -n "\$PLENV_DEBUG" ] && set -x

program="\${0##*/}"

export PLENV_ROOT="$PLENV_ROOT"
"$(command -v plenv)" exec "\$program" "\$@"
rc=\$?
for arg in \$@
do
case \$arg in
'-g'|'--global')
"$(command -v plenv)" rehash
exit \$rc
;;
esac
done
exit \$rc
SH

command -p chmod +x "$CPM_SHIM_PATH"