Policy/References/RequireSigils.pm

filter: Statementstmt 93.6% 89 / 95 Branchbran 86.3% 38 / 44 Conditioncond 86.6% 13 / 15 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 93.7% 15 / 16 Podpod 50.0% 4 / 8 totaltotal 88.2% 165 / 187 CC 31 SCAR 20.9
CC
31
Cov
91%
violates
15.0
operatorViolates
8.3
castViolates
7.1
CRAP 8.1
« Policy/Generic/External.pm ↑ Summary Policy/CodeLayout/RequireParensWithBuiltins.pm »
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 //= ""
l!l
628
MC/DC100%1/1
$note //= ""
$note
Truth table100%2/2
A
A= $note
Aresult
11
00
47 34 ▶ $desc//=$DESC;
Condition66%2/3
$desc //= $DESC
l!l&&r!l&&!r
6280
MC/DC0%0/2
$desc //= $DESC
$desc $DESC
Truth table66%2/3
A //= B
A= $descB= $DESC
ABresult
1X1
011
000
48 0 ▶ if($note) { $note=" ($note)" }
Branch: 1 branch
BranchTrueFalseTotal
if ($note) 0 34 34
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
BranchTrueFalseTotal
if ($next->isa("PPI::Token::Symbol")) 20 16 36
56 16 ▶ if($next->isa('PPI::Structure::Block')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Structure::Block")) 12 4 16
57 12 my @children=$next->schildren();
58 0 ▶ if($#children>0) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($#children > 0) 0 12 12
59 0 ▶ if(!$children[0]->isa('PPI::Statement')) { return } # cases?
Branch: 1 branch
BranchTrueFalseTotal
unless ($children[0]->isa("PPI::Statement")) 0 12 12
60 12 @children=$children[0]->schildren();
61 12 ▶ if($#children>0) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($#children > 0) 2 10 12
62 10 ▶ if($children[0]->isa('PPI::Token::Symbol')) { return $self->invalid($elem,'',"Do not block cast single symbols") }
Branch: 1 branch
BranchTrueFalseTotal
if ($children[0]->isa("PPI::Token::Symbol")) 6 4 10
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
BranchTrueFalseTotal
if ($elem->content ne "->") 64 36 100
70 36 my $next=$elem->snext_sibling();
71 0 ▶ if(!$next) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($next) 0 36 36
72 36 ▶ if($next->isa('PPI::Token::Word') && is_method_call($next)) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Token::Word") and is_method_call($next)) 8 28 36
Condition66%2/3
$next->isa("PPI::Token::Word") and is_method_call($next)
!ll&&!rl&&r
2808
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)
ABresult
0X0
100
111
73 28 ▶ if($next->isa('PPI::Structure::Subscript')) { return $self->invalid($elem) }
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Structure::Subscript")) 12 16 28
74 16 ▶ if($next->isa('PPI::Structure::List')) { return $self->invalid($elem) }
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Structure::List")) 6 10 16
75 10 ▶ if($next->isa('PPI::Token::Cast')) { return $self->invalid($elem) }
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Token::Cast")) 10 0 10
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
BranchTrueFalseTotal
if ($self->{"_directcast"} and $elem->isa("PPI::Token::Cast")) 23 178 201
Condition100%3/3
$self->{"_directcast"} and $elem->isa("PPI::Token::Cast")
!ll&&!rl&&r
879123
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")
ABresult
0X0
100
111
82 178 ▶ if($elem->isa('PPI::Token::Operator')) { return $self->operatorViolates($elem) }
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Operator")) 92 86 178
83 86 ▶ if($elem->isa('PPI::Token::Quote')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Quote")) 65 21 86
84 65 ▶ if(!$$self{_interpolation}) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_interpolation"}) 23 42 65
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
BranchTrueFalseTotal
if (@tocheck) 101 33 134
89 101 my $node=shift(@tocheck);
90 101 ▶ if($node->isa('PPIx::QuoteLike::Token::Interpolation')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("PPIx::QuoteLike::Token::Interpolation")) 34 67 101
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') || []
l!l
826
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')
Aresult
11
00
94 8 ▶ if(my $violation=$self->operatorViolates($inner)) { return $violation }
Branch: 1 branch
BranchTrueFalseTotal
if (my $violation = $self->operatorViolates($inner)) 8 0 8
95 }
96 26 ▶ if($$self{_directcast}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_directcast"}) 13 13 26
97 13 ▶ foreach my $inner (@{$doc->find('PPI::Token::Cast')||[]}) {
Condition100%2/2
$doc->find('PPI::Token::Cast') || []
l!l
94
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')
Aresult
11
00
98 13 ▶ if(my $violation=$self->castViolates($inner)) { return $violation }
Branch: 1 branch
BranchTrueFalseTotal
if (my $violation = $self->castViolates($inner)) 1 12 13
99 } }
100 }
101 }
102 33 return;
103 }
104 21 return;
105 }
106  
107 #-----------------------------------------------------------------------------
108  
109 11 1;
110  
111 __END__
« Policy/Generic/External.pm ↑ Summary Policy/CodeLayout/RequireParensWithBuiltins.pm »