lib/Perl/Critic/Policy/Subroutines/ProhibitAmpersandSigils.pm

filter: Statementstmt 76.1% 32 / 42 Branchbran 22.2% 4 / 18 Conditioncond 3.7% 1 / 27 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 44.4% 52 / 117 CC 19 SCAR 50.1
CC
19
Cov
43%
violates
227.9
BEGIN
1.0
BEGIN
1.0
CRAP 149.7
« lib/Perl/Critic/Policy/ValuesAndExpressions/RequireConstantVersion.pm ↑ Summary lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusedCapture.pm »
1 package Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :severities hashify };
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Scalar my $DESC => q{Subroutine called with "&" sigil};
17 40 Readonly::Scalar my $EXPL => [ 175 ];
18  
19 40 Readonly::Hash my %EXEMPTIONS =>
20 hashify( qw< defined exists goto sort > );
21  
22 40 Readonly::Hash my %IS_COMMA =>
23 hashify( q{,}, q{=>} );
24  
25 #-----------------------------------------------------------------------------
26  
27 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
28 74 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
29 85 ▶sub default_themes { return qw(core pbp maintenance) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
30 31 ▶sub applies_to { return 'PPI::Token::Symbol' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
31  
32 #-----------------------------------------------------------------------------
33  
34 173 ▶sub violates {
Subroutine violates: called CC=19 SCAR=54.3
Pod documented
35 173 my ( $self, $elem, undef ) = @_;
36  
37 173 my $previous = $elem->sprevious_sibling();
38 173 ▶ if ( $previous ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($previous) 131 42 173
39 #Sigil is allowed if taking a reference, e.g. "\&my_sub"
40 131 ▶ return if $previous->isa('PPI::Token::Cast') && $previous eq q{\\};
Branch: 1 branch
BranchTrueFalseTotal
if $previous->isa("PPI::Token::Cast") and $previous eq "\\" 0 131 131
Condition33%1/3
$previous->isa("PPI::Token::Cast") and $previous eq "\\"
!ll&&!rl&&r
13100
MC/DC0%0/2
$previous->isa("PPI::Token::Cast") and $previous eq "\\"
$previous->isa("PPI::Token::Cast") $previous eq "\\"
Truth table33%1/3
A and B
A= $previous->isa("PPI::Token::Cast")B= $previous eq "\\"
ABresult
0X0
100
111
41 }
42  
43 173 ▶ return if ( $elem !~ m{\A [&] }xms ); # ok
Branch: 1 branch
BranchTrueFalseTotal
unless $elem =~ /\A [&] /msx 173 0 173
44  
45 # look up past parens to get say the "defined" in "defined(&foo)" or
46 # "defined((&foo))" etc
47 0 ▶ if (not $previous or
Branch: 1 branch
BranchTrueFalseTotal
if (not $previous or $previous->isa("PPI::Token::Operator") and $IS_COMMA{$previous->content}) 0 0 0
Condition0%0/6
not $previous or $previous->isa("PPI::Token::Operator") and $IS_COMMA{$previous->content}
l!l&&r!l&&!r
000
$previous->isa("PPI::Token::Operator") and $IS_COMMA{$previous->content}
!ll&&!rl&&r
000
MC/DC0%0/3
not $previous or $previous->isa("PPI::Token::Operator") and $IS_COMMA{$previous->content}
not $previous $previous->isa("PPI::Token::Operator") $IS_COMMA{$previous->content}
Truth table0%0/4
not(A) or B and C
A= not $previousB= $previous->isa("PPI::Token::Operator")C= $IS_COMMA{$previous->content}
ABCresult
1XX1
0111
00X0
0100
48 $previous->isa( 'PPI::Token::Operator' ) and
49 $IS_COMMA{ $previous->content() } ) {
50 0 my $up = $elem;
51  
52 PARENT:
53 0 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($up = $up->parent and $up->isa("PPI::Statement::Expression") || $up->isa("PPI::Structure::List") || $up->isa("PPI::Statement")) 0 0 0
Condition0%0/9
$up = $up->parent and $up->isa("PPI::Statement::Expression") || $up->isa("PPI::Structure::List") || $up->isa("PPI::Statement")
!ll&&!rl&&r
000
$up->isa("PPI::Statement::Expression") or $up->isa("PPI::Structure::List") or $up->isa("PPI::Statement")
l!l&&r!l&&!r
000
$up->isa("PPI::Statement::Expression") or $up->isa("PPI::Structure::List")
l!l&&r!l&&!r
000
MC/DC0%0/4
$up = $up->parent and $up->isa("PPI::Statement::Expression") || $up->isa("PPI::Structure::List") || $up->isa("PPI::Statement")
$up = $up->parent $up->isa("PPI::Statement::Expression") $up->isa("PPI::Structure::List") $up->isa("PPI::Statement")
Truth table0%0/5
A and B or C or D
A= $up = $up->parentB= $up->isa("PPI::Statement::Expression")C= $up->isa("PPI::Structure::List")D= $up->isa("PPI::Statement")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
54 ($up = $up->parent)
55 and (
56 $up->isa('PPI::Statement::Expression')
57 or $up->isa('PPI::Structure::List')
58 or $up->isa('PPI::Statement')
59 )
60 ) {
61 0 ▶ if (my $word = $up->sprevious_sibling) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $word = $up->sprevious_sibling) 0 0 0
62 # Since backslashes distribute over lists (per perlref), if
63 # we have a list and the previous is a backslash, we're cool.
64 return if
65 0 ▶ $up->isa('PPI::Structure::List')
Branch: 1 branch
BranchTrueFalseTotal
if $up->isa("PPI::Structure::List") and $word->isa("PPI::Token::Cast") and $word->content eq "\\" 0 0 0
Condition0%0/6
$up->isa("PPI::Structure::List") and $word->isa("PPI::Token::Cast") and $word->content eq "\\"
!ll&&!rl&&r
000
$up->isa("PPI::Structure::List") and $word->isa("PPI::Token::Cast")
!ll&&!rl&&r
000
MC/DC0%0/3
$up->isa("PPI::Structure::List") and $word->isa("PPI::Token::Cast") and $word->content eq "\\"
$up->isa("PPI::Structure::List") $word->isa("PPI::Token::Cast") $word->content eq "\\"
Truth table0%0/4
A and B and C
A= $up->isa("PPI::Structure::List")B= $word->isa("PPI::Token::Cast")C= $word->content eq "\\"
ABCresult
0XX0
10X0
1100
1111
66 && $word->isa('PPI::Token::Cast')
67 && $word->content() eq q{\\};
68  
69 # For a word set $previous to have it checked against %EXEMPTIONS
70 # below. For a non-word it's a violation, leave $previous false
71 # to get there.
72 0 ▶ if ($word->isa('PPI::Token::Word')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word->isa("PPI::Token::Word")) 0 0 0
73 0 $previous = $word;
74 }
75 0 last PARENT;
76 }
77 }
78 }
79 0 ▶ return if $previous and $EXEMPTIONS{$previous};
Branch: 1 branch
BranchTrueFalseTotal
if $previous and $EXEMPTIONS{$previous} 0 0 0
Condition0%0/3
$previous and $EXEMPTIONS{$previous}
!ll&&!rl&&r
000
MC/DC0%0/2
$previous and $EXEMPTIONS{$previous}
$previous $EXEMPTIONS{$previous}
Truth table0%0/3
A and B
A= $previousB= $EXEMPTIONS{$previous}
ABresult
0X0
100
111
80  
81 0 return $self->violation( $DESC, $EXPL, $elem );
82 }
83  
84 40 1;
85  
86 __END__
« lib/Perl/Critic/Policy/ValuesAndExpressions/RequireConstantVersion.pm ↑ Summary lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusedCapture.pm »