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

filter: Statementstmt 90.0% 45 / 50 Branchbran 42.8% 6 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 83.3% 5 / 6 totaltotal 82.9% 68 / 82 CC 10 SCAR 14.8
CC
10
Cov
80%
violates
9.2
initialize_if_enabled
5.5
BEGIN
1.0
CRAP 4.4
« lib/Perl/Critic/Policy/Subroutines/ProhibitNestedSubs.pm ↑ Summary lib/Perl/Critic/Policy/CodeLayout/ProhibitHardTabs.pm »
1 package Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls;
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{ :booleans :characters :severities :classification
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 hashify is_perl_bareword };
10  
11 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 40 our $VERSION = '1.156';
14  
15 #-----------------------------------------------------------------------------
16  
17 40 Readonly::Scalar my $DESC => q{Return value of flagged function ignored};
18 40 Readonly::Scalar my $EXPL => [208, 278];
19  
20 40 Readonly::Array my @DEFAULT_FUNCTIONS => qw(
21 open close print say
22 );
23 # I created this list by searching for "return" in perlfunc
24 40 Readonly::Array my @BUILTIN_FUNCTIONS => qw(
25 accept bind binmode chdir chmod chown close closedir connect
26 dbmclose dbmopen exec fcntl flock fork ioctl kill link listen
27 mkdir msgctl msgget msgrcv msgsnd open opendir pipe print read
28 readdir readline readlink readpipe recv rename rmdir say seek seekdir
29 semctl semget semop send setpgrp setpriority setsockopt shmctl
30 shmget shmread shutdown sleep socket socketpair symlink syscall
31 sysopen sysread sysseek system syswrite tell telldir truncate
32 umask unlink utime wait waitpid
33 );
34  
35 #-----------------------------------------------------------------------------
36  
37 93 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
38 return (
39 {
40 93 name => 'functions',
41 description =>
42 'The set of functions to require checking the return value of.',
43 default_string => join( $SPACE, @DEFAULT_FUNCTIONS ),
44 behavior => 'string list',
45 },
46 {
47 name => 'exclude_functions',
48 description =>
49 'The set of functions to not require checking the return value of.',
50 default_string => $EMPTY,
51 behavior => 'string list',
52 },
53 {
54 name => 'autodie_modules',
55 description => 'Modules which export autodie.',
56 default_string => 'autodie',
57 behavior => 'string list',
58 },
59 );
60 }
61  
62 77 ▶sub default_severity { return $SEVERITY_LOWEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
63 73 ▶sub default_themes { return qw( core maintenance certrule ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
64 31 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
65  
66 #-----------------------------------------------------------------------------
67  
68 50 ▶sub initialize_if_enabled {
Subroutine initialize_if_enabled: called CC=5 SCAR=17.0
Pod documented
69 50 my ($self, undef) = @_;
70  
71 50 my @specified_functions = keys %{ $self->{_functions} };
72 50 my @resulting_functions;
73  
74 50 foreach my $function (@specified_functions) {
75 200 ▶ if ( $function eq ':defaults' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($function eq ':defaults') { } 0 200 200
elsif ($function eq ':builtins') { } 0 200 200
76 0 push @resulting_functions, @DEFAULT_FUNCTIONS;
77 }
78 elsif ( $function eq ':builtins' ) {
79 0 push @resulting_functions, @BUILTIN_FUNCTIONS;
80 }
81 else {
82 200 push @resulting_functions, $function;
83 }
84 }
85  
86 50 my %functions = hashify(@resulting_functions);
87  
88 50 foreach my $function ( keys %{ $self->{_exclude_functions} } ) {
89 0 delete $functions{$function};
90 }
91  
92 50 $self->{_functions} = \%functions;
93  
94 50 return $TRUE;
95 }
96  
97 #-----------------------------------------------------------------------------
98  
99 332 ▶sub violates {
Subroutine violates: called CC=6 SCAR=22.1
Pod documented
100 332 my ( $self, $elem, undef ) = @_;
101  
102 332 ▶ if ( $self->{_functions}->{':all'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_functions'}{':all'}) { } 0 332 332
elsif (not $self->{'_functions'}{$elem->content}) { } 329 3 332
103 0 ▶ return if is_perl_bareword($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_perl_bareword($elem) 0 0 0
104 0 ▶ return if $self->{_exclude_functions}->{ $elem->content() };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_exclude_functions"}{$elem->content} 0 0 0
105 }
106 elsif ( not $self->{_functions}->{ $elem->content() } ) {
107 329 return;
108 }
109  
110 3 ▶ return if ! is_unchecked_call( $elem, [ keys %{ $self->{_autodie_modules} } ] );
Branch: 1 branch
BranchTrueFalseTotal
unless is_unchecked_call($elem, [keys %{$$self{"_autodie_modules"};}]) 0 3 3
111  
112 3 return $self->violation( "$DESC - " . $elem->content(), $EXPL, $elem );
113 }
114  
115  
116 40 1;
117  
118 __END__
« lib/Perl/Critic/Policy/Subroutines/ProhibitNestedSubs.pm ↑ Summary lib/Perl/Critic/Policy/CodeLayout/ProhibitHardTabs.pm »