tweak extra testing to not fire user side
[p5sagit/strictures.git] / lib / strictures.pm
CommitLineData
394c3a46 1package strictures;
2
3use strict;
4use warnings FATAL => 'all';
5
dca7f184 6our $VERSION = '1.001000'; # 1.1.0
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 }
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 {
dca7f184 23 !!($0 =~ /^x?t\/.*(?:load|compile|coverage|use_ok).*\.t$/
24 and (-e '.git' or -e '.svn'))
394c3a46 25 }
26 };
27 if ($do_indirect) {
28 if (eval { require indirect; 1 }) {
eae006ee 29 indirect->unimport(':fatal');
394c3a46 30 } else {
31 die "strictures.pm extra testing active but couldn't load indirect.pm: $@";
32 }
33 }
34}
35
361;
37
38__END__
39=head1 NAME
40
41strictures - turn on strict and make all warnings fatal
42
43=head1 SYNOPSIS
44
45 use strictures 1;
46
47is equivalent to
48
49 use strict;
50 use warnings FATAL => 'all';
51
52except when called from a file where $0 matches:
53
dca7f184 54 /^x?t\/.*(?:load|compile|coverage|use_ok).*\.t$/
394c3a46 55
dca7f184 56and when either '.git' or '.svn' is present in the current directory (with
57the intention of only forcing extra tests on the author side) - or when the
58PERL_STRICTURES_EXTRA environment variable is set, in which case
394c3a46 59
60 use strictures 1;
61
62is equivalent to
63
64 use strict;
65 use warnings FATAL => 'all';
66 no indirect 'fatal';
67
68Note that _EXTRA may at some point add even more tests, with only a minor
69version increase, but any changes to the effect of 'use strictures' in
70normal mode will involve a major version bump.
71
72=head1 DESCRIPTION
73
74I've been writing the equivalent of this module at the top of my code for
75about a year now. I figured it was time to make it shorter.
76
77Things like the importer in 'use Moose' don't help me because they turn
78warnings on but don't make them fatal - which from my point of view is
79useless because I want an exception to tell me my code isn't warnings clean.
80
81Any time I see a warning from my code, that indicates a mistake.
82
83Any time my code encounters a mistake, I want a crash - not spew to STDERR
84and then unknown (and probably undesired) subsequent behaviour.
85
86I also want to ensure that obvious coding mistakes, like indirect object
87syntax (and not so obvious mistakes that cause things to accidentally compile
88as such) get caught, but not at the cost of an XS dependency and not at the
89cost of blowing things up on another machine.
90
91Therefore, strictures turns on indirect checking only when it thinks it's
92running in a compilation (or pod coverage) test - though if this causes
93undesired behaviour this can be overriden by setting the
94PERL_STRICTURES_EXTRA environment variable.
95
96If additional useful author side checks come to mind, I'll add them to the
97_EXTRA code path only - this will result in a minor version increase (i.e.
981.000000 to 1.001000 (1.1.0) or similar). Any fixes only to the mechanism of
99this code will result in a subversion increas (i.e. 1.000000 to 1.000001
100(1.0.1)).
101
102If the behaviour of 'use strictures' in normal mode changes in any way, that
103will constitute a major version increase - and the code already checks
104when its version is tested to ensure that
105
106 use strictures 1;
107
108will continue to only introduce the current set of strictures even if 2.0 is
109installed.
eae006ee 110
111=head1 METHODS
112
113=head2 import
114
115This method does the setup work described above in L</DESCRIPTION>
116
117=head2 VERSION
118
119This method traps the strictures->VERSION(1) call produced by a use line
120with a version number on it and does the version check.
121
122=head1 COMMUNITY AND SUPPORT
123
124=head2 IRC channel
125
126irc.perl.org #toolchain
127
128(or bug 'mst' in query on there or freenode)
129
130=head2 Git repository
131
132Gitweb is on http://git.shadowcat.co.uk/ and the clone URL is:
133
134 git clone git://git.shadowcat.co.uk/p5sagit/strictures.git
135
136=head1 AUTHOR
137
138Matt S. Trout <mst@shadowcat.co.uk>
139
140=head1 CONTRIBUTORS
141
142None required yet. Maybe this module is perfect (hahahahaha ...).
143
144=head1 COPYRIGHT
145
146Copyright (c) 2010 the strictures L</AUTHOR> and L</CONTRIBUTORS>
147as listed above.
148
149=head1 LICENSE
150
151This library is free software and may be distributed under the same terms
152as perl itself.
153
154=cut