Plenv and carton

Preview:

DESCRIPTION

Managing different Perl environments with plenv and carton

Citation preview

Set yourself free from

the system: managing

non-system Perls

Jose Luis Martínez Torres

JLMARTIN

Barcelona Perl Workshop 2014

@pplu_io

System perl

Debian

squeeze: 5.10

wheezy: 5.14

jessie: 5.20

Redhat

RHEL5: 5.8

RHEL6: 5.10

RHEL7: 5.16

The distribution perl is not what you

think it is

For Debian Perl 5.14

$ /usr/bin/perl -V | grep DEBPKG | wc -l

57

The distribution perl is not what you

think it is

http://perlbuzz.com/2008/08/red-hats-patch-slows-down-overloading-in-

perl.html

Some investigation revealed that there’s a long standing bug in Redhat Perl that

causes *severe* performance degradation on code that uses the bless/overload

combo. The thread on this is here:

https://bugzilla.redhat.com/show_bug.cgi?id=379791

The distribution perl is not what you

think it is

http://perlbuzz.com/2008/08/red-hats-patch-slows-down-overloading-in-

perl.html

Some investigation revealed that there’s a long standing bug in Redhat Perl that

causes *severe* performance degradation on code that uses the bless/overload

combo. The thread on this is here:

https://bugzilla.redhat.com/show_bug.cgi?id=379791

Compile my own perl? Hard???

In the olden days it could be a challenge

Compile my own perl: Now

No need for root!

You only need compiler (and libs)

apt-get install build-essential

Now you choose: perlbrew / plenv

I’ll use plenv today… (like it more)

Plenv to the rescue

https://github.com/tokuhirom/plenv/

git clone git://github.com/tokuhirom/plenv.git ~/.plenvecho 'export PATH="$HOME/.plenv/bin:$PATH"' >> ~/.profileecho 'eval "$(plenv init -)"' >> ~/.profileexec $SHELL –lgit clone git://github.com/tokuhirom/Perl-Build.git ~/.plenv/plugins/perl-build/plenv install 5.20.1# wait for it…plenv rehashplenv install-cpanm

A Word of Caution

#!/usr/bin/perl is soooooooooooo 2010…

#!/usr/bin/env perl is the new #!/usr/bin/perl

It’ll help your programs find the correct perl!

Switching perls

(At the directory level)

plenv global 5.16.2

cd project1plenv local 5.14.0

./my_project

My Modules!

carton to the rescue

Carton

cpanm Carton

vi cpanfilerequires ‘Module1’;requires ‘Module2’;

carton install

# Magic happens… All modules get installed# Also generates a cpanfile.snapshot with all modules and versionsinstalled

carton exec ./my_project

Trick

carton exec $SHELL –l

#Perl will find your modules without invoking carton

Handling failures

Handling failures

Look at the log

Normally some headers missing

DBD::mysql requires libmysqlclient-dev to be installed (Debian/Ubuntu)

SSL related modules usually require OpenSSL: libssl-dev (Debian/Ubuntu)

Some XML related modules require libexpat1-dev libxml2-dev

Find a missing .h file in the compiler errors, and find which package it belongs to

Rinse and Repeat “carton install”

BUNDLE!!!

carton bundle

- Look at your vendor/cache dir!

- Look at vendor/bin!

./vendor/bin/carton (fat packed version)

I personally add the vendor directory to version control

Smells like we get repeatable

DEPLOY!!!

carton install# install all modules that don’t meet cpanfile requirements

carton install --deployment# installs all versions from cpanfile.snapshot

carton install --deployment --cached# installs versions from the vendor/cache

Conclusions

plenv controls your Perl version

carton controls your dependencies

Enables

Repeatablility

Independant interpreters for different needs (think of microservices)

Testing new versions

Using up-to-date modules with no fear of CPAN breakage

Thanks

Tokuhiro Matsuno for plenv

Tatsuhiko Miyagawa for carton

Extra, Extra

Extra, Extra: Here’s the cat

Recommended