… | |
… | |
6 | |
6 | |
7 | use common::sense; |
7 | use common::sense; |
8 | |
8 | |
9 | # supposed to be the same, with much lower memory usage, as: |
9 | # supposed to be the same, with much lower memory usage, as: |
10 | # |
10 | # |
|
|
11 | # use utf8; |
11 | # use strict qw(vars subs); |
12 | # use strict qw(vars subs); |
12 | # use feature qw(say state switch); |
13 | # use feature qw(say state switch); |
13 | # no warnings; |
14 | # no warnings; |
14 | # use warnings qw(FATAL closed threads internal debugging pack substr malloc |
15 | # use warnings qw(FATAL closed threads internal debugging pack substr malloc |
15 | # portable prototype inplace io pipe unpack regexp |
16 | # portable prototype inplace io pipe unpack regexp |
16 | # deprecated exiting glob digit printf utf8 layer |
17 | # deprecated exiting glob digit printf layer |
17 | # reserved parenthesis taint closure semicolon); |
18 | # reserved parenthesis taint closure semicolon); |
18 | # no warnings qw(exec newline unopened); |
19 | # no warnings qw(exec newline unopened); |
19 | |
20 | |
20 | =head1 DESCRIPTION |
21 | =head1 DESCRIPTION |
21 | |
22 | |
… | |
… | |
48 | and why it does it, and what the advantages (and disadvantages) of this |
49 | and why it does it, and what the advantages (and disadvantages) of this |
49 | approach are. |
50 | approach are. |
50 | |
51 | |
51 | =over 4 |
52 | =over 4 |
52 | |
53 | |
|
|
54 | =item use utf8 |
|
|
55 | |
|
|
56 | While it's not common sense to write your programs in UTF-8, it's quickly |
|
|
57 | becoming the most common encoding, and the most convenient encoding |
|
|
58 | available (you can do really nice quoting tricks...). Experience has shown |
|
|
59 | that our programs were either all pure ascii or utf-8, both of which will |
|
|
60 | stay the same. |
|
|
61 | |
|
|
62 | There are few drawbacks to enabling UTF-8 source code by default (mainly |
|
|
63 | some speed hits due to bugs in older versions of perl), so this module |
|
|
64 | enables UTF-8 source code encoding by default. |
|
|
65 | |
53 | =item use strict qw(subs vars) |
66 | =item use strict qw(subs vars) |
54 | |
67 | |
55 | Using C<use strict> is definitely common sense, but C<use strict |
68 | Using C<use strict> is definitely common sense, but C<use strict |
56 | 'refs'> definitely overshoots its usefulness. After almost two |
69 | 'refs'> definitely overshoots its usefulness. After almost two |
57 | decades of Perl hacking, we decided that it does more harm than being |
70 | decades of Perl hacking, we decided that it does more harm than being |
… | |
… | |
188 | |
201 | |
189 | =cut |
202 | =cut |
190 | |
203 | |
191 | package common::sense; |
204 | package common::sense; |
192 | |
205 | |
193 | our $VERSION = '2.03'; |
206 | our $VERSION = '3.0'; |
194 | |
207 | |
195 | # paste this into perl to find bitmask |
208 | # paste this into perl to find bitmask |
196 | |
209 | |
197 | # no warnings; |
210 | # no warnings; |
198 | # use warnings qw(FATAL closed threads internal debugging pack substr malloc portable prototype |
211 | # use warnings qw(FATAL closed threads internal debugging pack substr malloc portable prototype |
199 | # inplace io pipe unpack regexp deprecated exiting glob digit printf |
212 | # inplace io pipe unpack regexp deprecated exiting glob digit printf |
200 | # utf8 layer reserved parenthesis taint closure semicolon); |
213 | # layer reserved parenthesis taint closure semicolon); |
201 | # no warnings qw(exec newline unopened); |
214 | # no warnings qw(exec newline unopened); |
202 | # BEGIN { warn join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS}; exit 0 }; |
215 | # BEGIN { warn join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS}; exit 0 }; |
203 | |
216 | |
204 | # overload should be included |
217 | # overload should be included |
205 | |
218 | |
206 | sub import { |
219 | sub import { |
207 | # verified with perl 5.8.0, 5.10.0 |
220 | # verified with perl 5.8.0, 5.10.0 |
208 | ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\x33\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03"; |
221 | ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\x33\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x00"; |
209 | |
222 | |
210 | # use strict vars subs |
223 | # use utf8, strict vars subs |
211 | $^H |= 0x00000600; |
224 | $^H |= 0x00800600; |
212 | |
225 | |
213 | # use feature |
226 | # use feature |
214 | $^H{feature_switch} = |
227 | $^H{feature_switch} = |
215 | $^H{feature_say} = |
228 | $^H{feature_say} = |
216 | $^H{feature_state} = 1; |
229 | $^H{feature_state} = 1; |