blib/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
« blib/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireConstantVersion.pm ↑ Summary blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitMagicNumbers.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.150';
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 75 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
29 86 ▶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 sub violates {
35 173 ▶ my ( $self, $elem, undef ) = @_;
Subroutine violates: called CC=19 SCAR=54.3
Pod documented
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__
87  
88 #-----------------------------------------------------------------------------
89  
90 =pod
91  
92 =head1 NAME
93  
94 Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils - Don't call functions with a leading ampersand sigil.
95  
96 =head1 AFFILIATION
97  
98 This Policy is part of the core L<Perl::Critic|Perl::Critic>
99 distribution.
100  
101  
102 =head1 DESCRIPTION
103  
104 Since Perl 5, the ampersand sigil is completely optional when invoking
105 subroutines. It also turns off checking of subroutine prototypes.
106 It's easily confused with the bitwise 'and' operator.
107  
108 @result = &some_function(); # not ok
109 @result = some_function(); # ok
110  
111  
112 =head1 CONFIGURATION
113  
114 This Policy is not configurable except for the standard options.
115  
116  
117 =head1 AUTHOR
118  
119 Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
120  
121 =head1 COPYRIGHT
122  
123 Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
124  
125 This program is free software; you can redistribute it and/or modify
126 it under the same terms as Perl itself. The full text of this license
127 can be found in the LICENSE file included with this module.
128  
129 =cut
130  
131 # Local Variables:
132 # mode: cperl
133 # cperl-indent-level: 4
134 # fill-column: 78
135 # indent-tabs-mode: nil
136 # c-indentation-style: bsd
137 # End:
138 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
« blib/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireConstantVersion.pm ↑ Summary blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitMagicNumbers.pm »