« Policy/ValuesAndExpressions/RestrictLongStrings.pm
↑ Summary
Policy/Modules/RequirePerlVersion.pm »
| 1 | ############################################################################## | ||||||||||||||||||||||||||||
| 2 | # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm $ | ||||||||||||||||||||||||||||
| 3 | # $Date: 2008-07-07 09:09:13 -0700 (Mon, 07 Jul 2008) $ | ||||||||||||||||||||||||||||
| 4 | # $Author: clonezone $ | ||||||||||||||||||||||||||||
| 5 | # $Revision: 2537 $ | ||||||||||||||||||||||||||||
| 6 | ############################################################################## | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | package Perl::Critic::Policy::ValuesAndExpressions::RequireConstantOnLeftSideOfEquality; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use 5.006001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use Perl::Critic::Utils qw{ :severities }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 7 | our $VERSION = '1.003'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | Readonly::Scalar my $DESC => q{Constant value on right side of equality}; | |||||||||||||||||||||||||||
| 27 | 7 | Readonly::Scalar my $EXPL => | |||||||||||||||||||||||||||
| 28 | q{Putting the constant on the left exposes typos}; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 7 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub default_themes { return qw(more) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 3 | ▶ | sub applies_to { return qw(PPI::Token::Operator) } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 18 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 18 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 41 | 18 | ▶ | return if !( q<==> eq $elem || q<eq> eq $elem ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
"==" eq $elem or "eq" eq $elem
MC/DC100%2/2
"==" eq $elem or "eq" eq $elem
"==" eq $elem
"eq" eq $elem
Truth table100%3/3
A or B
A= "==" eq $elemB= "eq" eq $elem
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 15 | ▶ | my $right_sib = $elem->snext_sibling() || return; | ||||||||||||||||||||||||||
|
Condition50%1/2
$elem->snext_sibling || (return)
MC/DC0%0/1
$elem->snext_sibling || (return)
$elem->snext_sibling
Truth table50%1/2
A
A= $elem->snext_sibling
| |||||||||||||||||||||||||||||
| 44 | 15 | ▶ | my $left_sib = $elem->sprevious_sibling() || return; | ||||||||||||||||||||||||||
|
Condition50%1/2
$elem->sprevious_sibling || (return)
MC/DC0%0/1
$elem->sprevious_sibling || (return)
$elem->sprevious_sibling
Truth table50%1/2
A
A= $elem->sprevious_sibling
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 15 | ▶ | if ( !_is_constant_like($left_sib) && _is_constant_like($right_sib) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not _is_constant_like($left_sib) and _is_constant_like($right_sib)
MC/DC100%2/2
not _is_constant_like($left_sib) and _is_constant_like($right_sib)
not _is_constant_like($left_sib)
_is_constant_like($right_sib)
Truth table100%3/3
not(A) and B
A= not _is_constant_like($left_sib)B= _is_constant_like($right_sib)
| |||||||||||||||||||||||||||||
| 47 | 6 | return $self->violation( $DESC, $EXPL, $right_sib ); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 9 | return; # ok! | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 24 | ▶ | sub _is_constant_like { | ||||||||||||||||||||||||||
|
Subroutine
_is_constant_like: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 56 | 24 | my $elem = shift; | |||||||||||||||||||||||||||
| 57 | 24 | ▶ | return 1 if $elem->isa('PPI::Token::Number'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 18 | ▶ | return 1 if $elem->isa('PPI::Token::Quote'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 12 | return 0; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 7 | 1; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||