Perl、h2xs、设置所需的 Perl 版本

Perl, h2xs, set required Perl-version

我开始使用 h2xs 创建 Perl 模块。真正的 XS 模块(C 到 Perl)和非 XS(我也将它用于纯 Perl 模块以获得框架)。

对我来说,h2xs 假定需要当前使用的 Perl 版本(在 Makefile.PL 以及模块 .pm 中),这很烦人。

如果我将模块转移到其他装有旧版本 Perl 的机器上,我需要修改 1 或 2 个文件。

有没有办法在 h2xs 或 Makefile.PL 中手动设置所需的 Perl 版本??

感谢帮助!

查看手册页 (here):

-b, --compat-version=version Generates a .pm file which is backwards compatible with the specified perl version. For versions < 5.6.0, the changes are. - no use of 'our' (uses 'use vars' instead) - no 'use warnings' Specifying a compatibility version higher than the version of perl you are using to run h2xs will have no effect. If unspecified h2xs will default to compatibility with the version of perl you are using to run h2xs.

您在寻找 -b 选项吗?来自 the docs:

-b, --compat-version=version

Generates a .pm file which is backwards compatible with the specified perl version.

For versions < 5.6.0, the changes are. - no use of 'our' (uses 'use vars' instead) - no 'use warnings'

Specifying a compatibility version higher than the version of perl you are using to run h2xs will have no effect. If unspecified h2xs will default to compatibility with the version of perl you are using to run h2xs.

似乎按预期工作:

$ h2xs -b 5.10.0 -A Foo
Writing Foo/ppport.h
Writing Foo/lib/Foo.pm
Writing Foo/Foo.xs
Writing Foo/Makefile.PL
Writing Foo/README
Writing Foo/t/Foo.t
Writing Foo/Changes
Writing Foo/MANIFEST

$ grep 'use 5' Foo/lib/Foo.pm
use 5.010000;

$ rm -rf Foo/

$ h2xs -b 5.20.0 -A Foo
Writing Foo/ppport.h
Writing Foo/lib/Foo.pm
Writing Foo/Foo.xs
Writing Foo/Makefile.PL
Writing Foo/README
Writing Foo/t/Foo.t
Writing Foo/Changes
Writing Foo/MANIFEST

$ grep 'use 5' Foo/lib/Foo.pm
use 5.020000;