File Coverage

blib/lib/Perl/Critic/Policy/TestingAndDebugging/ProhibitProlongedStrictureOverride.pm
Criterion Covered Total %
statement 23 31 74.1
branch 1 8 12.5
condition 0 6 0.0
subroutine 11 11 100.0
pod 4 5 80.0
total 39 61 63.9


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride;
2              
3 40     40   26438 use 5.010001;
  40         177  
4 40     40   268 use strict;
  40         134  
  40         897  
5 40     40   234 use warnings;
  40         166  
  40         952  
6 40     40   243 use Readonly;
  40         114  
  40         1884  
7              
8 40     40   303 use Perl::Critic::Utils qw{ :severities };
  40         122  
  40         1883  
9 40     40   4722 use parent 'Perl::Critic::Policy';
  40         155  
  40         239  
10              
11             our $VERSION = '1.150';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{Don't turn off strict for large blocks of code};
16             Readonly::Scalar my $EXPL => [ 433 ];
17              
18             #-----------------------------------------------------------------------------
19              
20             sub supported_parameters {
21             return (
22             {
23 90     90 0 2079 name => 'statements',
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 74     74 1 395 sub default_severity { return $SEVERITY_HIGH }
33 92     92 1 453 sub default_themes { return qw( core pbp bugs certrec ) }
34 32     32 1 95 sub applies_to { return 'PPI::Statement::Include' }
35              
36             #-----------------------------------------------------------------------------
37              
38             sub violates {
39 61     61 1 137 my ($self, $elem, $doc) = @_;
40              
41 61 50       150 return if $elem->type ne 'no';
42 0 0         return if $elem->module ne 'strict';
43              
44 0           my $sib = $elem->snext_sibling;
45 0           my $nstatements = 0;
46 0           while ($nstatements++ <= $self->{_statements}) {
47 0 0         return if !$sib;
48 0 0 0       return if $sib->isa('PPI::Statement::Include') &&
      0        
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             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 :