File Coverage

blib/lib/Perl/Lint/Policy/Subroutines/ProhibitNestedSubs.pm
Criterion Covered Total %
statement 30 30 100.0
branch 11 12 91.6
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 47 49 95.9


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::Subroutines::ProhibitNestedSubs;
2 133     133   67183 use strict;
  133         192  
  133         3249  
3 133     133   419 use warnings;
  133         183  
  133         2578  
4 133     133   846 use Perl::Lint::Constants::Type;
  133         163  
  133         59994  
5 133     133   639 use parent "Perl::Lint::Policy";
  133         206  
  133         569  
6              
7             # TODO msg!
8             use constant {
9 133         24880 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 133     133   7241 };
  133         182  
13              
14             sub evaluate {
15 6     6 0 13 my ($class, $file, $tokens, $args) = @_;
16              
17 6         5 my @violations;
18 6         17 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
19 26         23 my $token_type = $token->{type};
20              
21 26 100       48 if ($token_type == FUNCTION) {
22 9         7 my $left_brace_num = 0;
23 9         14 for ($i++; my $token = $tokens->[$i]; $i++) {
24 81         63 my $token_type = $token->{type};
25 81 100       173 if ($token_type == FUNCTION) {
    100          
    100          
26 4 50       9 if ($left_brace_num > 0) {
27             push @violations, {
28             filename => $file,
29             line => $token->{line},
30 4         22 description => DESC,
31             explanation => EXPL,
32             policy => __PACKAGE__,
33             };
34             }
35             }
36             elsif ($token_type == LEFT_BRACE) {
37 18         27 $left_brace_num++;
38             }
39             elsif ($token_type == RIGHT_BRACE) {
40 18         9 $left_brace_num--;
41 18 100       47 last if $left_brace_num <= 0;
42             }
43             }
44             }
45             }
46              
47 6         23 return \@violations;
48             }
49              
50             1;
51