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

Comparing common-sense/sense.pm.PL (file contents):
Revision 1.9 by root, Sat Mar 24 12:46:11 2012 UTC vs.
Revision 1.10 by root, Sun Jun 10 19:33:12 2012 UTC

3open STDOUT, ">$ARGV[0]~" 3open STDOUT, ">$ARGV[0]~"
4 or die "$ARGV[0]~: $!"; 4 or die "$ARGV[0]~: $!";
5 5
6our $WARN; 6our $WARN;
7our $H; 7our $H;
8our %H;
8 9
9BEGIN { 10BEGIN {
10 $H = $^H; 11 $H = $^H;
11 $WARN = ${^WARNING_BITS}; 12 $WARN = ${^WARNING_BITS};
12} 13}
13 14
14use utf8; 15use utf8;
15use strict qw(subs vars); 16use strict qw(subs vars);
17
18BEGIN {
19 if ($] >= 5.010) {
20 require feature;
21 feature->import (qw(say state switch));
22 }
23 if ($] >= 5.012) {
24 feature->import (qw(unicode_strings));
25 }
26 if ($] >= 5.016) {
27 feature->import (qw(current_sub fc evalbytes));
28 feature->unimport (qw(array_base));
29 }
30}
16 31
17no warnings; 32no warnings;
18use warnings qw(FATAL closed threads internal debugging pack malloc portable prototype 33use warnings qw(FATAL closed threads internal debugging pack malloc portable prototype
19 inplace io pipe unpack deprecated glob digit printf 34 inplace io pipe unpack deprecated glob digit printf
20 layer reserved taint closure semicolon); 35 layer reserved taint closure semicolon);
21no warnings qw(exec newline unopened); 36no warnings qw(exec newline unopened);
22 37
23BEGIN { 38BEGIN {
24 $H = $^H & ~$H; 39 $H = $^H & ~$H;
25 $WARN = ${^WARNING_BITS} & ~$WARN; 40 $WARN = ${^WARNING_BITS} & ~$WARN;
41 %H = %^H;
26} 42}
27 43
28while (<DATA>) { 44while (<DATA>) {
29 if (/^IMPORT/) { 45 if (/^IMPORT/) {
30 print " # use warnings\n"; 46 print " # use warnings\n";
31 printf " \${^WARNING_BITS} ^= \${^WARNING_BITS} ^ \"%s\";\n", 47 printf " \${^WARNING_BITS} ^= \${^WARNING_BITS} ^ \"%s\";\n",
32 join "", map "\\x$_", unpack "(H2)*", $WARN; 48 join "", map "\\x$_", unpack "(H2)*", $WARN;
33 print " # use strict, use utf8;\n"; 49 print " # use strict, use utf8; use feature;\n";
34 printf " \$^H |= 0x%x;\n", $H; 50 printf " \$^H |= 0x%x;\n", $H;
51
52 if (my @features = grep /^feature_/, keys %H) {
53 print " \@^H{qw(@features)} = (1) x ", (scalar @features), ";\n";
54 }
35 } else { 55 } else {
36 print; 56 print;
37 } 57 }
38} 58}
39 59
46 66
47common::sense - save a tree AND a kitten, use common::sense! 67common::sense - save a tree AND a kitten, use common::sense!
48 68
49=head1 SYNOPSIS 69=head1 SYNOPSIS
50 70
51 use common::sense; 71 use common::sense;
52 72
53 # supposed to be the same, with much lower memory usage, as: 73 # Supposed to be mostly the same, with much lower memory usage, as:
54 # 74
55 # use utf8; 75 # use utf8;
56 # use strict qw(vars subs); 76 # use strict qw(vars subs);
57 # use feature qw(say state switch); 77 # use feature qw(say state switch);
78 # use feature qw(unicode_strings unicode_eval current_sub fc evalbytes);
79 # no feature qw(array_base);
58 # no warnings; 80 # no warnings;
59 # use warnings qw(FATAL closed threads internal debugging pack 81 # use warnings qw(FATAL closed threads internal debugging pack
60 # portable prototype inplace io pipe unpack malloc 82 # portable prototype inplace io pipe unpack malloc
61 # deprecated glob digit printf layer 83 # deprecated glob digit printf layer
62 # reserved taint closure semicolon); 84 # reserved taint closure semicolon);
63 # no warnings qw(exec newline unopened); 85 # no warnings qw(exec newline unopened);
64
65 86
66=head1 DESCRIPTION 87=head1 DESCRIPTION
67 88
68 “Nothing is more fairly distributed than common sense: no one thinks 89 “Nothing is more fairly distributed than common sense: no one thinks
69 he needs more of it than he already has.” 90 he needs more of it than he already has.”
160 for (@{ $var->[0] }) { ... 181 for (@{ $var->[0] }) { ...
161 182
162If that isn't hypocrisy! And all that from a mere program! 183If that isn't hypocrisy! And all that from a mere program!
163 184
164 185
165=item use feature qw(say state given) 186=item use feature qw(say state given ...)
166 187
167We found it annoying that we always have to enable extra features. If 188We found it annoying that we always have to enable extra features. If
168something breaks because it didn't anticipate future changes, so be 189something breaks because it didn't anticipate future changes, so be
169it. 5.10 broke almost all our XS modules and nobody cared either (or at 190it. 5.10 broke almost all our XS modules and nobody cared either (or at
170least I know of nobody who really complained about gratuitous changes - 191least I know of nobody who really complained about gratuitous changes -
180older versions of perl - common::sense of course works there as well. 201older versions of perl - common::sense of course works there as well.
181There is also an important other mode where having additional features by 202There is also an important other mode where having additional features by
182default is useful: commandline hacks and internal use scripts: See "much 203default is useful: commandline hacks and internal use scripts: See "much
183reduced typing", below. 204reduced typing", below.
184 205
206There is one notable exception: C<unicode_eval> is not enabled by
207default. In our opinion, C<use feature> had one main effect - newer perl
208versions don't value backwards compatibility and the ability to write
209modules for multiple perl versions much, after all, you can use feature.
210
211C<unicode_eval> doesn't add a new feature, it breaks an existing function.
185 212
186=item no warnings, but a lot of new errors 213=item no warnings, but a lot of new errors
187 214
188Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w> 215Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w>
189switch: Even though we don't care if other people use warnings (and 216switch: Even though we don't care if other people use warnings (and
274our $VERSION = '3.5'; 301our $VERSION = '3.5';
275 302
276# overload should be included 303# overload should be included
277 304
278sub import { 305sub import {
279 local $^W; # work around perl 5.16 spewing out warnings for next line 306 local $^W; # work around perl 5.16 spewing out warnings for next statement
280IMPORT 307IMPORT
281 # use feature
282 $^H{feature_switch} =
283 $^H{feature_say} =
284 $^H{feature_state} = 1;
285} 308}
286 309
2871; 3101;
288 311
289=back 312=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines