Commit | Line | Data |
394c3a46 |
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. |