| 1 | package Perl::Critic::Policy::References::RequireSigils; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Perl::Critic::Utils qw/:severities :classification/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use PPI::Document; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use PPIx::QuoteLike; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 11 | our $VERSION = '0.1.4'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 11 | Readonly::Scalar my $DESC => q{Only use arrows for methods}; | |||||||||||||||||||||||||||
| 17 | 11 | Readonly::Scalar my $EXPL => undef; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | return ( | ||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||
| 24 | 4 | name => 'directcast', | |||||||||||||||||||||||||||
| 25 | description => 'Prohibit block-style casting of direct references (not yet available).', | ||||||||||||||||||||||||||||
| 26 | default_string => '1', | ||||||||||||||||||||||||||||
| 27 | behavior => 'boolean', | ||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | name => 'interpolation', | ||||||||||||||||||||||||||||
| 31 | description => 'Check interpolated strings for arrow-like patterns.', | ||||||||||||||||||||||||||||
| 32 | default_string => '1', | ||||||||||||||||||||||||||||
| 33 | behavior => 'boolean', | ||||||||||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 129 | ▶ | sub applies_to { return qw/PPI::Token::Cast PPI::Token::Operator PPI::Token::Quote::Double/ } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 34 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub default_themes { return qw/cosmetic/ } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 34 | ▶ | sub invalid { | ||||||||||||||||||||||||||
|
Subroutine
invalid: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 34 | my ($self,$elem,$note,$desc)=@_; | |||||||||||||||||||||||||||
| 46 | 34 | ▶ | $note//=''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$note //= ""
MC/DC100%1/1
$note //= ""
$note
Truth table100%2/2
A
A= $note
| |||||||||||||||||||||||||||||
| 47 | 34 | ▶ | $desc//=$DESC; | ||||||||||||||||||||||||||
|
Condition66%2/3
$desc //= $DESC
MC/DC0%0/2
$desc //= $DESC
$desc
$DESC
Truth table66%2/3
A //= B
A= $descB= $DESC
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if($note) { $note=" ($note)" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 34 | return $self->violation(sprintf("%s%s",$desc,$note),$EXPL,$elem); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 36 | ▶ | sub castViolates { | ||||||||||||||||||||||||||
|
Subroutine
castViolates: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 36 | my ($self,$elem)=@_; | |||||||||||||||||||||||||||
| 54 | 36 | my $next=$elem->snext_sibling(); | |||||||||||||||||||||||||||
| 55 | 36 | ▶ | if($next->isa('PPI::Token::Symbol')) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 16 | ▶ | if($next->isa('PPI::Structure::Block')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 12 | my @children=$next->schildren(); | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | if($#children>0) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if(!$children[0]->isa('PPI::Statement')) { return } # cases? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 12 | @children=$children[0]->schildren(); | |||||||||||||||||||||||||||
| 61 | 12 | ▶ | if($#children>0) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 10 | ▶ | if($children[0]->isa('PPI::Token::Symbol')) { return $self->invalid($elem,'',"Do not block cast single symbols") } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 8 | return; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 100 | ▶ | sub operatorViolates { | ||||||||||||||||||||||||||
|
Subroutine
operatorViolates: called CC=8 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 100 | my ($self,$elem)=@_; | |||||||||||||||||||||||||||
| 69 | 100 | ▶ | if($elem->content() ne '->') { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 36 | my $next=$elem->snext_sibling(); | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | if(!$next) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 36 | ▶ | if($next->isa('PPI::Token::Word') && is_method_call($next)) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$next->isa("PPI::Token::Word") and is_method_call($next)
MC/DC50%1/2
$next->isa("PPI::Token::Word") and is_method_call($next)
$next->isa("PPI::Token::Word")
is_method_call($next)
Truth table66%2/3
A and B
A= $next->isa("PPI::Token::Word")B= is_method_call($next)
| |||||||||||||||||||||||||||||
| 73 | 28 | ▶ | if($next->isa('PPI::Structure::Subscript')) { return $self->invalid($elem) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 16 | ▶ | if($next->isa('PPI::Structure::List')) { return $self->invalid($elem) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 10 | ▶ | if($next->isa('PPI::Token::Cast')) { return $self->invalid($elem) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | return; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 201 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 201 | my ($self,$elem,undef)=@_; | |||||||||||||||||||||||||||
| 81 | 201 | ▶ | if($$self{_directcast} && $elem->isa('PPI::Token::Cast')) { return $self->castViolates($elem) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"_directcast"} and $elem->isa("PPI::Token::Cast")
MC/DC100%2/2
$self->{"_directcast"} and $elem->isa("PPI::Token::Cast")
$self->{"_directcast"}
$elem->isa("PPI::Token::Cast")
Truth table100%3/3
A and B
A= $self->{"_directcast"}B= $elem->isa("PPI::Token::Cast")
| |||||||||||||||||||||||||||||
| 82 | 178 | ▶ | if($elem->isa('PPI::Token::Operator')) { return $self->operatorViolates($elem) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 86 | ▶ | if($elem->isa('PPI::Token::Quote')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 65 | ▶ | if(!$$self{_interpolation}) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 42 | my $content=$elem->content(); | |||||||||||||||||||||||||||
| 86 | 42 | my $string=PPIx::QuoteLike->new($content); | |||||||||||||||||||||||||||
| 87 | 42 | my @tocheck=$string->children(); | |||||||||||||||||||||||||||
| 88 | 42 | ▶ | while(@tocheck) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 101 | my $node=shift(@tocheck); | |||||||||||||||||||||||||||
| 90 | 101 | ▶ | if($node->isa('PPIx::QuoteLike::Token::Interpolation')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 34 | $content=$node->content(); | |||||||||||||||||||||||||||
| 92 | 34 | my $doc=PPI::Document->new(\$content); | |||||||||||||||||||||||||||
| 93 | 34 | ▶ | foreach my $inner (@{$doc->find('PPI::Token::Operator')||[]}) { | ||||||||||||||||||||||||||
|
Condition100%2/2
$doc->find('PPI::Token::Operator') || []
MC/DC100%1/1
$doc->find('PPI::Token::Operator') || []
$doc->find('PPI::Token::Operator')
Truth table100%2/2
A
A= $doc->find('PPI::Token::Operator')
| |||||||||||||||||||||||||||||
| 94 | 8 | ▶ | if(my $violation=$self->operatorViolates($inner)) { return $violation } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 26 | ▶ | if($$self{_directcast}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 13 | ▶ | foreach my $inner (@{$doc->find('PPI::Token::Cast')||[]}) { | ||||||||||||||||||||||||||
|
Condition100%2/2
$doc->find('PPI::Token::Cast') || []
MC/DC100%1/1
$doc->find('PPI::Token::Cast') || []
$doc->find('PPI::Token::Cast')
Truth table100%2/2
A
A= $doc->find('PPI::Token::Cast')
| |||||||||||||||||||||||||||||
| 98 | 13 | ▶ | if(my $violation=$self->castViolates($inner)) { return $violation } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | } } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 33 | return; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 21 | return; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 11 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||