Skip to content

Instantly share code, notes, and snippets.

@dolmen
Created July 27, 2012 12:39
Show Gist options
  • Save dolmen/3187732 to your computer and use it in GitHub Desktop.
Save dolmen/3187732 to your computer and use it in GitHub Desktop.
My perl environment builder: creates ~/.perl/profile to be called in ~/.bash_profile
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Getopt::Long;
my $CPAN_MIRROR = 'http://distrib-coffee.ipsl.jussieu.fr/pub/mirrors/cpan/';
GetOptions("mirror=s" => \$CPAN_MIRROR);
my $DIR = $ARGV[0] // "$ENV{HOME}/.perl";
-d $DIR or mkdir $DIR or die "Can't create $DIR";
# TODO CPAN.pm setup
# TODO créer un lien ~/.cpan -> ~/.local/share/.cpan
# -d "$ENV{HOME}/.local/share" or mkdir "$ENV{HOME}/.local/share/.cpan";
# TODO CPAN setup
# o conf build_requires_install_policy yes
# o conf prerequisites_policy follow
open my $profile, '>', "$DIR/profile" or die;
print $profile <<EOF;
#
# Add this line to ~/.bash_profile:
# . ~/.perl/profile
#
PERL_LOCAL_LIB_ROOT="\${PERL_LOCAL_LIB_ROOT:+\${PERL_LOCAL_LIB}:}$DIR"
# Keep bindoc as it is useful to have man pages for commands
PERL_MB_OPT="--install_base '$DIR' --install_path libdoc= --install_path libhtml= --install_path binhtml="
# Keep INSTALLMAN1DIR as it useful to have man pages for commands
PERL_MM_OPT="INSTALL_BASE=$DIR INSTALLMAN3DIR=none"
PERL5LIB="$DIR/lib/perl5"
MANPATH="$DIR/man\${MANPATH:+: }\${MANPATH}"
[[ ":\$PATH:" = *:$DIR/bin:* ]] || PATH="$DIR/bin:\$PATH"
PERL_CPANM_OPT="-l $DIR --mirror $CPAN_MIRROR"
PERLBREW_ROOT="$DIR/perlbrew"
export PERL5LIB PERL_LOCAL_LIB_ROOT PERL_MB_OPT PERL_MM_OPT PERL_CPANM_OPT PERLBREW_ROOT
# TODO: fix PERL5LIB when perlbrew is started
#[[ -d "\$PERLBREW_ROOT" ]] && . "\$PERLBREW_ROOT"/etc/bashrc
EOF
close $profile;
# Install Perlbrew
unless (-x "$DIR/perlbrew/bin/perlbrew") {
$ENV{PERLBREW_ROOT} = "$DIR/perlbrew";
system('curl -kL http://install.perlbrew.pl | bash');
# TODO setup the mirror for perlbrew to point to $CPAN_MIRROR
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment