Policy/ControlStructures/ProhibitInlineDo.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 81.8% 18 / 22 Conditioncond 70.0% 7 / 10 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 12 / 12 Podpod 80.0% 4 / 5 totaltotal 89.0% 98 / 110 CC 16 SCAR 18.5
CC
16
Cov
91%
violates
11.0
_cmpLocation
6.7
BEGIN
1.0
CRAP 6.3
« Policy/CodeLayout/RequireParensWithBuiltins.pm ↑ Summary Policy/Variables/ProhibitExcessiveNames.pm »
1 package Perl::Critic::Policy::ControlStructures::ProhibitInlineDo;
2  
3 11 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use Perl::Critic::Utils qw/:severities :classification/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 our $VERSION = '0.1.4';
12  
13 11 Readonly::Scalar my $DESC => q{Do not use inline do-blocks};
14 11 Readonly::Scalar my $EXPL => undef; # [ ];
15  
16 #-----------------------------------------------------------------------------
17  
18 12 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
19 4 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
20 1 ▶sub default_themes { return qw/maintenance complexity/ }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
21 2 ▶sub supported_parameters { return }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
22  
23 #-----------------------------------------------------------------------------
24  
25 7 ▶sub _cmpLocation {
Subroutine _cmpLocation: called CC=6 SCAR=19.0
26 7 my ($L,$R)=@_;
27 7 ▶ my @ll=@{$L->location()//[]};
Condition50%1/2
$L->location // []
l!l
70
MC/DC0%0/1
$L->location // []
$L->location
Truth table50%1/2
A
A= $L->location
Aresult
11
00
28 7 ▶ my @rr=@{$R->location()//[]};
Condition50%1/2
$R->location // []
l!l
70
MC/DC0%0/1
$R->location // []
$R->location
Truth table50%1/2
A
A= $R->location
Aresult
11
00
29 7 ▶ @ll or return;
Branch: 1 branch
BranchTrueFalseTotal
@ll or return 7 0 7
30 7 ▶ @rr or return;
Branch: 1 branch
BranchTrueFalseTotal
@rr or return 7 0 7
31 7 ▶ return ($ll[0]<=>$rr[0]) || ($ll[1]<=>$rr[1]);
Condition66%2/3
$ll[0] <=> $rr[0] || $ll[1] <=> $rr[1]
l!l&&r!l&&!r
043
MC/DC50%1/2
$ll[0] <=> $rr[0] || $ll[1] <=> $rr[1]
$ll[0] <=> $rr[0] $ll[1] <=> $rr[1]
Truth table66%2/3
A || B
A= $ll[0] <=> $rr[0]B= $ll[1] <=> $rr[1]
ABresult
1X1
011
000
32 }
33  
34 33 ▶sub violates {
Subroutine violates: called CC=11 SCAR=24.0
Pod documented
35 33 my ($self,$elem,undef)=@_;
36 33 ▶ if(!$elem->isa('PPI::Token::Word')) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem->isa("PPI::Token::Word")) 1 32 33
37 32 ▶ if(!is_perl_bareword($elem)) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless (is_perl_bareword($elem)) 9 23 32
38 23 ▶ if(is_method_call($elem)) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (is_method_call($elem)) 1 22 23
39 22 ▶ if($elem->content() ne 'do') { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->content ne "do") 8 14 22
40  
41 14 my $next=$elem->snext_sibling();
42 14 ▶ if(!$next || !$next->isa('PPI::Structure::Block')) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($next and $next->isa("PPI::Structure::Block")) 4 10 14
Condition100%3/3
$next and $next->isa("PPI::Structure::Block")
!ll&&!rl&&r
1310
MC/DC100%2/2
$next and $next->isa("PPI::Structure::Block")
$next $next->isa("PPI::Structure::Block")
Truth table100%3/3
A and B
A= $nextB= $next->isa("PPI::Structure::Block")
ABresult
0X0
100
111
43  
44 10 my $parent=$elem->parent();
45 0 ▶ if(!$parent) { return $self->violation($DESC,$EXPL,$elem) } # impossible?
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent) 0 10 10
46 10 ▶ if($parent->isa('PPI::Statement::Sub')) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->isa("PPI::Statement::Sub")) 3 7 10
47 7 ▶ if($parent->isa('PPI::Statement')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->isa("PPI::Statement")) 7 0 7
48 7 my $token=$parent->first_token();
49 7 ▶ if(0==_cmpLocation($elem,$token)) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (0 == _cmpLocation($elem, $token)) 3 4 7
50 }
51 4 return $self->violation($DESC,$EXPL,$elem);
52 }
53  
54 #-----------------------------------------------------------------------------
55  
56 11 1;
57  
58 __END__
« Policy/CodeLayout/RequireParensWithBuiltins.pm ↑ Summary Policy/Variables/ProhibitExcessiveNames.pm »