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