9

I have a lot perl code that does different things in test and production, and I want to lock my code to specific versions of CPAN modules in case there are some changes to some of them in the future which may possibly break my code.

So I want to use specific versions of all the modules I use. By use I mean

use XML::Smart 
Gogi
  • 1,695
  • 4
  • 23
  • 36
  • Check whether this thread has any useful information for you: http://stackoverflow.com/questions/260593/how-can-i-install-a-specific-version-of-a-perl-module – slayedbylucifer Jan 15 '13 at 06:32
  • You are the exact use case for Pinto, by Jeffrey Thalhammer. It's on CPAN: http://search.cpan.org/perldoc?Pinto – DavidO Jan 15 '13 at 06:32
  • 1
    To elaborate: Pinto manages your dependency chain, allowing you to "pin" some modules at specific versions, while allowing others to upgrade as new releases come available. You're able to roll back changes, and a lot more. It's like version control geared specifically toward Perl modules/distributions. – DavidO Jan 15 '13 at 06:38
  • Pinto doesn't mean that someone else ignores it and upgrades it through other means. – brian d foy Jan 15 '13 at 18:50

2 Answers2

9

To use specific module refer only

use only MyModule => 0.30;

Also to print error if module version you want is above to currently installed one You can say

use XML::Smart v1.6.9;

or

use XML::Smart 1.6.9;

or
for backward compatibility

use XML::Smart 1.006_009;  

With reference from perldoc :

  • use Module VERSION LIST
  • use Module VERSION
  • use Module LIST
  • use Module
  • use VERSION

If the VERSION argument is present between Module and LIST, then the use will call the VERSION method in class Module with the given version as an argument. The default VERSION method, inherited from the UNIVERSAL class, croaks if the given version is larger than the value of the variable $Module::VERSION .

  • 1
    That doesn't stop newer versions from being used. – ikegami Jan 15 '13 at 08:26
  • @ikegami - sorry for that. Updated answer with [only](http://search.cpan.org/~ingy/only-0.28/lib/only.pm) module –  Jan 15 '13 at 10:50
4

You can do the low tech thing:

BEGIN {
    use XML::Simple;
    die "..." unless XML::Simple->VERSION eq '1.23';
    }

There is a headache knowing how a particular module reports its version. The version module is supposed to do version math, but I haven't found it reliable since there are too many ways to specify a version.

brian d foy
  • 129,424
  • 31
  • 207
  • 592