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