自动引入Perl最新特性模块之Modern::Perl
在前面我们介绍过如何引入Perl该版本的那些新的特性,因各个版本都会加入一些新特性,所以我们在使用它们时必须显式地声明,比如像:use feature ':5.10'; #引入5.10中的所有新特性
use feature 'say switch evalbytes '; #引入所声明的关键特性,'evalbytes'是Perl 5.16中引入的
在cpan上出现一个自动载入当前版本所有新特性的模块,下面我们简单介绍一下。
Modern::Perl - enable all of the features of Modern Perl with one import.
Modern Perl programs use several modules to enable additional features of Perl and of the CPAN. Instead of copying and pasting all of these use lines, instead write only one:
use Modern::Perl;
This enables the strict and warnings pragmas, as well as all of the features available in Perl 5.10. It also enables C3 method resolution order as documented in perldoc mro and loads IO::File and IO::Handle so that you may call methods on filehandles. In the future, it may include additional core modules and pragmas.
Because so much of this module's behavior uses lexically scoped pragmas, you may disable these pragmas within an inner scope with:
no Modern::Perl;
它是向前兼容的,向其传入年份可以打开具体版本的特性。
use Modern::Perl '2009';
use Modern::Perl '2010';
即引入'5.10'的相关特性。
use Modern::Perl '2011';
enables 5.12 features
use Modern::Perl '2012';
enables 5.14 features
use Modern::Perl '2013';
enables 5.16 features
Obviously you cannot use newer features on earlier versions. Perl will throw the appropriate exception if you try.
In the near future--sometime around September 2012--this module may drop support for 5.10 and will complain (once per process) if you use a year too old.
参考链接:
http://www.modernperlbooks.com/mt/2009/01/toward-a-modernperl.html
http://www.modernperlbooks.com/