Perl virtual environment
By Pierre Palatin on Friday, January 29 2010, 20:30 - Permalink
While Python as the extremely useful virtualenv tool, I haven't found anything similar for Perl. What I want is quite simple: being able to test random perl tools. They usually depend on a various set of libraries, some of them either too old on my system or not even present. Most of the time, I just want to test the tool, so installing random perl modules system-wide is not an option. Moreover, I really don't like having to install something system-wide which is not coming as a package for my distribution. The solution is to have a virtual environment where I can install all the libraries I want, somewhere in my user directory. This has the advantage too of allowing to use a different version of a library for different perl tools.
While I haven't found an all-in-one tool for perl, there's the CPAN module called local-lib which helps a lot. You can find its documentation here. Here is how to use it to create a virtual perl environment:
${PERLENV
} represents the directory where you want to have your perl virtual env. E.g.:
export PERLENV="$HOME"/perl5
- Create the directory and go in it to make our life easier:
mkdir -p "${PERLENV}"
cd "${PERLENV}"
- On http://search.cpan.org/dist/local-l... obtain the link to the tarball ("download" link), download, extract the library and go in its directory:
wget -O local-lib.tar.gz "${TARBALL_URL}"
tar xvf local-lib.tar.gz
cd local-lib-*
- Bootstrap it:
perl Makefile.PL --bootstrap="${PERLENV}"
- If that's the first time you use CPAN, you will have a message like, that you probably want to confirm:
Would you like me to configure as much as possible automatically? [yes]
- Then install local-lib:
make test && make install
The environment is now more or less setup. However, to use it, you need to set a few environment variables. Here are 2 helpers for that:
- A wrapper script for perl. Anytime this particular perl wrapper will be called, it will behave like a normal perl, but using your environment:
cat > $PERLENV/perl << EOF
#!/bin/sh
PERLENV="${PERLENV}"
perl -I\$PERLENV/lib/perl5 -Mlocal::lib=\$PERLENV -MCPAN "\$@"
EOF
chmod 755 $PERLENV/perl
- If you need to use other programs without an easy way to override the perl binary to use, you can create an
activate
script which would setup the environment in your current shell. Once created, you will just need to dosource "${PERLENV}"/activate
and then anything that needs perl in the current shell will use your custom environment.
cat > "${PERLENV}"/activate << EOF
PERLENV="${PERLENV}"
eval \$(perl -I\$PERLENV/lib/perl5 -Mlocal::lib=\$PERLENV -MCPAN "\$@")
EOF
Tadam, you local perl is now usable. You can start installing the CPAN modules you want and they will be installed in the environment:
"${PERLENV}"/perl -MCPAN -e 'CPAN::install(POE::Filter::IRCD)'
Or the CPAN shell:
"${PERLENV}"/perl -MCPAN -e shell
And if you want to install your favorite perl tool:
source "${PERLENV}"/activate
cd myfavoritetool
./runit
Various notes:
- I hardly know anything about perl - I might have missed some things. However, this approach works and seems somehow clean.
- This is not a fully isolated environment; system libraries will be available too. That's usually more an advantage than an issue though.
- The main issue is that it still relies on your //~/.cpan// configuration directory, so you cannot have CPAN parameters specific to your environment. AFAIK, there's no easy way around that.
Comments
http://www.coachoutletfactory.com coach outlet
http://www.coachoutletfactory.com coach factory outlet
http://www.coachoutletfactory.com coach outlet factory
http://www.coachoutletfactory.com coach outlet online
http://www.coachoutletfactory.com coach outlet store
http://www.coachoutletfactory.com coach bags on sale
http://www.coachoutletfactory.com coach bags outlet
http://www.coachoutletfactory.com coach factory outlet online
http://www.coachoutletfactory.com coach outlet store online
http://www.coachoutletfactory.com coach outlet online store
http://www.coachoutletfactory.com coach factory outlet sale
http://www.coachoutletfactory.com coach online outlet store
http://www.coachoutletfactory.com/c... coach sunglasses
http://www.coachoutletfactory.com/c... COACH HANDBAGS
http://www.coachoutletfactory.com/c... COACH WALLETS
http://www.coachoutletfactory.com/c... COACH ACCESSORIES
http://www.coachoutletfactory.com/c... COACH BOOTS
http://www.coachoutletfactory.com/c... COACH SHOES
http://www.coachoutletfactory.com/c... Coach-Handbags
http://www.coachoutletfactory.com/c... COACH JEWELRY
http://www.coachoutletfactory.com/c... COACH APPAREL
http://www.coachoutletfactory.com/c... COACH MEN
http://www.coachoutletfactory.com/c... Coach Shoulder Bags
http://www.coachoutletfactory.com/c... Coach Sling Bags
http://www.coachoutletfactory.com/c... Coach Luggage Bags
http://www.coachoutletfactory.com/c... Coach Patchwork Purse
http://www.coachoutletfactory.com/c... Coach Baby Bags
http://www.coachoutletfactory.com/c... Coach Tote Bags
http://www.coachoutletfactory.com/c... Coach Backpack Bags
http://www.coachoutletfactory.com/c... Coach Carly Bags
http://www.coachoutletfactory.com/c... Coach Claire Bags
http://www.coachoutletfactory.com/c... Coach Garnet Bags
http://www.coachoutletfactory.com/c... Coach Hampton Bags
http://www.coachoutletfactory.com/c... Coach HOBO Bags
http://www.coachoutletfactory.com/c... Coach Leather Handbags
http://www.coachoutletfactory.com/c... Coach Sabrina Bags
http://www.coachoutletfactory.com/c... Coach Spotlight Bags
http://www.coachoutletfactory.com/c... Coach Travel Bags
http://www.coachoutletfactory.com/c... Coach Tribeca Bags
http://www.coachoutletfactory.com/c... New Coach Handbags
http://www.coachoutletfactory.com/c... Coach Ergo Bags
http://www.coachoutletfactory.com/c... Coach Maggie Bags
http://www.gucci-outlet.us/gucci outlet
http://www.gucci-outlet.us/gucci bags
http://www.gucci-outlet.us/gucci outlet online
http://www.gucci-outlet.us/gucci bags outlet
http://www.gucci-outlet.us/gucci-ha... Handbags
http://www.gucci-outlet.us/gucci-ha... Backpacks
http://www.gucci-outlet.us/gucci-ha... Belt Bags
http://www.gucci-outlet.us/gucci-ha... Briefcases
http://www.gucci-outlet.us/gucci-ha... Computer Cases
http://www.gucci-outlet.us/gucci-ha... Duffels
http://www.gucci-outlet.us/gucci-ha... Hobos
http://www.gucci-outlet.us/gucci-ha... Jolicoeur
http://www.gucci-outlet.us/gucci-ha... Messenger Bags
http://www.gucci-outlet.us/gucci-ha... Shoulder Bags
http://www.gucci-outlet.us/gucci-ha... Top Handles
http://www.gucci-outlet.us/gucci-ha... Totes
http://www.gucci-outlet.us/gucci-ha... Travel Business
http://www.gucci-outlet.us/gucci-le... Leather Wallets
http://www.gucci-outlet.us/gucci-su... Sunglasses
http://www.gucci-outlet.us/gucci-wa... Wallets
http://www.gucci-outlet.us/gucci-ha... Hats
http://www.gucci-outlet.us/gucci-be... belts
http://www.gucci-outlet.us/gucci-br... bracelets
http://www.gucci-outlet.us/gucci-ea... earrings
http://www.gucci-outlet.us/gucci-ne... necklaces
http://www.gucci-outlet.us/gucci-sh... shoes
http://www.gucci-outlet.us/gucci-ba... barrette
Man’s dearest possession is life. <a href="http://www.edhardy-discount.com/">ed hardy caps</a> It is given to him but once, <a href="http://www.gobizfashion.com/">cheap Polo t shirts</a> and he must live it so as to feel no torturing regrets for wasted years, <a href="http://www.gobizfashion.com/wholesa...">discount Men Shoes</a> never know the burning shame of a mean and petty past; <a href="http://www.chinadesignerwholesale.c...">china shoes wholesale</a> so live that, dying, he might say: <a href="http://www.chinadesignerwholesale.c...">Designer Wholesale</a> all my life, <a href="http://www.edhardy-discount.com/dis...">ED HARDY on sale</a> all my strength were given to the finest cause in all the world—the fight for the Liberation of Mankind.<a href="http://www.usabuysale.com/Womens-Cl...">discount womens clothing</a>