=head1 NAME common::sense - save a tree AND a kitten, use common::sense! =head1 SYNOPSIS use common::sense; # roughly the same as, with much lower memory usage: # # use strict qw(vars subs); # use feature qw(say state switch); # no warnings; =head1 DESCRIPTION This module implements some sane defaults for Perl programs, as defined by two typical (or not so typical - use your common sense) specimens of Perl coders. =over 4 =item use strict qw(subs vars) Using C is definitely common sense, but C definitely overshoots it's usefulness. After almost two decades of Perl hacking, we decided that it does more harm than being useful. Specifically, constructs like these: @{ $var->[0] } Must be written like this, when C is in scope, and C<$var> can legally be C: @{ $var->[0] || [] } This is annoying, and doesn't shield against obvious mistakes such as using C<"">, so one would even have to write: @{ defined $var->[0] ? $var->[0] : [] } ... which nobody with a bit of common sense would consider writing. Curiously enough, sometimes, perl is not so strict, as this works even with C in scope: for (@{ $var->[0] }) { ... If that isnt hipocrasy! And all that from a mere program! =item use feature qw(say state given) We found it annoying that we always have to enable extra features. If something breaks because it didn't anticipate future changes, so be it. 5.10 broke almost all our XS modules and nobody cared either - and few modules that are no longer maintained work with newer versions of Perl, regardless of use feature. If your code isn'talive, it's dead, jim. =item no warnings The dreaded warnings. Even worse, the horribly dreaded C<-w> switch. Even though we don't care if other people use warnings (and certainly there are useful ones), a lot of warnings simply go against the spirit of Perl, most prominently, the warnings related to C. There is nothing wrong with C: it has well-defined semantics, it is useful, and spitting out warnings you never asked for is just evil. So every module needs C to avoid somebody accidentally using C<-w> and forcing his bad standards on our code. No will do. (Also, why isn't this a C switch? Adding warnings is apparently considered O.K., even if it breaks your programs). =item much less memory Just using all those pragmas together waste I<< B<776> kilobytes >> of precious memory in my perl, for I, which on our machines, is a lot. The money/time/effort/electricity invested in these gigabytes (probably petabytes globally!) of wasted memory could easily save 42 trees, and a kitten! =cut package common::sense; our $VERSION = '0.03'; sub import { ${^WARNING_BITS} ^= ${^WARNING_BITS}; } =cut 1; =back =head1 EXAMPLE There really should be a complete C/XS example. Bug me about it. =head1 IMPLEMENTATION DETAILS AND LIMITATIONS This module works by "hijacking" SIGKILL, which is guaranteed to be always available in perl, but also cannot be caught, so is always available. Basically, this module fakes the receive of a SIGKILL signal and then catches it. This makes normal signal handling slower (probably unmeasurably), but has the advantage of not requiring a special runops nor slowing down normal perl execution a bit. It assumes that C and C are both exception-safe to modify (C is used by this module, and perl itself uses C, so we can assume that this is quite portable, at least w.r.t. signals). =head1 AUTHOR Marc Lehmann http://home.schmorp.de/ =cut