Skip to content

Commit

Permalink
Merge pull request #8 from merrilymeredith/use-perl-install
Browse files Browse the repository at this point in the history
Use perl-install rather than Perl-Build, which requires a system perl
  • Loading branch information
ouest authored Feb 19, 2022
2 parents 171724f + 54311ea commit bbe620f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
10 changes: 5 additions & 5 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ install_perl() {
echoerr "For a list of available versions, see \`asdf list-all perl\`."
exit 1
fi
install_or_update_perl_build
install_or_update_perl_install

local build_args=("-j${concurrency}" -Dusethreads)
local build_args=("-j=${concurrency}" -Dusethreads)
if is_development_version "$version"; then
build_args+=(-Dusedevel --symlink-devel-executables)
fi
echo "perl-build ${build_args[@]} $version $install_path"
$(perl_build_path) "${build_args[@]}" "$version" "$install_path"
echo "perl-install ${build_args[@]} $version $install_path"
$(perl_install_bin) "${build_args[@]}" "$version" "$install_path"
}

install_cpanm() {
Expand Down Expand Up @@ -75,7 +75,7 @@ is_development_version() {
return 0
}

ensure_perl_build_installed
ensure_perl_install_installed
install_perl "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
install_cpanm "$ASDF_INSTALL_PATH"
install_default_perl_modules
4 changes: 2 additions & 2 deletions bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
source "$(dirname "$0")/utils.sh"

list_all() {
install_or_update_perl_build
$(perl_build_path) --definitions | tac | tr '\n' ' '
install_or_update_perl_install
$(perl_install_bin) --list-all | tac | tr '\n' ' '
}

list_all
55 changes: 26 additions & 29 deletions bin/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,53 @@ echoerr() {
printf "\033[0;31m%s\033[0m" "$1" >&2
}

ensure_perl_build_installed() {
if [ ! -f "$(perl_build_path)" ]; then
download_perl_build
ensure_perl_install_installed() {
if [ ! -f "$(perl_install_bin)" ]; then
download_perl_install
fi
}

download_perl_build() {
echo "Downloading perl-build..." >&2
local plenv_url="https://github.com/tokuhirom/plenv.git"
local perl_build_url="https://github.com/tokuhirom/Perl-Build.git"
git clone $plenv_url "$(plenv_path)"
git clone $perl_build_url "$(plenv_path)/plugins/perl-build/"
download_perl_install() {
echo "Downloading perl-install..." >&2
local perl_install_url="https://github.com/skaji/perl-install.git"
git clone --depth 1 $perl_install_url "$(perl_install_checkout)"
}

perl_build_path() {
echo "$(plenv_path)/plugins/perl-build/bin/perl-build"
perl_install_checkout() {
echo "$(dirname $(dirname $0))/perl-install"
}

update_perl_build() {
cd "$(plenv_path)" && git fetch && git reset --hard origin/master > /dev/null 2>&1
perl_install_bin() {
echo "$(perl_install_checkout)/perl-install"
}

plenv_path() {
echo "$(dirname $(dirname $0))/plenv"
update_perl_install() {
cd "$(perl_install_checkout)" && git fetch && git reset --hard origin/HEAD > /dev/null 2>&1
}

plenv_update_timestamp_path() {
echo "$(dirname $(dirname "$0"))/plenv_last_update"
update_timestamp_path() {
echo "$(perl_install_checkout)/.git/FETCH_HEAD"
}

plenv_should_update() {
update_timeout=3600
update_timestamp_path=$(plenv_update_timestamp_path)
should_update() {
local update_timeout=3600
local update_timestamp_path=$(update_timestamp_path)

if [ ! -f "$update_timestamp_path" ]; then
return 0
fi

last_update=$(cat "$update_timestamp_path")
current_timestamp=$(date +%s)
invalidated_at=$(($last_update + $update_timeout))
local last_update="$(date -r "$update_timestamp_path" +%s)"
local current_timestamp="$(date +%s)"
local invalidated_at="$(($last_update + $update_timeout))"

[ $invalidated_at -lt $current_timestamp ]
}

install_or_update_perl_build() {
if [ ! -f "$(perl_build_path)" ]; then
download_perl_build
elif plenv_should_update; then
update_perl_build
date +%s > "$(plenv_update_timestamp_path)"
install_or_update_perl_install() {
if [ ! -f "$(perl_install_bin)" ]; then
download_perl_install
elif should_update; then
update_perl_install
fi
}

0 comments on commit bbe620f

Please sign in to comment.