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 (but is unlikely to include non-core features).
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;
See <http://www.modernperlbooks.com/mt/2009/01/toward-a-modernperl.html> for more information,
<http://www.modernperlbooks.com/> for further discussion of Modern Perl and its implications, and
<http://onyxneon.com/books/modern_perl/index.html> for a freely-downloadable Modern Perl tutorial.
CLIUsage
As of Modern::Perl 2019, you may also enable this pragma from the command line:
$ perl -Modern::Perl -e 'say "Take that, awk!"'
You may also enable year-specific features:
$ perl -Modern::Perl=2020 -e 'say "Looking forward to Perl 5.30!"'
WrappingModern::Perl
If you want to wrap Modern::Perl in your own import() method, you can do so to add additional pragmas or
features, such as the use of Try::Tiny. Please note that, if you do so, you will not automatically enable
C3 method resolution in the calling scope. This is due to how the mro pragma works. In your custom
import() method, you will need to write code such as:
mro::set_mro( scalar caller(), 'c3' );
ForwardCompatibility
For forward compatibility, I recommend you specify a string containing a year value as the single
optional import tag. For example:
use Modern::Perl '2009';
use Modern::Perl '2010';
... both enable 5.10 features, while:
use Modern::Perl '2011';
... enables 5.12 features:
use Modern::Perl '2012';
... enables 5.14 features:
use Modern::Perl '2013';
... enables 5.16 features, and:
use Modern::Perl '2014';
... enables 5.18 features, and:
use Modern::Perl '2015';
... enables 5.20 features, and:
use Modern::Perl '2016';
... enables 5.24 features, and:
use Modern::Perl '2017';
... enables 5.24 features, and:
use Modern::Perl '2018';
... enables 5.26 features.
use Modern::Perl '2019';
... enables 5.28 features.
use Modern::Perl '2020';
... enables 5.30 features.
use Modern::Perl '2021';
... enables 5.32 features.
use Modern::Perl '2022';
... enables 5.34 features.
use Modern::Perl '2023';
... enables 5.36 features.
use Modern::Perl '2024';
... enables 5.38 features.
Obviously you cannot use newer features on earlier versions. Perl will throw the appropriate exception if
you try.
As of Perl 5.38, you may prefer to write "use v5.38", which is almost entirely equivalent to the use of
this module. For the purpose of forward compatibility, this module will continue to work as expected--and
will continue regular maintenance.
As of Perl 5.41.4, "given" is no longer available, so any import tags for older versions of Perl will not
enable this feature, no matter how much you try.