| 1 | package Perl::Critic::Policy::Reneeb::Capitalization; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: NamingConventions::Capitalization plus the ability to exempt "Full qualified package names" | ||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 5 | ▶ | use base 'Perl::Critic::Policy::NamingConventions::Capitalization'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 5 | our $VERSION = '2.05'; | |||||||||
| 11 | |||||||||||
| 12 | 15 | ▶ | sub supported_parameters { | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 13 | 15 | my ($self) = @_; | |||||||||
| 14 | |||||||||||
| 15 | 15 | my @params = $self->SUPER::supported_parameters(); | |||||||||
| 16 | |||||||||||
| 17 | 15 | push @params, { | |||||||||
| 18 | name => 'full_qualified_package_exemptions', | ||||||||||
| 19 | description => 'Package names that are exempt from capitalization rules. The values here are regexes that will be surrounded by \A and \z.', | ||||||||||
| 20 | default_string => 'main', | ||||||||||
| 21 | behavior => 'string list', | ||||||||||
| 22 | }; | ||||||||||
| 23 | |||||||||||
| 24 | 15 | return @params; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 4 | ▶ | sub initialize_if_enabled { | ||||||||
|
Subroutine
initialize_if_enabled: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 28 | 4 | my ($self, $config) = @_; | |||||||||
| 29 | |||||||||||
| 30 | 4 | my $return = $self->SUPER::initialize_if_enabled( $config ); | |||||||||
| 31 | |||||||||||
| 32 | 4 | my $option = $self->{_full_qualified_package_exemptions}; | |||||||||
| 33 | |||||||||||
| 34 | 4 | my $configuration_exceptions = | |||||||||
| 35 | Perl::Critic::Exception::AggregateConfiguration->new(); | ||||||||||
| 36 | |||||||||||
| 37 | 4 | for my $pattern ( sort keys %{$option} ) { | |||||||||
| 38 | 4 | my $regex; | |||||||||
| 39 | 4 | eval { $regex = qr{ \A $pattern \z }xms; } | |||||||||
| 40 | 4 | ▶ | or do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 1 | $configuration_exceptions->add_exception( | |||||||||
| 42 | Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue->new( | ||||||||||
| 43 | policy => $self, | ||||||||||
| 44 | option_name => '_full_qualified_package_exemptions', | ||||||||||
| 45 | option_value => $pattern, | ||||||||||
| 46 | message_suffix => | ||||||||||
| 47 | "is not a valid regular expression: $@", | ||||||||||
| 48 | ) | ||||||||||
| 49 | ); | ||||||||||
| 50 | }; | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 4 | ▶ | if ( $configuration_exceptions->has_exceptions ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 1 | $configuration_exceptions->throw; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 3 | return $return; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 21 | ▶ | sub _package_capitalization { | ||||||||
|
Subroutine
_package_capitalization: called CC=3 SCAR=11.0
| |||||||||||
| 61 | 21 | my ($self, $elem) = @_; | |||||||||
| 62 | |||||||||||
| 63 | 21 | my $namespace = $elem->namespace(); | |||||||||
| 64 | 21 | my $option = $self->{_full_qualified_package_exemptions}; | |||||||||
| 65 | |||||||||||
| 66 | 21 | for my $pattern ( sort keys %{$option} ) { | |||||||||
| 67 | 21 | ▶ | return if $namespace =~ m{\A $pattern \z}xms; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 16 | return $self->SUPER::_package_capitalization( $elem ); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 5 | 1; | |||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||