lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitLvalueSubstr.pm

filter: Statementstmt 81.4% 35 / 43 Branchbran 8.3% 1 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 83.3% 5 / 6 totaltotal 69.6% 55 / 79 CC 8 SCAR 26.6
CC
8
Cov
64%
violates
38.6
prepare_to_scan_document
2.1
BEGIN
1.0
CRAP 14.3
« lib/Perl/Critic/Utils.pm ↑ Summary lib/Perl/Critic/Policy/Documentation/RequirePodSections.pm »
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
l!l&&r!l&&!r
3100
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $elem->content ne "substr" 332 0 332
45 0 ▶ return if ! is_function_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
unless is_function_call($elem) 0 0 0
46  
47 0 my $sib = $elem;
48 0 ▶ while ($sib = $sib->snext_sibling()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sib = $sib->snext_sibling) 0 0 0
49 0 ▶ if ( $sib->isa( 'PPI::Token::Operator' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sib->isa("PPI::Token::Operator")) 0 0 0
50 0 my $rslt = $ASSIGNMENT_PRECEDENCE <=> precedence_of(
51 $sib->content() );
52 0 ▶ return if $rslt < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rslt < 0 0 0 0
53 0 ▶ return $self->violation( $DESC, $EXPL, $sib ) if $rslt == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rslt == 0 0 0 0
54 }
55 }
56 0 return; #ok!
57 }
58  
59 40 1;
60  
61 #-----------------------------------------------------------------------------
62  
63 __END__
« lib/Perl/Critic/Utils.pm ↑ Summary lib/Perl/Critic/Policy/Documentation/RequirePodSections.pm »