port build system to new style, fix POD tests to pass
[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 }) {
eae006ee 28 indirect->unimport(':fatal');
394c3a46 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.
eae006ee 108
109=head1 METHODS
110
111=head2 import
112
113This method does the setup work described above in L</DESCRIPTION>
114
115=head2 VERSION
116
117This method traps the strictures->VERSION(1) call produced by a use line
118with a version number on it and does the version check.
119
120=head1 COMMUNITY AND SUPPORT
121
122=head2 IRC channel
123
124irc.perl.org #toolchain
125
126(or bug 'mst' in query on there or freenode)
127
128=head2 Git repository
129
130Gitweb is on http://git.shadowcat.co.uk/ and the clone URL is:
131
132 git clone git://git.shadowcat.co.uk/p5sagit/strictures.git
133
134=head1 AUTHOR
135
136Matt S. Trout <mst@shadowcat.co.uk>
137
138=head1 CONTRIBUTORS
139
140None required yet. Maybe this module is perfect (hahahahaha ...).
141
142=head1 COPYRIGHT
143
144Copyright (c) 2010 the strictures L</AUTHOR> and L</CONTRIBUTORS>
145as listed above.
146
147=head1 LICENSE
148
149This library is free software and may be distributed under the same terms
150as perl itself.
151
152=cut