File Coverage

blib/lib/Perl/Lint/Policy/InputOutput/ProhibitExplicitStdin.pm
Criterion Covered Total %
statement 27 27 100.0
branch 8 8 100.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 44 45 97.7


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::InputOutput::ProhibitExplicitStdin;
2 133     133   100969 use strict;
  133         273  
  133         4902  
3 133     133   618 use warnings;
  133         212  
  133         3280  
4 133     133   942 use Perl::Lint::Constants::Type;
  133         191  
  133         83851  
5 133     133   864 use parent "Perl::Lint::Policy";
  133         262  
  133         938  
6              
7             use constant {
8 133         30179 DESC => 'Use "<>" or "" or a prompting module instead of ""',
9             EXPL => [216, 220, 221],
10 133     133   9666 };
  133         257  
11              
12             sub evaluate {
13 4     4 0 6 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 4         6 my @violations;
16 4         3 my $is_in_context_of_close = 0;
17 4         14 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 141         111 my $token_type = $token->{type};
19 141         110 my $token_data = $token->{data};
20              
21 141 100 100     446 if ($token_type == TYPE_STDIN) {
    100          
    100          
22 13 100       20 next if $is_in_context_of_close;
23 12         48 push @violations, {
24             filename => $file,
25             line => $token->{line},
26             description => DESC,
27             explanation => EXPL,
28             policy => __PACKAGE__,
29             };
30             }
31             elsif ($token_type == BUILTIN_FUNC && $token_data eq 'close') {
32 1         3 $is_in_context_of_close = 1;
33             }
34             elsif ($token_type == SEMI_COLON) {
35 18         27 $is_in_context_of_close = 0;
36             }
37             }
38              
39 4         14 return \@violations;
40             }
41              
42             1;
43