ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/common-sense/sense.pm
(Generate patch)

Comparing common-sense/sense.pm (file contents):
Revision 1.15 by root, Tue Sep 1 14:28:20 2009 UTC vs.
Revision 1.16 by root, Tue Sep 1 19:10:02 2009 UTC

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
22This module implements some sane defaults for Perl programs, as defined by 22This module implements some sane defaults for Perl programs, as defined by
23two typical (or not so typical - use your common sense) specimens of 23two typical (or not so typical - use your common sense) specimens of Perl
24Perl coders. 24coders.
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
69changes to many modules - new keywords are just the tip of the iceberg. 69changes to many modules - new keywords are just the tip of the iceberg.
70 70
71If your code isn't alive, it's dead, Jim - be an active maintainer. 71If 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
76Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w> 76Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w>
77switch: Even though we don't care if other people use warnings (and 77switch: Even though we don't care if other people use warnings (and
78certainly there are useful ones), a lot of warnings simply go against the 78certainly there are useful ones), a lot of warnings simply go against the
79spirit of Perl. 79spirit of Perl.
80 80
81Most prominently, the warnings related to C<undef>. There is nothing wrong 81Most prominently, the warnings related to C<undef>. There is nothing wrong
82with C<undef>: it has well-defined semantics, it is useful, and spitting 82with C<undef>: it has well-defined semantics, it is useful, and spitting
83out warnings you never asked for is just evil. 83out warnings you never asked for is just evil.
84 84
85So every one of our modules did C<no warnings> in the past, to avoid 85The result was that every one of our modules did C<no warnings> in the
86somebody accidentally using and forcing his bad standards on our code. No 86past, to avoid somebody accidentally using and forcing his bad standards
87will do. Really, the C<-w> switch should only enable wanrings for the main 87on our code. Of course, this switched off all warnings, even the useful
88program only. 88ones. Not a good situation. Really, the C<-w> switch should only enable
89warnings for the main program only.
89 90
90Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a 91Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a
91favourable way, calling it outright "wrong"), but standard utilities, such 92favourable way, calling it outright "wrong"), but standard utilities, such
92as L<prove>, or MakeMaker when running C<make test>, still enable them 93as L<prove>, or MakeMaker when running C<make test>, still enable them
93blindly. 94blindly.
94 95
95Anyways, since C<use warnings> is inacceptable, many people (including us 96For version 2 of common::sense, we finally sat down a few hours and went
96before we created common::sense) just flat out disabled all warnings. For 97through I<every single warning message>, identifiying - according to
97this module, we actually sat down a few hours and went through all the 98common sense - all the useful ones.
98warnings, and identified all the useful (accordign to common sense)
99warnings.
100 99
101This resulted in the rather impressive list in the SYNOPSIS. When we 100This resulted in the rather impressive list in the SYNOPSIS. When we
102weren't sure, we didn't include the warning, so the list might grow in 101weren't sure, we didn't include the warning, so the list might grow in
103the future (we might have made a mistake, too, so the list might shrink 102the future (we might have made a mistake, too, so the list might shrink
104again). 103as well).
105 104
106Note the presence of C<FATAL> in the list: we do not think that the 105Note the presence of C<FATAL> in the list: we do not think that the
107conditions caught by these warnings are worthy of a warning, we I<insist> 106conditions caught by these warnings are worthy of a warning, we I<insist>
108that they are worthy of stopping your program, instantly. They are bugs! 107that they are worthy of I<stopping> your program, I<instantly>. They are
108I<bugs>!
109 109
110Therefore we consider C<common::sense> to be much stricter than C<use 110Therefore we consider C<common::sense> to be much stricter than C<use
111warnings>, which is good if you are into strict things (we are not, 111warnings>, which is good if you are into strict things (we are not,
112actually, but these things tend to be subjective). 112actually, 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
157sub import { 157sub 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines