NAME

Perl::Critic::Policy::NamingConventions::Capitalization - Distinguish different program components by case.

AFFILIATION

This Policy is part of the core Perl::Critic distribution.

DESCRIPTION

Conway recommends to distinguish different program components by case.

Normal subroutines, methods and variables are all in lower case.

my $foo;            # ok
my $foo_bar;        # ok
sub foo {}          # ok
sub foo_bar {}      # ok

my $Foo;            # not ok
my $foo_Bar;        # not ok
sub Foo     {}      # not ok
sub foo_Bar {}      # not ok

Package and class names are capitalized.

package IO::Thing;     # ok
package Web::FooBar    # ok

package foo;           # not ok
package foo::Bar;      # not ok

Constants are in all-caps.

Readonly::Scalar my $FOO = 42;  # ok

Readonly::Scalar my $foo = 42;  # not ok

CONFIGURATION

You can specify capitalization rules for the following things: packages, subroutines, local_lexical_variables, scoped_lexical_variables, file_lexical_variables, global_variables, and constants.

constants are things declared via constant or Readonly.

use constant FOO => 193;
Readonly::Array my @BAR => qw< a b c >;

global_variables are anything declared using local or our. file_lexical_variables are variables declared at the file scope.

scoped_lexical_variables are variables declared inside bare blocks that are outside of any subroutines or other control structures; these are usually created to limit scope of variables to a given subset of subroutines. E.g.

sub foo { ... }

{
    my $thingy;

    sub bar { ... $thingy ... }
    sub baz { ... $thingy ... }
}

All other variable declarations are considered local_lexical_variables.

Each of the packages, subroutines, local_lexical_variables, scoped_lexical_variables, file_lexical_variables, global_variables, and constants options can be specified as one of :single_case, :all_lower, :all_upper:, :starts_with_lower, :starts_with_upper, or :no_restriction or a regular expression. The :single_case tag means a name can be all lower case or all upper case. If a regular expression is specified, it is surrounded by \A and \z.

packages defaults to :starts_with_upper. subroutines, local_lexical_variables, scoped_lexical_variables, file_lexical_variables, and global_variables default to :all_lower. And constants defaults to :all_upper.

There are corresponding package_exemptions, subroutine_exemptions, local_lexical_variable_exemptions, scoped_lexical_variable_exemptions, file_lexical_variable_exemptions, global_variable_exemptions, and constant_exemptions options that are lists of regular expressions to exempt from the corresponding capitalization rule. These values also end up being surrounded by \A and \z.

package_exemptions defaults to main. global_variable_exemptions defaults to \$VERSION @ISA @EXPORT(?:_OK)? %EXPORT_TAGS \$AUTOLOAD %ENV %SIG \$TODO.

TODO

Handle use vars. Treat constant subroutines like constant variables.

AUTHOR

Michael G Schwern <schwern@pobox.com>

COPYRIGHT

Copyright (c) 2008 Michael G Schwern. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.