| 1 | package Perl::Critic::Policy::Subroutines::ProhibitLvalueMethods; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | our $VERSION = '0.001000'; | |||||||||
| 6 | 1 | $VERSION =~ tr/_//d; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use parent qw(Perl::Critic::Policy); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Perl::Critic::Utils qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | is_method_call | ||||||||||
| 12 | precedence_of | ||||||||||
| 13 | 1 | ); | |||||||||
| 14 | |||||||||||
| 15 | 6 | ▶ | sub supported_parameters { } | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 16 | |||||||||||
| 17 | 2 | ▶ | sub default_severity { return $Perl::Critic::Utils::SEVERITY_MEDIUM } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 18 | 0 | ▶ | sub default_themes { return qw( ) } | ||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | |||||||||||
| 20 | 6 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | |||||||||||
| 22 | # match by precedence to catch other assignment ops, like ||= | ||||||||||
| 23 | 1 | ▶ | use constant ASSIGNMENT_PRECEDENCE => precedence_of('='); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 1 | my $DESC = 'Assignment to method "%s" used'; | |||||||||
| 26 | 1 | my $EXPL = <<'END_EXPL'; | |||||||||
| 27 | Use of methods as lvalues is uncommon and may indicate an accidental attempt | ||||||||||
| 28 | at assigning to a field or attribute, which is not commonly supported. | ||||||||||
| 29 | END_EXPL | ||||||||||
| 30 | |||||||||||
| 31 | 9 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 32 | 9 | my ($self, $elem, undef) = @_; | |||||||||
| 33 | |||||||||||
| 34 | 9 | ▶ | return if ! is_method_call($elem); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | |||||||||||
| 36 | 6 | my $sib = $elem; | |||||||||
| 37 | 6 | ▶ | while ($sib = $sib->snext_sibling) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 9 | ▶ | if ( $sib->isa( 'PPI::Token::Operator' ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | return | ||||||||||
| 40 | 3 | ▶ | if precedence_of( $sib->content ) != ASSIGNMENT_PRECEDENCE; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 2 | return $self->violation( sprintf($DESC, $elem->content), $EXPL, $sib ); | |||||||||
| 42 | } | ||||||||||
| 43 | } | ||||||||||
| 44 | 3 | return; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | 1; | |||||||||
| 48 | __END__ | ||||||||||