Perl version string: why use EVAL EXPR?

后端 未结 4 2051
情话喂你
情话喂你 2020-12-16 11:29

I just took notice to this generated by Catalyst.pl. It is obviously some sort of unannotated hack. What is the advantage of setting up a version string like th

4条回答
  •  醉梦人生
    2020-12-16 12:01

    From perlmodstyle: Version numbering

    If you want to release a 'beta' or 'alpha' version of a module but don't want CPAN.pm to list it as most recent use an '_' after the regular version number followed by at least 2 digits, eg. 1.20_01. If you do this, the following idiom is recommended:

    1. $VERSION = "1.12_01";
    2. $XS_VERSION = $VERSION; # only needed if you have XS code
    3. $VERSION = eval $VERSION;

    With that trick MakeMaker will only read the first line and thus read the underscore, while the perl interpreter will evaluate the $VERSION and convert the string into a number. Later operations that treat $VERSION as a number will then be able to do so without provoking a warning about $VERSION not being a number.

提交回复
热议问题