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.20230106
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 to
54 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 use Modern::Perl '2023';
116
117 ... enables 5.36 features.
118
119 Obviously you cannot use newer features on earlier versions. Perl will
120 throw the appropriate exception if you try.
121
123 chromatic, "<chromatic at wgz.org>"
124
126 None known.
127
128 Please report any bugs or feature requests to "bug-modern-perl at
129 rt.cpan.org", or through the web interface at
130 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Modern-Perl>. I will
131 be notified, and then you'll automatically be notified of progress on
132 your bug as I make changes.
133
135 You can find documentation for this module with the perldoc command.
136
137 perldoc Modern::Perl
138
139 You can also look for information at:
140
141 • RT: CPAN's request tracker
142
143 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Modern-Perl>
144
145 • AnnoCPAN: Annotated CPAN documentation
146
147 <http://annocpan.org/dist/Modern-Perl>
148
149 • CPAN Ratings
150
151 <http://cpanratings.perl.org/d/Modern-Perl>
152
153 • Search CPAN
154
155 <http://search.cpan.org/dist/Modern-Perl/>
156
158 Damian Conway (inspiration from Toolkit), Florian Ragwitz
159 (B::Hooks::Parser, so I didn't have to write it myself), chocolateboy
160 (for suggesting that I don't even need B::Hooks::Parser), Damien Learns
161 Perl, David Moreno, Evan Carroll, Elliot Shank, Andreas König, Father
162 Chrysostomos, Gryphon Shafer, and Norbert E. Grüner for reporting bugs,
163 filing patches, and requesting features.
164
166 chromatic
167
169 This software is copyright (c) 2018 by chromatic@wgz.org.
170
171 This is free software; you can redistribute it and/or modify it under
172 the same terms as the Perl 5 programming language system itself.
173
174
175
176perl v5.36.0 2023-01-20 Modern::Perl(3)