Perl/Lint/Policy/Subroutines/ProhibitNestedSubs.pm

filter: Statementstmt 51.6% 16 / 31 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 38.8% 21 / 54 CC 9 SCAR 40.6
CC
9
Cov
34%
evaluate
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 58.2
« Perl/Lint/Policy/Variables/RequireInitializationForLocalVars.pm ↑ Summary Perl/Lint/Policy/InputOutput/RequireBracedFileHandleWithPrint.pm »
1 package Perl::Lint::Policy::Subroutines::ProhibitNestedSubs;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # TODO msg!
8 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 DESC => 'Nested named subroutine',
10 EXPL => 'Declaring a named sub inside another named sub does not prevent the '
11 . 'inner sub from being global',
12 2 };
13  
14 0 ▶sub evaluate {
Subroutine evaluate: not called CC=9 SCAR=45.0
Pod undocumented
15 0 my ($class, $file, $tokens, $args) = @_;
16  
17 0 my @violations;
18 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
19 0 my $token_type = $token->{type};
20  
21 0 ▶ if ($token_type == FUNCTION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 203) 0 0 0
22 0 my $left_brace_num = 0;
23 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
24 0 my $token_type = $token->{type};
25 0 ▶ if ($token_type == FUNCTION) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 203) { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
26 0 ▶ if ($left_brace_num > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_brace_num > 0) 0 0 0
27 push @violations, {
28 filename => $file,
29 line => $token->{line},
30 0 description => DESC,
31 explanation => EXPL,
32 policy => __PACKAGE__,
33 };
34 }
35 }
36 elsif ($token_type == LEFT_BRACE) {
37 0 $left_brace_num++;
38 }
39 elsif ($token_type == RIGHT_BRACE) {
40 0 $left_brace_num--;
41 0 ▶ last if $left_brace_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $left_brace_num <= 0 0 0 0
42 }
43 }
44 }
45 }
46  
47 0 return \@violations;
48 }
49  
50 2 1;
51  
« Perl/Lint/Policy/Variables/RequireInitializationForLocalVars.pm ↑ Summary Perl/Lint/Policy/InputOutput/RequireBracedFileHandleWithPrint.pm »