lib/Perl/Critic/Policy/Subroutines/ProhibitNestedSubs.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 80.3% 53 / 66 CC 7 SCAR 15.2
CC
7
Cov
83%
violates
9.7
BEGIN
1.0
BEGIN
1.0
CRAP 4.6
« lib/Perl/Critic/UserProfile.pm ↑ Summary lib/Perl/Critic/Policy/InputOutput/RequireCheckedSyscalls.pm »
1 package Perl::Critic::Policy::Subroutines::ProhibitNestedSubs;
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 };
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{Nested named subroutine};
16 40 Readonly::Scalar my $EXPL =>
17 q{Declaring a named sub inside another named sub does not prevent the }
18 . q{inner sub from being global};
19  
20 #-----------------------------------------------------------------------------
21  
22 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
23 74 ▶sub default_severity { return $SEVERITY_HIGHEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
24 73 ▶sub default_themes { return qw(core bugs) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
25 37 ▶sub applies_to { return 'PPI::Statement::Sub' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
26  
27 #-----------------------------------------------------------------------------
28  
29 5 ▶sub violates {
Subroutine violates: called CC=7 SCAR=22.7
Pod documented
30 5 my ($self, $elem, undef) = @_;
31  
32 5 ▶ return if $elem->isa('PPI::Statement::Scheduled') || defined $elem->type;
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Statement::Scheduled") or defined $elem->type 0 5 5
Condition33%1/3
$elem->isa("PPI::Statement::Scheduled") or defined $elem->type
l!l&&r!l&&!r
005
MC/DC0%0/2
$elem->isa("PPI::Statement::Scheduled") or defined $elem->type
$elem->isa("PPI::Statement::Scheduled") defined $elem->type
Truth table33%1/3
A or B
A= $elem->isa("PPI::Statement::Scheduled")B= defined $elem->type
ABresult
1X1
011
000
33  
34 5 my $outer = $elem;
35 5 ▶ while ($outer = $outer->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outer = $outer->parent) 5 5 10
36 5 ▶ last if $outer->isa('PPI::Statement::Sub')
Branch: 1 branch
BranchTrueFalseTotal
if $outer->isa("PPI::Statement::Sub") and not $outer->isa("PPI::Statement::Scheduled") 0 5 5
Condition33%1/3
$outer->isa("PPI::Statement::Sub") and not $outer->isa("PPI::Statement::Scheduled")
!ll&&!rl&&r
500
MC/DC0%0/2
$outer->isa("PPI::Statement::Sub") and not $outer->isa("PPI::Statement::Scheduled")
$outer->isa("PPI::Statement::Sub") not $outer->isa("PPI::Statement::Scheduled")
Truth table33%1/3
A and not(B)
A= $outer->isa("PPI::Statement::Sub")B= not $outer->isa("PPI::Statement::Scheduled")
ABresult
0X0
100
111
37 && ! $outer->isa('PPI::Statement::Scheduled');
38 }
39 5 ▶ return if not $outer;
Branch: 1 branch
BranchTrueFalseTotal
unless $outer 5 0 5
40  
41 # Must be a violation...
42 0 return $self->violation($DESC, $EXPL, $elem);
43 }
44  
45 40 1;
46  
47 __END__
« lib/Perl/Critic/UserProfile.pm ↑ Summary lib/Perl/Critic/Policy/InputOutput/RequireCheckedSyscalls.pm »