Alister West

home is where your code is ...

Perl + local::lib + cpanm

Keeping your application perl libs seperate from your system perl.

Get cpanm (App::cpanminus) and local::lib

Install Cpan-Minus and local::lib via bootstrap (how-can-i-use-cpan-as-a-non-root-user)

# Module::Metadata will probably complain unless PERL5LIB is set.
export PERL5LIB=~/perl5/lib/perl5

# --verbose flag necessary for local::lib
curl -L http://cpanmin.us | perl - -l ~/perl5 --verbose App::cpanminus local::lib

eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)
echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >> ~/.bash_profile

echo $PERL5LIB
# /var/home/alister/perl5/lib/perl5/x86_64-linux:/var/home/alister/perl5/lib/perl5

echo "!*! Remember to add PERL5LIB=$HOME/perl5/lib/perl5 to your crontab !*!"

Carton - Perl module bundling

Carton makes it easy to install and manage library dependencies within a project. Lets have a look (with carton v0.9.15) ...

# make sure local::lib and carton are installed in system lib (or ~perl5).
cpanm local::lib Carton

# *cpanfile* controls which files to install
cd my_project
echo "requires 'Acme::Time::Baby';" >> cpanfile
carton install

# Keep the carton files in version-control, not the moudles.
echo .carton/ >> .gitignore
echo local/   >> .gitignore
git add cpanfile carton.snapshot

Script using carton bundled libs ..

#!/usr/bin/env perl
# bin/my_script.pl
use FindBin qw/$Bin/;
use local::lib "$Bin/../local";
use Acme::Time::Baby;
print babytime;

The result...

my_project
|-- bin
|   `-- my_script.pl
|-- .gitignore
|-- carton.lock
|-- cpanfile 
`-- local
    `-- lib
        `-- perl5
            `-- Acme
                `-- Time
                    `-- Baby.pm

App::perlbrew

Use perlbrew to get local perl install > 5.10.0!

TMPDIR=~/tmp cpanm App::perlbrew
perlbrew install
perlbrew init

# *init* will tell you the paths to put here.
echo 'source ~/perl5/perlbrew/etc/bashrc' | sh
echo 'source ~/perl5/perlbrew/etc/bashrc' >>~/.bashrc

perlbrew install --notest perl-stable
perlbrew available
perlbrew use perl-5.16.3

...

perlbrew off
By Alister West