… | |
… | |
11 | # use strict qw(vars subs); |
11 | # use strict qw(vars subs); |
12 | # use feature qw(say state switch); |
12 | # use feature qw(say state switch); |
13 | # no warnings; |
13 | # no warnings; |
14 | # use warnings qw(FATAL closed threads internal debugging pack substr malloc |
14 | # use warnings qw(FATAL closed threads internal debugging pack substr malloc |
15 | # unopened portable prototype inplace io pipe unpack regexp |
15 | # unopened portable prototype inplace io pipe unpack regexp |
16 | # deprecated exiting redefine glob digit printf utf8 layer |
16 | # deprecated exiting glob digit printf utf8 layer |
17 | # reserved parenthesis taint closure semicolon); |
17 | # reserved parenthesis taint closure semicolon); |
18 | # no warnings qw(exec newline); |
18 | # no warnings qw(exec newline); |
19 | |
19 | |
20 | =head1 DESCRIPTION |
20 | =head1 DESCRIPTION |
21 | |
21 | |
22 | This module implements some sane defaults for Perl programs, as defined by |
22 | This module implements some sane defaults for Perl programs, as defined by |
23 | two typical (or not so typical - use your common sense) specimens of |
23 | two typical (or not so typical - use your common sense) specimens of Perl |
24 | Perl coders. |
24 | coders. |
25 | |
25 | |
26 | =over 4 |
26 | =over 4 |
27 | |
27 | |
28 | =item use strict qw(subs vars) |
28 | =item use strict qw(subs vars) |
29 | |
29 | |
… | |
… | |
69 | changes to many modules - new keywords are just the tip of the iceberg. |
69 | changes to many modules - new keywords are just the tip of the iceberg. |
70 | |
70 | |
71 | If your code isn't alive, it's dead, Jim - be an active maintainer. |
71 | If your code isn't alive, it's dead, Jim - be an active maintainer. |
72 | |
72 | |
73 | |
73 | |
74 | =item no warnings, but a lot of new lexical errors |
74 | =item no warnings, but a lot of new errors |
75 | |
75 | |
76 | Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w> |
76 | Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w> |
77 | switch: Even though we don't care if other people use warnings (and |
77 | switch: Even though we don't care if other people use warnings (and |
78 | certainly there are useful ones), a lot of warnings simply go against the |
78 | certainly there are useful ones), a lot of warnings simply go against the |
79 | spirit of Perl. |
79 | spirit of Perl. |
80 | |
80 | |
81 | Most prominently, the warnings related to C<undef>. There is nothing wrong |
81 | Most prominently, the warnings related to C<undef>. There is nothing wrong |
82 | with C<undef>: it has well-defined semantics, it is useful, and spitting |
82 | with C<undef>: it has well-defined semantics, it is useful, and spitting |
83 | out warnings you never asked for is just evil. |
83 | out warnings you never asked for is just evil. |
84 | |
84 | |
85 | So every one of our modules did C<no warnings> in the past, to avoid |
85 | The result was that every one of our modules did C<no warnings> in the |
86 | somebody accidentally using and forcing his bad standards on our code. No |
86 | past, to avoid somebody accidentally using and forcing his bad standards |
87 | will do. Really, the C<-w> switch should only enable wanrings for the main |
87 | on our code. Of course, this switched off all warnings, even the useful |
88 | program only. |
88 | ones. Not a good situation. Really, the C<-w> switch should only enable |
|
|
89 | warnings for the main program only. |
89 | |
90 | |
90 | Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a |
91 | Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a |
91 | favourable way, calling it outright "wrong"), but standard utilities, such |
92 | favourable way, calling it outright "wrong"), but standard utilities, such |
92 | as L<prove>, or MakeMaker when running C<make test>, still enable them |
93 | as L<prove>, or MakeMaker when running C<make test>, still enable them |
93 | blindly. |
94 | blindly. |
94 | |
95 | |
95 | Anyways, since C<use warnings> is inacceptable, many people (including us |
96 | For version 2 of common::sense, we finally sat down a few hours and went |
96 | before we created common::sense) just flat out disabled all warnings. For |
97 | through I<every single warning message>, identifiying - according to |
97 | this module, we actually sat down a few hours and went through all the |
98 | common sense - all the useful ones. |
98 | warnings, and identified all the useful (accordign to common sense) |
|
|
99 | warnings. |
|
|
100 | |
99 | |
101 | This resulted in the rather impressive list in the SYNOPSIS. When we |
100 | This resulted in the rather impressive list in the SYNOPSIS. When we |
102 | weren't sure, we didn't include the warning, so the list might grow in |
101 | weren't sure, we didn't include the warning, so the list might grow in |
103 | the future (we might have made a mistake, too, so the list might shrink |
102 | the future (we might have made a mistake, too, so the list might shrink |
104 | again). |
103 | as well). |
105 | |
104 | |
106 | Note the presence of C<FATAL> in the list: we do not think that the |
105 | Note the presence of C<FATAL> in the list: we do not think that the |
107 | conditions caught by these warnings are worthy of a warning, we I<insist> |
106 | conditions caught by these warnings are worthy of a warning, we I<insist> |
108 | that they are worthy of stopping your program, instantly. They are bugs! |
107 | that they are worthy of I<stopping> your program, I<instantly>. They are |
|
|
108 | I<bugs>! |
109 | |
109 | |
110 | Therefore we consider C<common::sense> to be much stricter than C<use |
110 | Therefore we consider C<common::sense> to be much stricter than C<use |
111 | warnings>, which is good if you are into strict things (we are not, |
111 | warnings>, which is good if you are into strict things (we are not, |
112 | actually, but these things tend to be subjective). |
112 | actually, but these things tend to be subjective). |
113 | |
113 | |
… | |
… | |
145 | |
145 | |
146 | # paste this into pelr to find bitmask |
146 | # paste this into pelr to find bitmask |
147 | |
147 | |
148 | # no warnings; |
148 | # no warnings; |
149 | # use warnings qw(FATAL closed threads internal debugging pack substr malloc unopened portable prototype |
149 | # use warnings qw(FATAL closed threads internal debugging pack substr malloc unopened portable prototype |
150 | # inplace io pipe unpack regexp deprecated exiting redefine glob digit printf |
150 | # inplace io pipe unpack regexp deprecated exiting glob digit printf |
151 | # utf8 layer reserved parenthesis taint closure semicolon); |
151 | # utf8 layer reserved parenthesis taint closure semicolon); |
152 | # no warnings qw(exec newline); |
152 | # no warnings qw(exec newline); |
153 | # BEGIN { warn join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS}; exit 0 }; |
153 | # BEGIN { warn join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS}; exit 0 }; |
154 | |
154 | |
155 | # overload should be included |
155 | # overload should be included |
156 | |
156 | |
157 | sub import { |
157 | sub import { |
158 | # verified with perl 5.8.0, 5.10.0 |
158 | # verified with perl 5.8.0, 5.10.0 |
159 | ${^WARNING_BITS} = "\xfc\x3f\xf3\x00\xcf\xf3\xcf\xc0\xf3\xfc\x33\x03"; |
159 | ${^WARNING_BITS} = "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03"; |
160 | |
160 | |
161 | # use strict vars subs |
161 | # use strict vars subs |
162 | $^H |= 0x00000600; |
162 | $^H |= 0x00000600; |
163 | |
163 | |
164 | # use feature |
164 | # use feature |