Skip to content

Instantly share code, notes, and snippets.

@sstadick
Last active February 14, 2020 10:07
Show Gist options
  • Select an option

  • Save sstadick/ae60ceb5fc6b647d8700d8a9bf7211ab to your computer and use it in GitHub Desktop.

Select an option

Save sstadick/ae60ceb5fc6b647d8700d8a9bf7211ab to your computer and use it in GitHub Desktop.
Using a combo of plenv and carton seems to be the way to go.
Goals (something like virtualenv + pip):
1. Leave the system Perl alone.
2. Install any Perl i choose.
And even switch between installed Perls
Either globally or on a per-project page
4. Manage Perl module dependencies within the project’s git repo.
Steps:
Run the script below from the project dir to get set up with plenv, carton, and perlbuild, pass in perl version to use (5.10.1)
Note that the script can be modified so it doesn't set up a local install right away
plenv local 5.10.1
Check local version: perl -v
Create cpanfile to manage modules
echo 'requires "Mojolicious", "7.05";' >> cpanfile
carton install
That will create a local dir that contains all installed modules, as well as a cpanfile.snapshot that can be added to git.
set up .gitignore file
echo local/ >> .gitignore
Run stuff using 'carton exec perl ....'
Tools:
plenv: https://github.com/tokuhirom/plenv
carton: https://github.com/perl-carton/carton
Perl-Build: https://github.com/tokuhirom/Perl-Build
How To's:
plenv only: http://www.dagolden.com/index.php/2390/setting-up-a-perl-development-environment-with-plenv/
plenv and carton: https://gist.github.com/revmischa/7438068
Covers it all: http://kappataumu.com/articles/modern-perl-toolchain-for-web-apps.html ← This one is awesome when used with the example script below.
Other:
Plugins to make it more like perlbrew: https://github.com/miyagawa/plenv-contrib
Good starting script: https://gist.github.com/revmischa/7438068 (plenv, Perl-Build Plugin, carton)
#############################################################
#!/bin/bash
# installs plenv, perl, carton, cpanminus, sets up environment in .bash_profile
# from https://github.com/tokuhirom/plenv#readme
PLENV_PERL_VERSION=$1
if [[ -n "$PERL_MB_OPT" ]]; then
echo "You must unset your local::lib environment variables first"
echo "Edit your ~/.bash_profile or ~/.bashrc and remove any references"
echo "to local::lib or export PERL*..."
exit 1
fi
echo " - Building perl environment -"
# get plenv latest
echo " + Cloning latest plenv..."
git clone git://github.com/tokuhirom/plenv.git ~/.plenv
echo " + Updating .bash_profile with plenv bin and perl binary shims..."
PLENV_PATH='export PATH="$HOME/.plenv/bin:$PATH"'
PLENV_INIT='eval "$(plenv init -)"'
echo $PLENV_PATH >> ~/.bash_profile # add plenv to path
echo $PLENV_INIT >> ~/.bash_profile # shims and autocomplete
# make the above available for the rest of this script
eval $PLENV_PATH
eval $PLENV_INIT
echo " + Cloning perl-build..."
git clone git://github.com/tokuhirom/Perl-Build.git ~/.plenv/plugins/perl-build/
echo " + Building perl ${PLENV_PERL_VERSION}..."
plenv install $PLENV_PERL_VERSION -Dusethreads
echo " + Switching to $PLENV_PERL_VERSION"
plenv local $PLENV_PERL_VERSION
echo " + Installing cpanminus..."
plenv install-cpanm
echo " + Installing carton..."
cpanm Carton
echo "plenv installation complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment