| 1 | package Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr; | ||||||||||||||||||||
| 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 | 40 | ▶ | use version 0.77 (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities :classification :language }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $DESC => q{Lvalue form of "substr" used}; | |||||||||||||||||||
| 17 | 40 | Readonly::Scalar my $EXPL => [ 165 ]; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $ASSIGNMENT_PRECEDENCE => precedence_of( q{=} ); | |||||||||||||||||||
| 20 | 40 | Readonly::Scalar my $MINIMUM_PERL_VERSION => version->new( 5.005 ); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 25 | 74 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 26 | 85 | ▶ | sub default_themes { return qw( core maintenance pbp ) } | ||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 27 | 31 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 31 | ▶ | sub prepare_to_scan_document { | ||||||||||||||||||
|
Subroutine
prepare_to_scan_document: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 32 | 31 | my ( undef, $document ) = @_; | |||||||||||||||||||
| 33 | # perl5005delta says that is when the fourth argument to substr() | ||||||||||||||||||||
| 34 | # was introduced, so ... (RT #59112) | ||||||||||||||||||||
| 35 | 31 | my $version = $document->highest_explicit_perl_version(); | |||||||||||||||||||
| 36 | 31 | ▶ | return ! $version || $version >= $MINIMUM_PERL_VERSION; | ||||||||||||||||||
|
Condition33%1/3
!$version || $version >= $MINIMUM_PERL_VERSION
MC/DC0%0/2
!$version || $version >= $MINIMUM_PERL_VERSION
!$version
$version >= $MINIMUM_PERL_VERSION
Truth table33%1/3
not(A) || B
A= !$versionB= $version >= $MINIMUM_PERL_VERSION
| |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 332 | ▶ | sub violates { | ||||||||||||||||||
|
Subroutine
violates: called CC=7 SCAR=36.5
Pod
documented
| |||||||||||||||||||||
| 42 | 332 | my ($self, $elem, undef) = @_; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 332 | ▶ | return if $elem->content() ne 'substr'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | ▶ | return if ! is_function_call($elem); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | my $sib = $elem; | |||||||||||||||||||
| 48 | 0 | ▶ | while ($sib = $sib->snext_sibling()) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | ▶ | if ( $sib->isa( 'PPI::Token::Operator' ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | my $rslt = $ASSIGNMENT_PRECEDENCE <=> precedence_of( | |||||||||||||||||||
| 51 | $sib->content() ); | ||||||||||||||||||||
| 52 | 0 | ▶ | return if $rslt < 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 0 | ▶ | return $self->violation( $DESC, $EXPL, $sib ) if $rslt == 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | 0 | return; #ok! | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 40 | 1; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||