Skip to content

Commit

Permalink
allow modification of version via hooks
Browse files Browse the repository at this point in the history
The new internal version-munge command is used to modify the version when
read from a version file or when specified on the command line via the
shell, local, or global commands.  The version stored in a version
file is not modified.

This allows the user to modify the version dependent upon the existing
environment.  For example, if the PLENV_ROOT directory is shared
across multiple platforms with different OS's, hardware, or ABI's, one
could modify the version at run-time to include a platform specific
suffix, allowing a single version stored in a version file to
accomodate multiple platforms.

For example, if the hostname is used to distinguish the platform, e.g.
on each host Perl was installed with

    % plenv install --as 5.22-$(hostname) 5.22

Then with the following hook:

    % cat ~/.plenv/plenv.d/version-munge/hostname.bash
    #!/bin/bash

    if [[ "$version" != --* ]]; then

	suffix=$(hostname)

	plenv-prefix "$version-$suffix" 1> /dev/null \
	    && version="$version-$suffix"

    fi

Setting

    % plenv global 5.22

will set ~/.plenv/version to 5.22 and the hook will ensure that
each host will see its own version.
  • Loading branch information
djerius committed Feb 25, 2016
1 parent 907a8ad commit cc0f754
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions libexec/plenv-sh-shell
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ version="$1"
shell="${PLENV_SHELL:-$SHELL}"
shell="${shell##*/}"

version=$(plenv-version-munge $version)

if [ -z "$version" ]; then
if [ -z "$PLENV_VERSION" ]; then
echo "plenv: no shell-specific version configured" >&2
Expand Down
6 changes: 5 additions & 1 deletion libexec/plenv-version-file-read
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
# Reads the first non-whitespace word from the specified version file,
# careful not to load it whole in case there's something crazy in it.
if [ -e "$1" ]; then
command -p awk 'BEGIN {rc=1} NF > 0 { print $1 ; exit rc=0 } END { exit rc }' "$1"

version=$(command -p awk 'BEGIN {rc=1} NF > 0 { print $1 ; exit rc=0 } END { exit rc }' "$1")

plenv-version-munge "$version"

fi
2 changes: 1 addition & 1 deletion libexec/plenv-version-file-write
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ -z "$PLENV_VERSION" ] || [ -z "$PLENV_VERSION_FILE" ]; then
fi

# Make sure the specified version is installed.
plenv-prefix "$PLENV_VERSION" >/dev/null
plenv-prefix "$(plenv-version-munge \"$PLENV_VERSION\")" >/dev/null

# Write the version out to disk.
echo "$PLENV_VERSION" > "$PLENV_VERSION_FILE"
17 changes: 17 additions & 0 deletions libexec/plenv-version-munge
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Summary: munge the passed Perl version using plugins

version="$1"
if [ "$version" != '' ]; then

OLDIFS="$IFS"
IFS=$'\n' scripts=(`plenv-hooks version-munge`)
IFS="$OLDIFS"

for script in "${scripts[@]}"; do
source "$script"
done

fi

echo "$version"

0 comments on commit cc0f754

Please sign in to comment.