How can I 'use' specific version of a perl CPAN module?

孤者浪人 提交于 2019-12-05 05:18:09

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 .

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!