21
Set yourself free from the system: managing non-system Perls Jose Luis Martínez Torres JLMARTIN Barcelona Perl Workshop 2014 @pplu_io

Plenv and carton

Embed Size (px)

DESCRIPTION

Managing different Perl environments with plenv and carton

Citation preview

Page 1: Plenv and carton

Set yourself free from

the system: managing

non-system Perls

Jose Luis Martínez Torres

JLMARTIN

Barcelona Perl Workshop 2014

@pplu_io

Page 2: Plenv and carton

System perl

Debian

squeeze: 5.10

wheezy: 5.14

jessie: 5.20

Redhat

RHEL5: 5.8

RHEL6: 5.10

RHEL7: 5.16

Page 3: Plenv and carton

The distribution perl is not what you

think it is

For Debian Perl 5.14

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

57

Page 4: Plenv and carton

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

Page 5: Plenv and carton

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

Page 6: Plenv and carton

Compile my own perl? Hard???

In the olden days it could be a challenge

Page 7: Plenv and carton

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)

Page 8: Plenv and carton

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

Page 9: Plenv and carton

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!

Page 10: Plenv and carton

Switching perls

(At the directory level)

plenv global 5.16.2

cd project1plenv local 5.14.0

./my_project

Page 11: Plenv and carton

My Modules!

carton to the rescue

Page 12: Plenv and carton

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

Page 13: Plenv and carton

Trick

carton exec $SHELL –l

#Perl will find your modules without invoking carton

Page 14: Plenv and carton

Handling failures

Page 15: Plenv and carton

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”

Page 16: Plenv and carton

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

Page 17: Plenv and carton

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

Page 18: Plenv and carton

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

Page 19: Plenv and carton

Thanks

Tokuhiro Matsuno for plenv

Tatsuhiko Miyagawa for carton

Page 20: Plenv and carton

Extra, Extra

Page 21: Plenv and carton

Extra, Extra: Here’s the cat