File Coverage

blib/lib/Perl/Critic/Policy/NamingConventions/ProhibitMixedCaseSubs.pm
Criterion Covered Total %
statement 26 27 96.3
branch 2 2 100.0
condition n/a
subroutine 10 11 90.9
pod 4 5 80.0
total 42 45 93.3


line stmt bran cond sub pod time code
1             ##############################################################################
2             # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-Deprecated/lib/Perl/Critic/Policy/NamingConventions/ProhibitMixedCaseSubs.pm $
3             # $Date: 2013-10-29 09:11:44 -0700 (Tue, 29 Oct 2013) $
4             # $Author: thaljef $
5             # $Revision: 4214 $
6             ##############################################################################
7              
8             package Perl::Critic::Policy::NamingConventions::ProhibitMixedCaseSubs;
9              
10 1     1   1129 use 5.006001;
  1         4  
  1         40  
11 1     1   6 use strict;
  1         1  
  1         34  
12 1     1   6 use warnings;
  1         2  
  1         41  
13 1     1   6 use Readonly;
  1         2  
  1         57  
14              
15 1     1   6 use Perl::Critic::Utils qw{ :severities };
  1         10  
  1         74  
16              
17 1     1   183 use base 'Perl::Critic::Policy';
  1         3  
  1         425  
18              
19             our $VERSION = '1.119';
20              
21             #-----------------------------------------------------------------------------
22              
23             Readonly::Scalar my $UPPER_LOWER => qr/ [[:upper:]] [[:lower:]] /xms;
24             Readonly::Scalar my $LOWER_UPPER => qr/ [[:lower:]] [[:upper:]] /xms;
25             Readonly::Scalar my $MIXED_RX => qr{ $UPPER_LOWER | $LOWER_UPPER }xmso;
26             Readonly::Scalar my $DESC => 'Mixed-case subroutine name';
27             Readonly::Scalar my $EXPL => [ 45, 46 ];
28              
29             #-----------------------------------------------------------------------------
30              
31 2     2 0 13168 sub supported_parameters { return () }
32 4     4 1 47 sub default_severity { return $SEVERITY_LOWEST }
33 0     0 1 0 sub default_themes { return qw( deprecated pbp cosmetic ) }
34 2     2 1 20983 sub applies_to { return 'PPI::Statement::Sub' }
35              
36             #-----------------------------------------------------------------------------
37              
38             sub violates {
39 9     9 1 662 my ( $self, $elem, undef ) = @_;
40 9         28 (my $name = $elem->name() ) =~ s/\A.*:://xms;
41 9 100       237 if ( $name =~ m/$MIXED_RX/xms ) {
42 4         22 return $self->violation( $DESC, $EXPL, $elem );
43             }
44 5         12 return; #ok!
45             }
46              
47             1;
48              
49             __END__
50              
51             #-----------------------------------------------------------------------------
52              
53             =pod
54              
55             =head1 NAME
56              
57             Perl::Critic::Policy::NamingConventions::ProhibitMixedCaseSubs - Write C<sub my_function{}> instead of C<sub MyFunction{}>.
58              
59              
60             =head1 AFFILIATION
61              
62             This Policy is part of the
63             L<Perl::Critic::Deprecated|Perl::Critic::Deprecated> distribution.
64              
65              
66             =head1 DESCRIPTION
67              
68             Conway's recommended naming convention is to use lower-case words
69             separated by underscores. Well-recognized acronyms can be in ALL
70             CAPS, but must be separated by underscores from other parts of the
71             name.
72              
73             sub foo_bar{} #ok
74             sub foo_BAR{} #ok
75             sub FOO_bar{} #ok
76             sub FOO_BAR{} #ok
77              
78             sub Some::Class::foo{} #ok, grudgingly
79              
80             sub FooBar {} #not ok
81             sub FOObar {} #not ok
82             sub fooBAR {} #not ok
83             sub fooBar {} #not ok
84              
85              
86             =head1 CONFIGURATION
87              
88             This Policy is not configurable except for the standard options.
89              
90              
91             =head1 SEE ALSO
92              
93             L<Perl::Critic::Policy::NamingConventions::ProhibitMixedCaseVars|Perl::Critic::Policy::NamingConventions::ProhibitMixedCaseVars>
94              
95             This policy is deprecated. Its functionality has been superseded by
96             L<Perl::Critic::Policy::NamingConventions::Capitalization|Perl::Critic::Policy::NamingConventions::Capitalization>.
97              
98             =head1 AUTHOR
99              
100             Jeffrey Ryan Thalhammer <thaljef@cpan.org>
101              
102             =head1 COPYRIGHT
103              
104             Copyright (c) 2005-2013 Jeffrey Ryan Thalhammer. All rights reserved.
105              
106             This program is free software; you can redistribute it and/or modify
107             it under the same terms as Perl itself. The full text of this license
108             can be found in the LICENSE file included with this module.
109              
110             =cut
111              
112             # Local Variables:
113             # mode: cperl
114             # cperl-indent-level: 4
115             # fill-column: 78
116             # indent-tabs-mode: nil
117             # c-indentation-style: bsd
118             # End:
119             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :