1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/NamingConventions/ProhibitMixedCaseVars.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::NamingConventions::ProhibitMixedCaseVars;
15 use Perl::Critic::Utils qw{ :severities };
17 use base 'Perl::Critic::Policy';
19 our $VERSION = '1.088';
21 #-----------------------------------------------------------------------------
23 Readonly::Scalar my $PACKAGE_RX => qr/ :: /mx;
24 Readonly::Scalar my $UPPER_LOWER => qr/ [[:upper:]] [[:lower:]] /xm;
25 Readonly::Scalar my $LOWER_UPPER => qr/ [[:lower:]] [[:upper:]] /xm;
26 Readonly::Scalar my $MIXED_RX => qr{ $UPPER_LOWER | $LOWER_UPPER }xmo;
27 Readonly::Scalar my $DESC => 'Mixed-case variable name(s)';
28 Readonly::Scalar my $EXPL => [ 44 ];
30 #-----------------------------------------------------------------------------
32 sub supported_parameters { return () }
33 sub default_severity { return $SEVERITY_LOWEST }
34 sub default_themes { return qw( core pbp cosmetic ) }
35 sub applies_to { return 'PPI::Statement::Variable' }
37 #-----------------------------------------------------------------------------
40 my ( $self, $elem, undef ) = @_;
41 if ( _has_mixed_case_vars($elem) ) {
42 return $self->violation( $DESC, $EXPL, $elem );
48 sub _has_mixed_case_vars {
50 for my $variable_name ( $elem->variables() ) {
52 #Variables with fully qualified package names are exempt
53 #because we can't really be responsible for symbols that
54 #are defined in other packages.
56 next if $elem->type() eq 'local' && $variable_name =~ m/$PACKAGE_RX/xms;
57 return 1 if $variable_name =~ m/$MIXED_RX/xms;
66 #-----------------------------------------------------------------------------
72 Perl::Critic::Policy::NamingConventions::ProhibitMixedCaseVars - Write C<$my_variable = 42> instead of C<$MyVariable = 42>.
76 This Policy is part of the core L<Perl::Critic> distribution.
81 Conway's recommended naming convention is to use lower-case words
82 separated by underscores. Well-recognized acronyms can be in ALL
83 CAPS, but must be separated by underscores from other parts of the
99 This Policy is not configurable except for the standard options.
104 L<Perl::Critic::Policy::NamingConventions::ProhibitMixedCaseSubs>
108 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
112 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
114 This program is free software; you can redistribute it and/or modify
115 it under the same terms as Perl itself. The full text of this license
116 can be found in the LICENSE file included with this module.
122 # cperl-indent-level: 4
124 # indent-tabs-mode: nil
125 # c-indentation-style: bsd
127 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :