lib/Perl/Critic/Policy/InputOutput/ProhibitBarewordFileHandles.pm

filter: Statementstmt 69.0% 29 / 42 Branchbran 6.2% 1 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 56.9% 45 / 79 CC 10 SCAR 37.7
CC
10
Cov
49%
violates
85.8
BEGIN
1.0
BEGIN
1.0
CRAP 43.4
« lib/Perl/Critic/Policy/ControlStructures/ProhibitUnreachableCode.pm ↑ Summary lib/Perl/Critic/Policy/BuiltinFunctions/RequireSimpleSortBlock.pm »
1 package Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :severities :classification :ppi hashify };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.156';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{Bareword file handle opened};
16 40 Readonly::Scalar my $EXPL => [ 202, 204 ];
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 74 ▶sub default_severity { return $SEVERITY_HIGHEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 91 ▶sub default_themes { return qw( core pbp bugs certrec ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 37 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24  
25 #-----------------------------------------------------------------------------
26  
27 40 Readonly::Scalar my $ARRAY_REF => ref [];
28 40 Readonly::Hash my %OPEN_FUNCS => hashify( qw( open sysopen ) );
29  
30 361 ▶sub violates {
Subroutine violates: called CC=10 SCAR=44.5
Pod documented
31 361 my ($self, $elem, undef) = @_;
32  
33 361 ▶ return if ! $OPEN_FUNCS{$elem->content()};
Branch: 1 branch
BranchTrueFalseTotal
unless $OPEN_FUNCS{$elem->content} 361 0 361
34 0 ▶ return if ! is_function_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
unless is_function_call($elem) 0 0 0
35  
36 0 my $first_arg = ( parse_arg_list($elem) )[0];
37 0 ▶ return if !$first_arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $first_arg 0 0 0
38 0 my $first_token;
39 # PPI can mis-parse something like open( CHECK, ... ) as a scheduled
40 # block. So ...
41 0 ▶ if ( 'PPI::Statement::Scheduled' eq ref $first_arg ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('PPI::Statement::Scheduled' eq ref $first_arg) { } 0 0 0
elsif ($ARRAY_REF eq ref $first_arg) { } 0 0 0
42 # If PPI PR #247 is accepted, the following should be unnecessary.
43 # We get here because when parse_arg_list() gets confused it
44 # just returns the statement object.
45 0 $first_token = $first_arg->schild( 0 );
46 } elsif ( $ARRAY_REF eq ref $first_arg ) {
47 # This is the normal path through the code.
48 0 $first_token = $first_arg->[0];
49 } else {
50 # This is purely defensive.
51 0 return;
52 }
53 0 ▶ return if !$first_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $first_token 0 0 0
54  
55 0 ▶ if ( $first_token->isa('PPI::Token::Word') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_token->isa("PPI::Token::Word")) 0 0 0
56 0 ▶ if ( ($first_token ne 'my') && ($first_token !~ m/^STD(?:IN|OUT|ERR)$/xms ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_token ne "my" and not $first_token =~ /^STD(?:IN|OUT|ERR)$/msx) 0 0 0
Condition0%0/3
$first_token ne "my" and not $first_token =~ /^STD(?:IN|OUT|ERR)$/msx
!ll&&!rl&&r
000
MC/DC0%0/2
$first_token ne "my" and not $first_token =~ /^STD(?:IN|OUT|ERR)$/msx
$first_token ne "my" not $first_token =~ /^STD(?:IN|OUT|ERR)$/msx
Truth table0%0/3
A and not(B)
A= $first_token ne "my"B= not $first_token =~ /^STD(?:IN|OUT|ERR)$/msx
ABresult
0X0
100
111
57 0 return $self->violation( $DESC, $EXPL, $elem );
58 }
59 }
60 0 return; #ok!
61 }
62  
63 40 1;
64  
65 __END__
« lib/Perl/Critic/Policy/ControlStructures/ProhibitUnreachableCode.pm ↑ Summary lib/Perl/Critic/Policy/BuiltinFunctions/RequireSimpleSortBlock.pm »