1Modern::Perl(3) User Contributed Perl Documentation Modern::Perl(3)
2
3
4
6 Modern::Perl - enable all of the features of Modern Perl with one
7 import
8
10 version 1.20220515
11
13 Modern Perl programs use several modules to enable additional features
14 of Perl and of the CPAN. Instead of copying and pasting all of these
15 "use" lines, instead write only one:
16
17 use Modern::Perl;
18
19 This enables the strict and warnings pragmas, as well as all of the
20 features available in Perl 5.10. It also enables C3 method resolution
21 order as documented in "perldoc mro" and loads IO::File and IO::Handle
22 so that you may call methods on filehandles. In the future, it may
23 include additional core modules and pragmas (but is unlikely to include
24 non-core features).
25
26 Because so much of this module's behavior uses lexically scoped
27 pragmas, you may disable these pragmas within an inner scope with:
28
29 no Modern::Perl;
30
31 See
32 <http://www.modernperlbooks.com/mt/2009/01/toward-a-modernperl.html>
33 for more information, <http://www.modernperlbooks.com/> for further
34 discussion of Modern Perl and its implications, and
35 <http://onyxneon.com/books/modern_perl/index.html> for a freely-
36 downloadable Modern Perl tutorial.
37
38 CLI Usage
39 As of Modern::Perl 2019, you may also enable this pragma from the
40 command line:
41
42 $ perl -Modern::Perl -e 'say "Take that, awk!"'
43
44 You may also enable year-specific features:
45
46 $ perl -Modern::Perl=2020 -e 'say "Looking forward to Perl 5.30!"'
47
48 Wrapping Modern::Perl
49 If you want to wrap Modern::Perl in your own "import()" method, you can
50 do so to add additional pragmas or features, such as the use of
51 Try::Tiny. Please note that, if you do so, you will not automatically
52 enable C3 method resolution in the calling scope. This is due to how
53 the mro pragma works. In your custom "import()" method, you will need
54 to write code such as:
55
56 mro::set_mro( scalar caller(), 'c3' );
57
58 Forward Compatibility
59 For forward compatibility, I recommend you specify a string containing
60 a year value as the single optional import tag. For example:
61
62 use Modern::Perl '2009';
63 use Modern::Perl '2010';
64
65 ... both enable 5.10 features, while:
66
67 use Modern::Perl '2011';
68
69 ... enables 5.12 features:
70
71 use Modern::Perl '2012';
72
73 ... enables 5.14 features:
74
75 use Modern::Perl '2013';
76
77 ... enables 5.16 features, and:
78
79 use Modern::Perl '2014';
80
81 ... enables 5.18 features, and:
82
83 use Modern::Perl '2015';
84
85 ... enables 5.20 features, and:
86
87 use Modern::Perl '2016';
88
89 ... enables 5.24 features, and:
90
91 use Modern::Perl '2017';
92
93 ... enables 5.24 features, and:
94
95 use Modern::Perl '2018';
96
97 ... enables 5.26 features.
98
99 use Modern::Perl '2019';
100
101 ... enables 5.28 features.
102
103 use Modern::Perl '2020';
104
105 ... enables 5.30 features.
106
107 use Modern::Perl '2021';
108
109 ... enables 5.32 features.
110
111 use Modern::Perl '2022';
112
113 ... enables 5.34 features.
114
115 Obviously you cannot use newer features on earlier versions. Perl will
116 throw the appropriate exception if you try.
117
119 chromatic, "<chromatic at wgz.org>"
120
122 None known.
123
124 Please report any bugs or feature requests to "bug-modern-perl at
125 rt.cpan.org", or through the web interface at
126 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Modern-Perl>. I will
127 be notified, and then you'll automatically be notified of progress on
128 your bug as I make changes.
129
131 You can find documentation for this module with the perldoc command.
132
133 perldoc Modern::Perl
134
135 You can also look for information at:
136
137 • RT: CPAN's request tracker
138
139 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Modern-Perl>
140
141 • AnnoCPAN: Annotated CPAN documentation
142
143 <http://annocpan.org/dist/Modern-Perl>
144
145 • CPAN Ratings
146
147 <http://cpanratings.perl.org/d/Modern-Perl>
148
149 • Search CPAN
150
151 <http://search.cpan.org/dist/Modern-Perl/>
152
154 Damian Conway (inspiration from Toolkit), Florian Ragwitz
155 (B::Hooks::Parser, so I didn't have to write it myself), chocolateboy
156 (for suggesting that I don't even need B::Hooks::Parser), Damien Learns
157 Perl, David Moreno, Evan Carroll, Elliot Shank, Andreas König, Father
158 Chrysostomos, Gryphon Shafer, and Norbert E. Grüner for reporting bugs,
159 filing patches, and requesting features.
160
162 chromatic
163
165 This software is copyright (c) 2018 by chromatic@wgz.org.
166
167 This is free software; you can redistribute it and/or modify it under
168 the same terms as the Perl 5 programming language system itself.
169
170
171
172perl v5.34.1 2022-05-16 Modern::Perl(3)