Policy/ValuesAndExpressions/RestrictLongStrings.pm

filter: Statementstmt 100% 39 / 39 Branchbran 90.0% 9 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 12 / 12 Podpod 80.0% 4 / 5 totaltotal 88.0% 66 / 75 CC 8 SCAR 14.2
CC
8
Cov
91%
violates
8.4
BEGIN
1.0
BEGIN
1.0
CRAP 4.1
↑ Summary Policy/ValuesAndExpressions/RequireConstantOnLeftSideOfEquality.pm »
1 #######################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-More/lib/Perl/Critic/Policy/ValuesAndExpressions/RestrictLongStrings.pm $
3 # $Date: 2013-10-29 09:39:11 -0700 (Tue, 29 Oct 2013) $
4 # $Author: thaljef $
5 # $Revision: 4222 $
6 ########################################################################
7  
8 package Perl::Critic::Policy::ValuesAndExpressions::RestrictLongStrings;
9  
10 7 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 7 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 7 our $VERSION = '1.003';
22  
23 #---------------------------------------------------------------------------
24  
25 7 Readonly::Scalar my $DESC => 'Long string mixed with code';
26 7 Readonly::Scalar my $EXPL =>
27 'Put long strings in their own subroutine or split them';
28  
29 #---------------------------------------------------------------------------
30  
31 8 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
32 1 ▶sub default_themes { return qw< more readability > }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
33 6 ▶sub applies_to { return 'PPI::Token::Quote' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
34  
35 10 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
36 return (
37 10 { name => 'max_length',
38 description => 'The maximum line length to allow.',
39 default_string => '78',
40 behavior => 'integer',
41 integer_minimum => 1,
42 },
43 );
44 }
45  
46 #---------------------------------------------------------------------------
47  
48 17 ▶sub violates {
Subroutine violates: called CC=8 SCAR=21.3
Pod documented
49 17 my ( $self, $elem, $doc ) = @_;
50  
51 17 my $length = length $elem->string;
52 17 ▶ return if $length <= $self->{_max_length};
Branch: 1 branch
BranchTrueFalseTotal
if $length <= $self->{"_max_length"} 8 9 17
53  
54 # Allow long strings in the last statment of a subroutine
55 9 my $stmt = $elem->statement;
56 9 ▶ if ( !$stmt->snext_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stmt->snext_sibling) 3 6 9
57 3 my $stmt_parent = $stmt->parent;
58 3 ▶ if ( $stmt_parent->isa('PPI::Structure::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt_parent->isa("PPI::Structure::Block")) 2 1 3
59  
60 # Named subroutine
61 2 ▶ return if $stmt_parent->parent->isa('PPI::Statement::Sub');
Branch: 1 branch
BranchTrueFalseTotal
if $stmt_parent->parent->isa("PPI::Statement::Sub") 1 1 2
62  
63 # Anonymous subroutine
64 1 my $sib = $stmt_parent->sprevious_sibling;
65 1 ▶ return if $sib && $sib->isa('PPI::Token::Word') && 'sub' eq $sib;
Branch: 1 branch
BranchTrueFalseTotal
if $sib and $sib->isa("PPI::Token::Word") and "sub" eq $sib 1 0 1
Condition33%2/6
$sib and $sib->isa("PPI::Token::Word") and "sub" eq $sib
!ll&&!rl&&r
001
$sib and $sib->isa("PPI::Token::Word")
!ll&&!rl&&r
001
MC/DC0%0/3
$sib and $sib->isa("PPI::Token::Word") and "sub" eq $sib
$sib $sib->isa("PPI::Token::Word") "sub" eq $sib
Truth table25%1/4
A and B and C
A= $sibB= $sib->isa("PPI::Token::Word")C= "sub" eq $sib
ABCresult
0XX0
10X0
1100
1111
66 }
67 }
68  
69 7 return $self->violation( $DESC, $EXPL, $elem );
70 }
71  
72 7 1;
73  
74 __END__
↑ Summary Policy/ValuesAndExpressions/RequireConstantOnLeftSideOfEquality.pm »