« lib/Perl/Critic/Policy/Variables/ProhibitMatchVars.pm
↑ Summary
lib/Perl/Critic/Policy/InputOutput/ProhibitJoinedReadline.pm »
| 1 | package Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms; | ||||||||||||||||||||||||||||
| 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 :data_conversion | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 40 | :classification :characters $EMPTY }; | |||||||||||||||||||||||||||
| 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::Array my @ALLOW => qw( import unimport AUTOLOAD DESTROY ); | |||||||||||||||||||||||||||
| 18 | 40 | Readonly::Hash my %ALLOW => hashify( @ALLOW ); | |||||||||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $DESC => q{Subroutine name is a homonym for builtin %s %s}; | |||||||||||||||||||||||||||
| 20 | 40 | Readonly::Scalar my $EXPL => [177]; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 91 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | return ( | ||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 91 | name => 'allow', | |||||||||||||||||||||||||||
| 28 | description => q<Subroutines matching the name regex to allow under this policy.>, | ||||||||||||||||||||||||||||
| 29 | default_string => $EMPTY, | ||||||||||||||||||||||||||||
| 30 | behavior => 'string list', | ||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 77 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 91 | ▶ | sub default_themes { return qw( core bugs pbp certrule ) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 33 | ▶ | sub applies_to { return 'PPI::Statement::Sub' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=7 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 5 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 42 | 5 | ▶ | return if $elem->isa('PPI::Statement::Scheduled'); #e.g. BEGIN, INIT, END | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 5 | ▶ | return if exists $ALLOW{ $elem->name() } and not defined $elem->type(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $ALLOW{$elem->name} and not defined $elem->type
MC/DC0%0/2
exists $ALLOW{$elem->name} and not defined $elem->type
exists $ALLOW{$elem->name}
not defined $elem->type
Truth table33%1/3
A and not(B)
A= exists $ALLOW{$elem->name}B= not defined $elem->type
| |||||||||||||||||||||||||||||
| 44 | 5 | ▶ | return if exists $self->{_allow}{ $elem->name() }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 5 | my $homonym_type = $EMPTY; | |||||||||||||||||||||||||||
| 47 | 5 | ▶ | if ( is_perl_builtin( $elem ) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 48 | 3 | $homonym_type = 'function'; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | elsif ( is_perl_bareword( $elem ) ) { | ||||||||||||||||||||||||||||
| 51 | 0 | $homonym_type = 'keyword'; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||
| 54 | 2 | return; #ok! | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 3 | my $desc = sprintf $DESC, $homonym_type, $elem->name(); | |||||||||||||||||||||||||||
| 58 | 3 | return $self->violation($desc, $EXPL, $elem); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 40 | 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||