| 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 // ""
MC/DC100%1/1
$elem->type // ""
$elem->type
Truth table100%2/2
A
A= $elem->type
| |||||||||||||||||||||||||||||
| 45 | 23 | ▶ | return if $LEXICAL{$type} || $elem->reserved; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$LEXICAL{$type} or $elem->reserved
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
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 19 | ▶ | my $name = $elem->name // return; | ||||||||||||||||||||||||||
|
Condition50%1/2
$elem->name // (return)
MC/DC0%0/1
$elem->name // (return)
$elem->name
Truth table50%1/2
A
A= $elem->name
| |||||||||||||||||||||||||||||
| 48 | 19 | my ($last) = $name =~ m/(\w+)\z/sx; | |||||||||||||||||||||||||||
| 49 | 19 | ▶ | return unless defined $last && substr( $last, 0, 1 ) eq '_'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $last and substr($last, 0, 1) eq "_"
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 "_"
| |||||||||||||||||||||||||||||
| 50 | 16 | ▶ | return if $self->{_allow}{$last}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 13 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||