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   68055 use strict;
  133         192  
  133         3030  
3 133     133   417 use warnings;
  133         165  
  133         2408  
4 133     133   849 use Perl::Lint::Constants::Type;
  133         149  
  133         60419  
5 133     133   601 use parent "Perl::Lint::Policy";
  133         177  
  133         634  
6              
7             use constant {
8 133         23435 DESC => 'Use "<>" or "" or a prompting module instead of ""',
9             EXPL => [216, 220, 221],
10 133     133   7050 };
  133         178  
11              
12             sub evaluate {
13 4     4 0 6 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 4         3 my @violations;
16 4         5 my $is_in_context_of_close = 0;
17 4         14 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 141         82 my $token_type = $token->{type};
19 141         97 my $token_data = $token->{data};
20              
21 141 100 100     368 if ($token_type == TYPE_STDIN) {
    100          
    100          
22 13 100       16 next if $is_in_context_of_close;
23             push @violations, {
24             filename => $file,
25             line => $token->{line},
26 12         43 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         31 $is_in_context_of_close = 0;
36             }
37             }
38              
39 4         13 return \@violations;
40             }
41              
42             1;
43