blib/lib/Perl/Critic/Policy/Subroutines/ProhibitUnderscorePrivateSubs.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 100% 6 / 6 Conditioncond 80.0% 8 / 10 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 91.6% 11 / 12 Podpod 100% 5 / 5 totaltotal 92.1% 70 / 76 CC 8 SCAR 13.9
CC
8
Cov
94%
violates
8.0
default_themes
2.0
BEGIN
1.0
CRAP 4.0
↑ Summary
1 package Perl::Critic::Policy::Subroutines::ProhibitUnderscorePrivateSubs 0.001;
2  
3 # ABSTRACT: Make a private sub lexical, rather than private by a leading underscore.
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use re '/aa';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use parent qw{Perl::Critic::Policy};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 2 Readonly::Scalar my $DESC => q{Private sub named with a leading underscore};
19 2 Readonly::Scalar my $EXPL => q{Make it a lexical sub: "my sub" or "my $name = sub"};
20  
21 # The kinds of declaration that are scoped to a block, as PPI::Statement::Sub
22 # reports them.
23 2 Readonly::Hash my %LEXICAL => map { $_ => 1 } qw{ my state };
24  
25  
26 2 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod documented
27 return (
28 {
29 2 name => 'allow',
30 description => 'Names of subs that another module requires to be package subs.',
31 default_string => q{},
32 behavior => 'string list',
33 },
34 );
35 }
36 13 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
37 0 ▶sub default_themes { return qw{ maintenance } }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
38 23 ▶sub applies_to { return 'PPI::Statement::Sub' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
39  
40  
41 23 ▶sub violates {
Subroutine violates: called CC=8 SCAR=20.8
Pod documented
42 23 my ( $self, $elem, undef ) = @_;
43  
44 23 ▶ my $type = $elem->type // q{};
Condition100%2/2
$elem->type // ""
l!l
518
MC/DC100%1/1
$elem->type // ""
$elem->type
Truth table100%2/2
A
A= $elem->type
Aresult
11
00
45 23 ▶ return if $LEXICAL{$type} || $elem->reserved;
Branch: 1 branch
BranchTrueFalseTotal
if $LEXICAL{$type} or $elem->reserved 4 19 23
Condition100%3/3
$LEXICAL{$type} or $elem->reserved
l!l&&r!l&&!r
2219
MC/DC100%2/2
$LEXICAL{$type} or $elem->reserved
$LEXICAL{$type} $elem->reserved
Truth table100%3/3
A or B
A= $LEXICAL{$type}B= $elem->reserved
ABresult
1X1
011
000
46  
47 19 ▶ my $name = $elem->name // return;
Condition50%1/2
$elem->name // (return)
l!l
190
MC/DC0%0/1
$elem->name // (return)
$elem->name
Truth table50%1/2
A
A= $elem->name
Aresult
11
00
48 19 my ($last) = $name =~ m/(\w+)\z/sx;
49 19 ▶ return unless defined $last && substr( $last, 0, 1 ) eq '_';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last and substr($last, 0, 1) eq "_" 3 16 19
Condition66%2/3
defined $last and substr($last, 0, 1) eq "_"
!ll&&!rl&&r
0316
MC/DC50%1/2
defined $last and substr($last, 0, 1) eq "_"
defined $last substr($last, 0, 1) eq "_"
Truth table66%2/3
A and B
A= defined $lastB= substr($last, 0, 1) eq "_"
ABresult
0X0
100
111
50 16 ▶ return if $self->{_allow}{$last};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_allow"}{$last} 3 13 16
51  
52 13 return $self->violation( $DESC, $EXPL, $elem );
53 }
54  
55 2 1;
56  
57 __END__
↑ Summary