blib/lib/Perl/Critic/Policy/ErrorHandling/RequireReturnFromEval.pm

filter: Statementstmt 85.7% 36 / 42 Branchbran 68.7% 11 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 4 / 4 totaltotal 82.8% 58 / 70 CC 10 SCAR 19.7
CC
10
Cov
81%
violates
11.5
default_themes
2.0
BEGIN
1.0
CRAP 7.2
↑ Summary
1 package Perl::Critic::Policy::ErrorHandling::RequireReturnFromEval;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Perl::Critic::Utils qw{ :severities :ppi };
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '1.00';
10  
11 3 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
12 0 ▶sub default_themes { return qw(style) }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
13 7 ▶sub applies_to { return 'PPI::Structure::Block' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
14  
15 6 ▶sub violates {
Subroutine violates: called CC=10 SCAR=24.4
Pod documented
16 6 my ($self, $elem, undef) = @_;
17  
18 6 my $prev = $elem->sprevious_sibling();
19 6 ▶ if (!$prev) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev) 0 6 6
20 0 return;
21 }
22 6 ▶ if (!$prev->isa('PPI::Token::Word')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev->isa("PPI::Token::Word")) 0 6 6
23 0 return;
24 }
25 6 ▶ if ($prev->content() ne 'eval') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->content ne "eval") 0 6 6
26 0 return;
27 }
28  
29 6 my @children = $elem->children();
30 6 ▶ if (!@children) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@children) 0 6 6
31 0 return;
32 }
33  
34 6 my @statements = grep { $_->isa('PPI::Statement') } @children;
35 6 ▶ if (!@statements) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@statements) 1 5 6
36 1 return;
37 }
38  
39 5 foreach my $stmt (@statements) {
40 7 my @stmt_children = $stmt->children();
41 7 ▶ if (!@stmt_children) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stmt_children) 0 7 7
42 0 next;
43 }
44  
45 7 my $first = $stmt_children[0];
46 7 ▶ if (!$first->isa('PPI::Token::Word')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first->isa("PPI::Token::Word")) 1 6 7
47 1 next;
48 }
49 6 ▶ if ($first->content() eq 'return') {
Branch: 1 branch
BranchTrueFalseTotal
if ($first->content eq "return") 2 4 6
50 2 return;
51 }
52 }
53  
54 3 return $self->violation('Eval block should use explicit return', '', $elem);
55 }
56  
57 2 1;
58  
59 __END__
↑ Summary