| 1 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package Perl::Critic::Policy::Tics::ProhibitManyArrows 0.010; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: (this => is => not => good) | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 7 | #pod | ||||||||||||||||||||||||||||
| 8 | #pod You are not clever if you do this: | ||||||||||||||||||||||||||||
| 9 | #pod | ||||||||||||||||||||||||||||
| 10 | #pod my %hash = (key1=>value1=>key2=>value2=>key3=>'value3'); | ||||||||||||||||||||||||||||
| 11 | #pod | ||||||||||||||||||||||||||||
| 12 | #pod You are even more not clever if you do this: | ||||||||||||||||||||||||||||
| 13 | #pod | ||||||||||||||||||||||||||||
| 14 | #pod my %hash = (key1=>value1=>key2=>value2=>key3=>value3=>); | ||||||||||||||||||||||||||||
| 15 | #pod | ||||||||||||||||||||||||||||
| 16 | #pod =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 17 | #pod | ||||||||||||||||||||||||||||
| 18 | #pod There is one parameter for this policy, F<max_allowed>, which specifies the | ||||||||||||||||||||||||||||
| 19 | #pod maximum number of fat arrows that may appear as item separators. The default | ||||||||||||||||||||||||||||
| 20 | #pod is two. If you really hate the fat arrow, and never want to see it, you can | ||||||||||||||||||||||||||||
| 21 | #pod set F<max_allowed> to zero and make any occurance of C<< => >> illegal. | ||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||
| 23 | #pod Here are some examples of code that would fail with various F<max_allowed> | ||||||||||||||||||||||||||||
| 24 | #pod values: | ||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||
| 26 | #pod max_allowed failing code | ||||||||||||||||||||||||||||
| 27 | #pod 0 (foo => bar) | ||||||||||||||||||||||||||||
| 28 | #pod 1 (foo => bar => baz) | ||||||||||||||||||||||||||||
| 29 | #pod 2 (foo => bar => baz => quux) | ||||||||||||||||||||||||||||
| 30 | #pod | ||||||||||||||||||||||||||||
| 31 | #pod =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | ▶ | use Perl::Critic::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 5 | ▶ | use parent qw(Perl::Critic::Policy); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 5 | my $DESCRIPTION = q{Too many fat-arrow-separated values in a row}; | |||||||||||||||||||||||||||
| 37 | 5 | my $EXPLANATION = q{Fat arrows should separate pairs, not produce long chains | |||||||||||||||||||||||||||
| 38 | of values}; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 6 | ▶ | sub default_severity { $SEVERITY_MEDIUM } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub default_themes { qw(tics) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 11 | ▶ | sub applies_to { 'PPI::Token::Operator' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 11 | ▶ | sub supported_parameters { qw(max_allowed) } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 11 | my ($class, %arg) = @_; | |||||||||||||||||||||||||||
| 48 | 11 | my $self = $class->SUPER::new(%arg); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 11 | ▶ | $arg{max_allowed} = 2 unless defined $arg{max_allowed}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Carp::croak "max_allowed for Tics::ProhibitManyArrows must be a positive int" | ||||||||||||||||||||||||||||
| 53 | 11 | ▶ | unless $arg{max_allowed} =~ /\A\d+\z/ and $arg{max_allowed} >= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$arg{"max_allowed"} =~ /\A\d+\z/ and $arg{"max_allowed"} >= 0
MC/DC0%0/2
$arg{"max_allowed"} =~ /\A\d+\z/ and $arg{"max_allowed"} >= 0
$arg{"max_allowed"} =~ /\A\d+\z/
$arg{"max_allowed"} >= 0
Truth table33%1/3
A and B
A= $arg{"max_allowed"} =~ /\A\d+\z/B= $arg{"max_allowed"} >= 0
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 11 | $self->{max_allowed} = $arg{max_allowed}; | |||||||||||||||||||||||||||
| 56 | 11 | bless $self => $class; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 12 | ▶ | sub _max_allowed { $_[0]->{max_allowed} } | ||||||||||||||||||||||||||
|
Subroutine
_max_allowed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 46 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 46 | my ($self, $elem, $doc) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 46 | ▶ | return unless $elem eq '=>'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 24 | ▶ | return if eval { $elem->sprevious_sibling->sprevious_sibling } eq '=>'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 12 | my $in_a_row = 1; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 12 | my $start = $elem; | |||||||||||||||||||||||||||
| 70 | 12 | ▶ | while (my $next = eval { $start->snext_sibling->snext_sibling }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 18 | ▶ | last unless $next eq '=>'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 12 | $in_a_row++; | |||||||||||||||||||||||||||
| 73 | 12 | $start = $next; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 12 | ▶ | return unless $in_a_row > $self->_max_allowed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Must be a violation... | ||||||||||||||||||||||||||||
| 79 | 6 | return $self->violation($DESCRIPTION, $EXPLANATION, $start); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 5 | 1; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||