Release commit for 1.002002
[p5sagit/strictures.git] / lib / strictures.pm
CommitLineData
394c3a46 1package strictures;
2
3use strict;
4use warnings FATAL => 'all';
5
23d8c3be 6our $VERSION = '1.002002'; # 1.2.2
394c3a46 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 }
0925b84b 13 # disable this since Foo->VERSION(undef) correctly returns the version
14 # and that can happen either if our caller passes undef explicitly or
15 # because the for above autovivified $_[1] - I could make it stop but
16 # it's pointless since we don't want to blow up if the caller does
17 # something valid either.
18 no warnings 'uninitialized';
394c3a46 19 shift->SUPER::VERSION(@_);
20}
21
22sub import {
23 strict->import;
24 warnings->import(FATAL => 'all');
653f4377 25 my $extra_tests = do {
394c3a46 26 if (exists $ENV{PERL_STRICTURES_EXTRA}) {
27 $ENV{PERL_STRICTURES_EXTRA}
28 } else {
dca7f184 29 !!($0 =~ /^x?t\/.*(?:load|compile|coverage|use_ok).*\.t$/
30 and (-e '.git' or -e '.svn'))
394c3a46 31 }
32 };
653f4377 33 if ($extra_tests) {
34 if (eval {
35 require indirect;
36 require multidimensional;
37 require bareword::filehandles;
38 1
39 }) {
eae006ee 40 indirect->unimport(':fatal');
653f4377 41 multidimensional->unimport;
42 bareword::filehandles->unimport;
394c3a46 43 } else {
653f4377 44 die "strictures.pm extra testing active but couldn't load modules.
0925b84b 45Extra testing is auto-enabled in checkouts only, so if you're the author
653f4377 46of a strictures using module you need to run:
47
48 cpan indirect multidimensional bareword::filehandles
49
50but these modules are not required by your users.
51
52Error loading modules was: $@";
394c3a46 53 }
54 }
55}
56
571;
58
59__END__
60=head1 NAME
61
62strictures - turn on strict and make all warnings fatal
63
64=head1 SYNOPSIS
65
66 use strictures 1;
67
68is equivalent to
69
70 use strict;
71 use warnings FATAL => 'all';
72
73except when called from a file where $0 matches:
74
dca7f184 75 /^x?t\/.*(?:load|compile|coverage|use_ok).*\.t$/
394c3a46 76
dca7f184 77and when either '.git' or '.svn' is present in the current directory (with
78the intention of only forcing extra tests on the author side) - or when the
79PERL_STRICTURES_EXTRA environment variable is set, in which case
394c3a46 80
81 use strictures 1;
82
83is equivalent to
84
85 use strict;
86 use warnings FATAL => 'all';
87 no indirect 'fatal';
653f4377 88 no multidimensional;
89 no bareword::filehandles;
394c3a46 90
91Note that _EXTRA may at some point add even more tests, with only a minor
92version increase, but any changes to the effect of 'use strictures' in
93normal mode will involve a major version bump.
94
653f4377 95Be aware: THIS MEANS THE EXTRA TEST MODULES ARE REQUIRED FOR AUTHORS OF
96STRICTURES USING CODE - but not by end users thereof.
17b03f2e 97
394c3a46 98=head1 DESCRIPTION
99
100I've been writing the equivalent of this module at the top of my code for
101about a year now. I figured it was time to make it shorter.
102
103Things like the importer in 'use Moose' don't help me because they turn
104warnings on but don't make them fatal - which from my point of view is
105useless because I want an exception to tell me my code isn't warnings clean.
106
107Any time I see a warning from my code, that indicates a mistake.
108
109Any time my code encounters a mistake, I want a crash - not spew to STDERR
110and then unknown (and probably undesired) subsequent behaviour.
111
112I also want to ensure that obvious coding mistakes, like indirect object
113syntax (and not so obvious mistakes that cause things to accidentally compile
114as such) get caught, but not at the cost of an XS dependency and not at the
115cost of blowing things up on another machine.
116
117Therefore, strictures turns on indirect checking only when it thinks it's
118running in a compilation (or pod coverage) test - though if this causes
93ae637e 119undesired behaviour this can be overridden by setting the
394c3a46 120PERL_STRICTURES_EXTRA environment variable.
121
122If additional useful author side checks come to mind, I'll add them to the
123_EXTRA code path only - this will result in a minor version increase (i.e.
1241.000000 to 1.001000 (1.1.0) or similar). Any fixes only to the mechanism of
125this code will result in a subversion increas (i.e. 1.000000 to 1.000001
126(1.0.1)).
127
128If the behaviour of 'use strictures' in normal mode changes in any way, that
129will constitute a major version increase - and the code already checks
130when its version is tested to ensure that
131
132 use strictures 1;
133
134will continue to only introduce the current set of strictures even if 2.0 is
135installed.
eae006ee 136
137=head1 METHODS
138
139=head2 import
140
141This method does the setup work described above in L</DESCRIPTION>
142
143=head2 VERSION
144
145This method traps the strictures->VERSION(1) call produced by a use line
146with a version number on it and does the version check.
147
148=head1 COMMUNITY AND SUPPORT
149
150=head2 IRC channel
151
152irc.perl.org #toolchain
153
154(or bug 'mst' in query on there or freenode)
155
156=head2 Git repository
157
158Gitweb is on http://git.shadowcat.co.uk/ and the clone URL is:
159
160 git clone git://git.shadowcat.co.uk/p5sagit/strictures.git
161
162=head1 AUTHOR
163
d81f898d 164mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
eae006ee 165
166=head1 CONTRIBUTORS
167
168None required yet. Maybe this module is perfect (hahahahaha ...).
169
170=head1 COPYRIGHT
171
172Copyright (c) 2010 the strictures L</AUTHOR> and L</CONTRIBUTORS>
173as listed above.
174
175=head1 LICENSE
176
177This library is free software and may be distributed under the same terms
178as perl itself.
179
180=cut