Policy/Reneeb/Capitalization.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 100% 49 / 49 CC 6 SCAR 9.7
CC
6
Cov
100%
initialize_if_enabled
4.0
_package_capitalization
3.0
BEGIN
1.0
CRAP 2.6
« Policy/Reneeb/ProhibitGrepToGetFirstFoundElement.pm ↑ Summary Policy/Reneeb/RequirePostderef.pm »
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
BranchTrueFalseTotal
eval { do { $regex = qr/ \A $pattern \z /msx } } or do { $configuration_exceptions->add_exception("Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue"->new("policy", $self, "option_name", "_full_qualified_package_exemptions", "option_value", $pattern, "message_suffix", "is not a valid regular expression: $@")) } 3 1 4
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
BranchTrueFalseTotal
if ($configuration_exceptions->has_exceptions) 1 3 4
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
BranchTrueFalseTotal
if $namespace =~ /\A $pattern \z/msx 5 16 21
68 }
69
70 16 return $self->SUPER::_package_capitalization( $elem );
71 }
72  
73 5 1;
74  
75 __END__
« Policy/Reneeb/ProhibitGrepToGetFirstFoundElement.pm ↑ Summary Policy/Reneeb/RequirePostderef.pm »