Sunday, June 13, 2010

Installing dependencies for your packaged for CPAN library

Update: See the comments, apparently the warning against auto_install is outdated information. I don't have any opinion of myself here.

It always puzzled me what is the 'canonical' way to install dependencies for an unpacked distribution, be it downloaded from CPAN or your own in-house product packaged the CPAN way for convenience. Module::Install provides an 'auto_install' option that you add to your Makefile.PL and then perl Makefile.PL; make (or perl Makefile.PL; sudo make) should do that trick. This seemed like a good solution that could be a standard, but now I see that the FAQ of that module says:


Do I really have to avoid auto_install()?

auto_install() has a long history of breaking CPAN toolchains. Lots of people had a bad feeling on it, and have said it should be strongly avoided. In fact it was deprecated and removed once.

Although most of the known problems have been fixed and you can use it more safely than ever, the use of auto_install() is still discouraged, especially if what you are writing is a module to be uploaded on the CPAN. auto_install() does lots of things itself, thus does not always do the same things as other toolchains do (including extra attribute handling, etc; which can be fixed somehow but that's not too DRY). It only supports CPAN and CPANPLUS as its backends. If you use other tools to install, it may still cause a trouble.

Besides, now you can do what auto_install() does with other means. If your CPAN module is new enough, you can pass a dot to the cpan command it provides, and it will install all the required distributions from the CPAN:

$ cpan .

So apparently this is the way to go - using the cpan shell. There is a minor problem with this when used for testing - it would automatically install the package from the directory you are in. Sure you can suppress that you need by adding another command switch (-m), but it would be better if the default action was the safe one.

4 comments:

Peter Rabbitson said...

Oh crap - this is FUD and misinformation. It was supposed to be ripped out of the POD ages ago. I'll try to poke the necessary people.

John Napiorkowski said...

I'm a bit confused by this as well, I'm mostly cargo culting stuff in my Makefile.PL from other successful projects. However lately I've been using cpan-minus to install local deps and finds that works very well.

cpanm --installdeps .

you can add -l to install to a new local lib as well, btw, although if local::lib is alraeady setup you cpan-minus is smart enough to just use it.

John Napiorkowski

Peter Rabbitson said...

Erroneous doc is finally fixed. Please update your blogpost:
http://fisheye2.atlassian.com/changelog/cpan/trunk/Module-Install?cs=12453

ijw said...

Seconded on the cpanm front. In my experience it's faster than cpan, and you can get an up to date copy with

wget http://cpanmin.us/

Also, it knows how to create a local perl install directory, and will do it by default if you're not root.