strictures.pm

filter: Statementstmt 100% 85 / 85 Branchbran 95.6% 44 / 46 Conditioncond 50.0% 15 / 30 MC/DCmcdc 38.4% 5 / 13 Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 86.6% 162 / 187 SCAR 36.0
CC
35
Cov
89%
_want_extra
23.3
_enable_1
5.0
_enable_2
5.0
CRAP 36.4
↑ Summary strictures/extra.pm »
1 package strictures;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 BEGIN {
7 3 ▶ *_PERL_LT_5_8_4 = ($] < 5.008004) ? sub(){1} : sub(){0};
Subroutine BEGIN: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
$] < 5.008004 ? : 0 3 3
8 # goto &UNIVERSAL::VERSION usually works on 5.8, but fails on some ARM
9 # machines. Seems to always work on 5.10 though.
10 3 ▶ *_CAN_GOTO_VERSION = ($] >= 5.010000) ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
$] >= 5.01 ? : 3 0 3
11 }
12  
13 3 our $VERSION = '2.000003';
14 3 $VERSION = eval $VERSION;
15  
16 3 our @WARNING_CATEGORIES = grep { exists $warnings::Offsets{$_} } qw(
17 closure
18 chmod
19 deprecated
20 exiting
21 experimental
22 experimental::autoderef
23 experimental::bitwise
24 experimental::const_attr
25 experimental::lexical_subs
26 experimental::lexical_topic
27 experimental::postderef
28 experimental::re_strict
29 experimental::refaliasing
30 experimental::regex_sets
31 experimental::signatures
32 experimental::smartmatch
33 experimental::win32_perlio
34 glob
35 imprecision
36 io
37 closed
38 exec
39 layer
40 newline
41 pipe
42 syscalls
43 unopened
44 locale
45 misc
46 missing
47 numeric
48 once
49 overflow
50 pack
51 portable
52 recursion
53 redefine
54 redundant
55 regexp
56 severe
57 debugging
58 inplace
59 internal
60 malloc
61 signal
62 substr
63 syntax
64 ambiguous
65 bareword
66 digit
67 illegalproto
68 parenthesis
69 precedence
70 printf
71 prototype
72 qw
73 reserved
74 semicolon
75 taint
76 threads
77 uninitialized
78 umask
79 unpack
80 untie
81 utf8
82 non_unicode
83 nonchar
84 surrogate
85 void
86 void_unusual
87 y2k
88 );
89  
90 sub VERSION {
91 {
92 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine VERSION: called CC=3 SCAR=11.0
Pod documented
93 33 local $@;
94 33 ▶ if (defined $_[1] && eval { &UNIVERSAL::VERSION; 1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1] and eval { do { &UNIVERSAL::VERSION; 1 } }) 31 2 33
Condition100%3/3
defined $_[1] and eval { do { &UNIVERSAL::VERSION; 1 } }
!ll&&!rl&&r
1131
MC/DC100%2/2
defined $_[1] and eval { do { &UNIVERSAL::VERSION; 1 } }
defined $_[1] eval { do { &UNIVERSAL::VERSION; 1 } }
Truth table100%3/3
A and B
A= defined $_[1]B= eval { do { &UNIVERSAL::VERSION; 1 } }
ABresult
0X0
100
111
95 31 $^H |= 0x20000
96 unless _PERL_LT_5_8_4;
97 31 $^H{strictures_enable} = int $_[1];
98 }
99 }
100 33 _CAN_GOTO_VERSION ? goto &UNIVERSAL::VERSION : &UNIVERSAL::VERSION;
101 }
102  
103 3 our %extra_load_states;
104  
105 3 our $Smells_Like_VCS;
106  
107 sub import {
108 34 ▶ my $class = shift;
Subroutine import: called CC=4 SCAR=13.9
109 34 ▶ my %opts = @_ == 1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 2 32 34
110 34 ▶ if (!exists $opts{version}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"version"}) 32 2 34
111 $opts{version}
112 = exists $^H{strictures_enable} ? delete $^H{strictures_enable}
113 32 ▶ : int $VERSION;
Branch: 1 branch
BranchTrueFalseTotal
exists $^H{'strictures_enable'} ? : 31 1 32
114 }
115 34 $opts{file} = (caller)[1];
116 34 $class->_enable(\%opts);
117 }
118  
119 sub _enable {
120 34 ▶ my ($class, $opts) = @_;
Subroutine _enable: called CC=3 SCAR=11.0
121 34 my $version = $opts->{version};
122 34 ▶ $version = 'undef'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 1 33 34
123 if !defined $version;
124 34 my $method = "_enable_$version";
125 34 ▶ if (!$class->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can($method)) 2 32 34
126 2 require Carp;
127 2 Carp::croak("Major version specified as $version - not supported!");
128 }
129 32 $class->$method($opts);
130 }
131  
132 sub _enable_1 {
133 15 ▶ my ($class, $opts) = @_;
Subroutine _enable_1: called CC=5 SCAR=16.1
134 15 strict->import;
135 15 warnings->import(FATAL => 'all');
136  
137 15 ▶ if (_want_extra($opts->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_want_extra($opts->{"file"})) 8 7 15
138 8 _load_extras(qw(indirect multidimensional bareword::filehandles));
139 indirect->unimport(':fatal')
140 8 ▶ if $extra_load_states{indirect};
Branch: 1 branch
BranchTrueFalseTotal
if $strictures::extra_load_states{"indirect"} 6 2 8
141 multidimensional->unimport
142 8 ▶ if $extra_load_states{multidimensional};
Branch: 1 branch
BranchTrueFalseTotal
if $strictures::extra_load_states{"multidimensional"} 6 2 8
143 bareword::filehandles->unimport
144 8 ▶ if $extra_load_states{'bareword::filehandles'};
Branch: 1 branch
BranchTrueFalseTotal
if $strictures::extra_load_states{"bareword::filehandles"} 6 2 8
145 }
146 }
147  
148 3 our @V2_NONFATAL = grep { exists $warnings::Offsets{$_} } (
149 'exec', # not safe to catch
150 'recursion', # will be caught by other mechanisms
151 'internal', # not safe to catch
152 'malloc', # not safe to catch
153 'newline', # stat on nonexistent file with a newline in it
154 'experimental', # no reason for these to be fatal
155 'deprecated', # unfortunately can't make these fatal
156 'portable', # everything worked fine here, just may not elsewhere
157 );
158 3 our @V2_DISABLE = grep { exists $warnings::Offsets{$_} } (
159 'once' # triggers inconsistently, can't be fatalized
160 );
161  
162 sub _enable_2 {
163 17 ▶ my ($class, $opts) = @_;
Subroutine _enable_2: called CC=5 SCAR=16.1
164 17 strict->import;
165 17 warnings->import;
166 17 warnings->import(FATAL => @WARNING_CATEGORIES);
167 17 warnings->unimport(FATAL => @V2_NONFATAL);
168 17 warnings->import(@V2_NONFATAL);
169 17 warnings->unimport(@V2_DISABLE);
170  
171 17 ▶ if (_want_extra($opts->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_want_extra($opts->{"file"})) 9 8 17
172 9 _load_extras(qw(indirect multidimensional bareword::filehandles));
173 indirect->unimport(':fatal')
174 9 ▶ if $extra_load_states{indirect};
Branch: 1 branch
BranchTrueFalseTotal
if $strictures::extra_load_states{"indirect"} 6 3 9
175 multidimensional->unimport
176 9 ▶ if $extra_load_states{multidimensional};
Branch: 1 branch
BranchTrueFalseTotal
if $strictures::extra_load_states{"multidimensional"} 6 3 9
177 bareword::filehandles->unimport
178 9 ▶ if $extra_load_states{'bareword::filehandles'};
Branch: 1 branch
BranchTrueFalseTotal
if $strictures::extra_load_states{"bareword::filehandles"} 6 3 9
179 }
180 }
181  
182 sub _want_extra_env {
183 32 ▶ if (exists $ENV{PERL_STRICTURES_EXTRA}) {
Subroutine _want_extra_env: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"PERL_STRICTURES_EXTRA"}) 8 24 32
184 8 if (_PERL_LT_5_8_4 and $ENV{PERL_STRICTURES_EXTRA}) {
185 die 'PERL_STRICTURES_EXTRA checks are not available on perls older'
186 . "than 5.8.4: please unset \$ENV{PERL_STRICTURES_EXTRA}\n";
187 }
188 8 ▶ return $ENV{PERL_STRICTURES_EXTRA} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PERL_STRICTURES_EXTRA'} ? : 5 3 8
189 }
190 24 return undef;
191 }
192  
193 sub _want_extra {
194 32 ▶ my $file = shift;
Subroutine _want_extra: called CC=12 SCAR=31.5
195 32 my $want_env = _want_extra_env();
196 32 ▶ return $want_env
Branch: 1 branch
BranchTrueFalseTotal
if defined $want_env 8 24 32
197 if defined $want_env;
198 return (
199 24 ▶ !_PERL_LT_5_8_4
Branch: 1 branch
BranchTrueFalseTotal
defined $strictures::Smells_Like_VCS ? : 10 4 14
Condition44%12/27
$file =~ m[^(?:t|xt|lib|blib)[\\/]] && (defined $strictures::Smells_Like_VCS ? $strictures::Smells_Like_VCS : ($strictures::Smells_Like_VCS = !!(-e '.git' || -e '.svn' || -e '.hg' || -e '.bzr' || -e '../../dist.ini' && (-e '../../.git' || -e '../../.svn' || -e '../../.hg' || -e '../../.bzr'))))
!ll&&!rl&&r
10212
-e '.git' || -e '.svn' || -e '.hg' || -e '.bzr' || -e '../../dist.ini' && (-e '../../.git' || -e '../../.svn' || -e '../../.hg' || -e '../../.bzr')
l!l&&r!l&&!r
202
-e ".git" or -e ".svn" or -e ".hg" or -e ".bzr"
l!l&&r!l&&!r
202
-e ".git" or -e ".svn" or -e ".hg"
l!l&&r!l&&!r
202
-e ".git" or -e ".svn"
l!l&&r!l&&!r
202
-e "../../dist.ini" and -e "../../.git" || -e "../../.svn" || -e "../../.hg" || -e "../../.bzr"
!ll&&!rl&&r
200
-e "../../.git" or -e "../../.svn" or -e "../../.hg" or -e "../../.bzr"
l!l&&r!l&&!r
000
-e "../../.git" or -e "../../.svn" or -e "../../.hg"
l!l&&r!l&&!r
000
-e "../../.git" or -e "../../.svn"
l!l&&r!l&&!r
000
MC/DC100%2/2
$file =~ m[^(?:t|xt|lib|blib)[\\/]] && (defined $strictures::Smells_Like_VCS ? $strictures::Smells_Like_VCS : ($strictures::Smells_Like_VCS = !!(-e '.git' || -e '.svn' || -e '.hg' || -e '.bzr' || -e '../../dist.ini' && (-e '../../.git' || -e '../../.svn' || -e '../../.hg' || -e '../../.bzr'))))
$file =~ m[^(?:t|xt|lib|blib)[\\/]] (defined $strictures::Smells_Like_VCS ? $strictures::Smells_Like_VCS : ($strictures::Smells_Like_VCS = !!(-e '.git' || -e '.svn' || -e '.hg' || -e '.bzr' || -e '../../dist.ini' && (-e '../../.git' || -e '../../.svn' || -e '../../.hg' || -e '../../.bzr'))))
MC/DC11%1/9
-e '.git' || -e '.svn' || -e '.hg' || -e '.bzr' || -e '../../dist.ini' && (-e '../../.git' || -e '../../.svn' || -e '../../.hg' || -e '../../.bzr')
-e ".git" -e ".svn" -e ".hg" -e ".bzr" -e "../../dist.ini" -e "../../.git" -e "../../.svn" -e "../../.hg" -e "../../.bzr"
Truth table100%3/3
A && B
A= $file =~ m[^(?:t|xt|lib|blib)[\\/]]B= (defined $strictures::Smells_Like_VCS ? $strictures::Smells_Like_VCS : ($strictures::Smells_Like_VCS = !!(-e '.git' || -e '.svn' || -e '.hg' || -e '.bzr' || -e '../../dist.ini' && (-e '../../.git' || -e '../../.svn' || -e '../../.hg' || -e '../../.bzr'))))
ABresult
0X0
100
111
Truth table20%2/10
A or B or C or D || E and F or G or H or I
A= -e ".git"B= -e ".svn"C= -e ".hg"D= -e ".bzr"E= -e "../../dist.ini"F= -e "../../.git"G= -e "../../.svn"H= -e "../../.hg"I= -e "../../.bzr"
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
000011XXX1
0000101XX1
00001001X1
0000100011
00000XXXX0
0000100000
200 and $file =~ /^(?:t|xt|lib|blib)[\\\/]/
201 and defined $Smells_Like_VCS ? $Smells_Like_VCS
202 : ( $Smells_Like_VCS = !!(
203 -e '.git' || -e '.svn' || -e '.hg' || -e '.bzr'
204 || (-e '../../dist.ini'
205 && (-e '../../.git' || -e '../../.svn' || -e '../../.hg' || -e '../../.bzr' ))
206 ))
207 );
208 }
209  
210 sub _load_extras {
211 17 ▶ my @extras = @_;
Subroutine _load_extras: called CC=5 SCAR=16.1
212 17 my @failed;
213 17 foreach my $mod (@extras) {
214 next
215 51 ▶ if exists $extra_load_states{$mod};
Branch: 1 branch
BranchTrueFalseTotal
if exists $strictures::extra_load_states{$mod} 39 12 51
216  
217 12 ▶ $extra_load_states{$mod} = eval "require $mod; 1;" or do {
Branch: 1 branch
BranchTrueFalseTotal
$strictures::extra_load_states{$mod} = eval "require $mod; 1;" or do { push @failed, $mod; (my $file = $mod) =~ s[::][/]g; delete $INC{"$file.pm"} } 9 3 12
218 9 push @failed, $mod;
219  
220 #work around 5.8 require bug
221 9 (my $file = $mod) =~ s|::|/|g;
222 9 delete $INC{"${file}.pm"};
223 };
224 }
225  
226 17 ▶ if (@failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed) 3 14 17
227 3 my $failed = join ' ', @failed;
228 3 my $extras = join ' ', @extras;
229 3 print STDERR <<EOE;
230 strictures.pm extra testing active but couldn't load all modules. Missing were:
231  
232 $failed
233  
234 Extra testing is auto-enabled in checkouts only, so if you're the author
235 of a strictures-using module you need to run:
236  
237 cpan $extras
238  
239 but these modules are not required by your users.
240 EOE
241 }
242 }
243  
244 3 1;
245  
246 __END__
↑ Summary strictures/extra.pm »