first version of strictures.pm - code and brief docs
[p5sagit/strictures.git] / lib / strictures.pm
CommitLineData
394c3a46 1package strictures;
2
3use strict;
4use warnings FATAL => 'all';
5
6our $VERSION = '1.000000'; # 1.0.0
7
8sub VERSION {
9 for ($_[1]) {
10 last unless defined && !ref && int != 1;
11 die "Major version specified as $_ - this is strictures version 1";
12 }
13 shift->SUPER::VERSION(@_);
14}
15
16sub import {
17 strict->import;
18 warnings->import(FATAL => 'all');
19 my $do_indirect = do {
20 if (exists $ENV{PERL_STRICTURES_EXTRA}) {
21 $ENV{PERL_STRICTURES_EXTRA}
22 } else {
23 !!($0 =~ /^x?t\/.*(?:load|compile|coverage).*\.t$/)
24 }
25 };
26 if ($do_indirect) {
27 if (eval { require indirect; 1 }) {
28 indirect->unimport('FATAL');
29 } else {
30 die "strictures.pm extra testing active but couldn't load indirect.pm: $@";
31 }
32 }
33}
34
351;
36
37__END__
38=head1 NAME
39
40strictures - turn on strict and make all warnings fatal
41
42=head1 SYNOPSIS
43
44 use strictures 1;
45
46is equivalent to
47
48 use strict;
49 use warnings FATAL => 'all';
50
51except when called from a file where $0 matches:
52
53 /^x?t\/.*(?:load|compile|coverage).*\.t$/
54
55or when the PERL_STRICTURES_EXTRA environment variable is set, in which
56case
57
58 use strictures 1;
59
60is equivalent to
61
62 use strict;
63 use warnings FATAL => 'all';
64 no indirect 'fatal';
65
66Note that _EXTRA may at some point add even more tests, with only a minor
67version increase, but any changes to the effect of 'use strictures' in
68normal mode will involve a major version bump.
69
70=head1 DESCRIPTION
71
72I've been writing the equivalent of this module at the top of my code for
73about a year now. I figured it was time to make it shorter.
74
75Things like the importer in 'use Moose' don't help me because they turn
76warnings on but don't make them fatal - which from my point of view is
77useless because I want an exception to tell me my code isn't warnings clean.
78
79Any time I see a warning from my code, that indicates a mistake.
80
81Any time my code encounters a mistake, I want a crash - not spew to STDERR
82and then unknown (and probably undesired) subsequent behaviour.
83
84I also want to ensure that obvious coding mistakes, like indirect object
85syntax (and not so obvious mistakes that cause things to accidentally compile
86as such) get caught, but not at the cost of an XS dependency and not at the
87cost of blowing things up on another machine.
88
89Therefore, strictures turns on indirect checking only when it thinks it's
90running in a compilation (or pod coverage) test - though if this causes
91undesired behaviour this can be overriden by setting the
92PERL_STRICTURES_EXTRA environment variable.
93
94If additional useful author side checks come to mind, I'll add them to the
95_EXTRA code path only - this will result in a minor version increase (i.e.
961.000000 to 1.001000 (1.1.0) or similar). Any fixes only to the mechanism of
97this code will result in a subversion increas (i.e. 1.000000 to 1.000001
98(1.0.1)).
99
100If the behaviour of 'use strictures' in normal mode changes in any way, that
101will constitute a major version increase - and the code already checks
102when its version is tested to ensure that
103
104 use strictures 1;
105
106will continue to only introduce the current set of strictures even if 2.0 is
107installed.