blib/lib/Perl/Critic/Policy/TestingAndDebugging/ProhibitProlongedStrictureOverride.pm

filter: Statementstmt 77.1% 27 / 35 Branchbran 10.0% 1 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 61.4% 43 / 70 CC 8 SCAR 31.7
CC
8
Cov
55%
violates
52.3
BEGIN
1.0
BEGIN
1.0
CRAP 23.8
« blib/lib/Perl/Critic/Policy/Subroutines/ProhibitManyArgs.pm ↑ Summary blib/lib/Perl/Critic/Policy/References/ProhibitDoubleSigils.pm »
1 package Perl::Critic::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.150';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{Don't turn off strict for large blocks of code};
16 40 Readonly::Scalar my $EXPL => [ 433 ];
17  
18 #-----------------------------------------------------------------------------
19  
20 sub supported_parameters {
21 return (
22 {
23 91 ▶ name => 'statements',
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
24 description => 'The maximum number of statements in a no strict block.',
25 default_string => '3',
26 behavior => 'integer',
27 integer_minimum => 1,
28 },
29 );
30 }
31  
32 75 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
33 92 ▶sub default_themes { return qw( core pbp bugs certrec ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
34 33 ▶sub applies_to { return 'PPI::Statement::Include' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
35  
36 #-----------------------------------------------------------------------------
37  
38 sub violates {
39 61 ▶ my ($self, $elem, $doc) = @_;
Subroutine violates: called CC=8 SCAR=39.6
Pod documented
40  
41 61 ▶ return if $elem->type ne 'no';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->type ne "no" 61 0 61
42 0 ▶ return if $elem->module ne 'strict';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->module ne "strict" 0 0 0
43  
44 0 my $sib = $elem->snext_sibling;
45 0 my $nstatements = 0;
46 0 ▶ while ($nstatements++ <= $self->{_statements}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nstatements++ <= $self->{"_statements"}) 0 0 0
47 0 ▶ return if !$sib;
Branch: 1 branch
BranchTrueFalseTotal
unless $sib 0 0 0
48 0 ▶ return if $sib->isa('PPI::Statement::Include') &&
Branch: 1 branch
BranchTrueFalseTotal
if $sib->isa("PPI::Statement::Include") and $sib->type eq "use" and $sib->module eq "strict" 0 0 0
Condition0%0/6
$sib->isa("PPI::Statement::Include") and $sib->type eq "use" and $sib->module eq "strict"
!ll&&!rl&&r
000
$sib->isa("PPI::Statement::Include") and $sib->type eq "use"
!ll&&!rl&&r
000
MC/DC0%0/3
$sib->isa("PPI::Statement::Include") and $sib->type eq "use" and $sib->module eq "strict"
$sib->isa("PPI::Statement::Include") $sib->type eq "use" $sib->module eq "strict"
Truth table0%0/4
A and B and C
A= $sib->isa("PPI::Statement::Include")B= $sib->type eq "use"C= $sib->module eq "strict"
ABCresult
0XX0
10X0
1100
1111
49 $sib->type eq 'use' &&
50 $sib->module eq 'strict';
51 0 $sib = $sib->snext_sibling;
52 }
53  
54 0 return $self->violation( $DESC, $EXPL, $elem );
55 }
56  
57 40 1;
58  
59 #-----------------------------------------------------------------------------
60  
61 __END__
62  
63 =pod
64  
65 =head1 NAME
66  
67 Perl::Critic::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride - Don't turn off strict for large blocks of code.
68  
69  
70 =head1 AFFILIATION
71  
72 This Policy is part of the core L<Perl::Critic|Perl::Critic>
73 distribution.
74  
75  
76 =head1 DESCRIPTION
77  
78 Every agrees that C<use strict> is the first step to writing
79 maintainable code in Perl. However, sometimes C<strict> is a little
80 too strict. In those cases, you can turn it off briefly with a C<no
81 strict> directive.
82  
83 This policy checks that C<no strict> is only in effect for a small
84 number of statements.
85  
86  
87 =head1 CONFIGURATION
88  
89 The default number of statements allowed per C<no strict> is three.
90 To override this number, put the following in your F<.perlcriticrc>:
91  
92 [TestingAndDebugging::ProhibitProlongedStrictureOverride]
93 statements = 5
94  
95  
96 =head1 AUTHOR
97  
98 Chris Dolan <cdolan@cpan.org>
99  
100  
101 =head1 COPYRIGHT
102  
103 Copyright (c) 2006-2011 Chris Dolan.
104  
105 This program is free software; you can redistribute it and/or modify
106 it under the same terms as Perl itself.
107  
108 =cut
109  
110 # Local Variables:
111 # mode: cperl
112 # cperl-indent-level: 4
113 # fill-column: 78
114 # indent-tabs-mode: nil
115 # c-indentation-style: bsd
116 # End:
117 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
« blib/lib/Perl/Critic/Policy/Subroutines/ProhibitManyArgs.pm ↑ Summary blib/lib/Perl/Critic/Policy/References/ProhibitDoubleSigils.pm »