blib/lib/Perl/Critic/Policy/Variables/ProhibitPerl4PackageNames.pm

filter: Statementstmt 84.8% 28 / 33 Branchbran 16.6% 1 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 73.3% 44 / 60 CC 5 SCAR 17.0
CC
5
Cov
69%
violates
14.4
BEGIN
1.0
BEGIN
1.0
CRAP 5.5
« blib/lib/Perl/Critic.pm ↑ Summary blib/lib/Perl/Critic/UserProfile.pm »
1 package Perl::Critic::Policy::Variables::ProhibitPerl4PackageNames;
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 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :characters :severities :classification };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.150';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $EXPL =>
16 q{Use double colon (::) to separate package name components instead of single quotes (')};
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 75 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 74 ▶sub default_themes { return qw(core maintenance certrec ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 31 ▶sub applies_to { return qw( PPI::Token::Word PPI::Token::Symbol ) }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24  
25 #-----------------------------------------------------------------------------
26  
27 sub violates {
28 505 ▶ my ( $self, $elem, undef ) = @_;
Subroutine violates: called CC=5 SCAR=26.7
Pod documented
29 505 my $content = $elem->content();
30  
31 505 ▶ if ( (index $content, $QUOTE) < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($content, $Perl::Critic::Policy::Variables::ProhibitPerl4PackageNames::QUOTE) == -1) 505 0 505
32 505 return;
33 }
34  
35 0 ▶ if ( $content =~ m< \A [\$@%&*] ' \z >xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ / \A [\$\@%&*] ' \z /msx) 0 0 0
36 # We've found $POSTMATCH.
37 0 return;
38 }
39  
40 0 ▶ if ( $elem->isa('PPI::Token::Word') && is_hash_key($elem) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Word") and is_hash_key($elem)) 0 0 0
Condition0%0/3
$elem->isa("PPI::Token::Word") and is_hash_key($elem)
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa("PPI::Token::Word") and is_hash_key($elem)
$elem->isa("PPI::Token::Word") is_hash_key($elem)
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Word")B= is_hash_key($elem)
ABresult
0X0
100
111
41 0 return;
42 }
43  
44 return
45 0 $self->violation(
46 qq{"$content" uses the obsolete single quote package separator.},
47 $EXPL,
48 $elem
49 );
50 }
51  
52 #-----------------------------------------------------------------------------
53  
54 40 1;
55  
56 __END__
57  
58 #-----------------------------------------------------------------------------
59  
60 =pod
61  
62 =for stopwords perlmod
63  
64 =head1 NAME
65  
66 Perl::Critic::Policy::Variables::ProhibitPerl4PackageNames - Use double colon (::) to separate package name components instead of single quotes (').
67  
68  
69 =head1 AFFILIATION
70  
71 This Policy is part of the core L<Perl::Critic|Perl::Critic>
72 distribution.
73  
74  
75 =head1 DESCRIPTION
76  
77 Perl 5 kept single quotes (C<'>) as package component separators in
78 order to remain backward compatible with prior C<perl>s, but advocated
79 using double colon (C<::>) instead. In the more than a decade since
80 Perl 5, double colons have been overwhelmingly adopted and most people
81 are not even aware that the single quote can be used in this manner.
82 So, unless you're trying to obfuscate your code, don't use them.
83  
84 package Foo::Bar::Baz; #ok
85 package Foo'Bar'Baz; #not ok
86  
87  
88 =head1 CONFIGURATION
89  
90 This Policy is not configurable except for the standard options.
91  
92  
93 =head1 SEE ALSO
94  
95 L<perlmod|perlmod>
96  
97  
98 =head1 AUTHOR
99  
100 Elliot Shank C<< <perl@galumph.com> >>
101  
102  
103 =head1 COPYRIGHT
104  
105 Copyright (c) 2007-2014 Elliot Shank.
106  
107 This program is free software; you can redistribute it and/or modify
108 it under the same terms as Perl itself. The full text of this license
109 can be found in the LICENSE file included with this module.
110  
111 =cut
112  
113 # Local Variables:
114 # mode: cperl
115 # cperl-indent-level: 4
116 # fill-column: 78
117 # indent-tabs-mode: nil
118 # c-indentation-style: bsd
119 # End:
120 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
« blib/lib/Perl/Critic.pm ↑ Summary blib/lib/Perl/Critic/UserProfile.pm »