« lib/Perl/Critic/Policy/Variables/ProhibitConditionalDeclarations.pm
↑ Summary
lib/Perl/Critic.pm »
| 1 | package Perl::Critic::Config; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use List::SomeUtils qw( any apply ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 40 | ▶ | use Perl::Critic::Exception::AggregateConfiguration; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 40 | ▶ | use Perl::Critic::Exception::Configuration; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 40 | ▶ | use Perl::Critic::Exception::Configuration::Option::Global::ParameterValue; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 40 | ▶ | use Perl::Critic::Exception::Fatal::Internal qw{ throw_internal }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 40 | ▶ | use Perl::Critic::PolicyFactory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 40 | ▶ | use Perl::Critic::Theme qw( $RULE_INVALID_CHARACTER_REGEX cook_rule ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 40 | ▶ | use Perl::Critic::UserProfile qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 40 | ▶ | use Perl::Critic::Utils qw{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | :booleans :characters :severities :internal_lookup :classification | ||||||||||||||||||||||||||||
| 22 | :data_conversion | ||||||||||||||||||||||||||||
| 23 | 40 | }; | |||||||||||||||||||||||||||
| 24 | 40 | ▶ | use Perl::Critic::Utils::Constants qw< | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | :profile_strictness | ||||||||||||||||||||||||||||
| 26 | $_MODULE_VERSION_TERM_ANSICOLOR | ||||||||||||||||||||||||||||
| 27 | 40 | >; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 40 | Readonly::Scalar my $SINGLE_POLICY_CONFIG_KEY => 'single-policy'; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 38 | # Constructor | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 280 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 280 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||
| 43 | 280 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 44 | 280 | $self->_init( %args ); | |||||||||||||||||||||||||||
| 45 | 276 | return $self; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 280 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||
| 51 | 280 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # -top or -theme imply that -severity is 1, unless it is already defined | ||||||||||||||||||||||||||||
| 54 | 280 | ▶ | if ( defined $args{-top} || defined $args{-theme} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args{"-top"} or defined $args{"-theme"}
MC/DC100%2/2
defined $args{"-top"} or defined $args{"-theme"}
defined $args{"-top"}
defined $args{"-theme"}
Truth table100%3/3
A or B
A= defined $args{"-top"}B= defined $args{"-theme"}
| |||||||||||||||||||||||||||||
| 55 | 55 | ▶ | $args{-severity} ||= $SEVERITY_LOWEST; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"-severity"} ||= $Perl::Critic::Config::SEVERITY_LOWEST
MC/DC0%0/2
$args{"-severity"} ||= $Perl::Critic::Config::SEVERITY_LOWEST
$args{"-severity"}
$Perl::Critic::Config::SEVERITY_LOWEST
Truth table66%2/3
A ||= B
A= $args{"-severity"}B= $Perl::Critic::Config::SEVERITY_LOWEST
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 280 | my $errors = Perl::Critic::Exception::AggregateConfiguration->new(); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Construct the UserProfile to get default options. | ||||||||||||||||||||||||||||
| 61 | 280 | my $profile_source = $args{-profile}; # Can be file path or data struct | |||||||||||||||||||||||||||
| 62 | 280 | my $profile = Perl::Critic::UserProfile->new( -profile => $profile_source ); | |||||||||||||||||||||||||||
| 63 | 280 | my $options_processor = $profile->options_processor(); | |||||||||||||||||||||||||||
| 64 | 280 | $self->{_profile} = $profile; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | $self->_validate_and_save_profile_strictness( | ||||||||||||||||||||||||||||
| 67 | 280 | $args{'-profile-strictness'}, | |||||||||||||||||||||||||||
| 68 | $errors, | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # If given, these options should always have a true value. | ||||||||||||||||||||||||||||
| 72 | $self->_validate_and_save_regex( | ||||||||||||||||||||||||||||
| 73 | 280 | 'include', $args{-include}, $options_processor->include(), $errors | |||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | $self->_validate_and_save_regex( | ||||||||||||||||||||||||||||
| 76 | 280 | 'exclude', $args{-exclude}, $options_processor->exclude(), $errors | |||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||
| 78 | $self->_validate_and_save_regex( | ||||||||||||||||||||||||||||
| 79 | $SINGLE_POLICY_CONFIG_KEY, | ||||||||||||||||||||||||||||
| 80 | 280 | $args{ qq/-$SINGLE_POLICY_CONFIG_KEY/ }, | |||||||||||||||||||||||||||
| 81 | $options_processor->single_policy(), | ||||||||||||||||||||||||||||
| 82 | $errors, | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | $self->_validate_and_save_color_severity( | ||||||||||||||||||||||||||||
| 85 | 280 | 'color_severity_highest', $args{'-color-severity-highest'}, | |||||||||||||||||||||||||||
| 86 | $options_processor->color_severity_highest(), $errors | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | $self->_validate_and_save_color_severity( | ||||||||||||||||||||||||||||
| 89 | 280 | 'color_severity_high', $args{'-color-severity-high'}, | |||||||||||||||||||||||||||
| 90 | $options_processor->color_severity_high(), $errors | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | $self->_validate_and_save_color_severity( | ||||||||||||||||||||||||||||
| 93 | 280 | 'color_severity_medium', $args{'-color-severity-medium'}, | |||||||||||||||||||||||||||
| 94 | $options_processor->color_severity_medium(), $errors | ||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | $self->_validate_and_save_color_severity( | ||||||||||||||||||||||||||||
| 97 | 280 | 'color_severity_low', $args{'-color-severity-low'}, | |||||||||||||||||||||||||||
| 98 | $options_processor->color_severity_low(), $errors | ||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||
| 100 | $self->_validate_and_save_color_severity( | ||||||||||||||||||||||||||||
| 101 | 280 | 'color_severity_lowest', $args{'-color-severity-lowest'}, | |||||||||||||||||||||||||||
| 102 | $options_processor->color_severity_lowest(), $errors | ||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 280 | $self->_validate_and_save_verbosity($args{-verbose}, $errors); | |||||||||||||||||||||||||||
| 106 | 280 | $self->_validate_and_save_severity($args{-severity}, $errors); | |||||||||||||||||||||||||||
| 107 | 280 | $self->_validate_and_save_top($args{-top}, $errors); | |||||||||||||||||||||||||||
| 108 | 280 | $self->_validate_and_save_theme($args{-theme}, $errors); | |||||||||||||||||||||||||||
| 109 | 280 | $self->_validate_and_save_pager($args{-pager}, $errors); | |||||||||||||||||||||||||||
| 110 | $self->_validate_and_save_program_extensions( | ||||||||||||||||||||||||||||
| 111 | 280 | $args{'-program-extensions'}, $errors); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # If given, these options can be true or false (but defined) | ||||||||||||||||||||||||||||
| 114 | 280 | ▶ | $self->{_force} = _boolean_to_number( $args{-force} // $options_processor->force() ); | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"-force"} // $options_processor->force
MC/DC0%0/2
$args{"-force"} // $options_processor->force
$args{"-force"}
$options_processor->force
Truth table66%2/3
A // B
A= $args{"-force"}B= $options_processor->force
| |||||||||||||||||||||||||||||
| 115 | 280 | ▶ | $self->{_only} = _boolean_to_number( $args{-only} // $options_processor->only() ); | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"-only"} // $options_processor->only
MC/DC0%0/2
$args{"-only"} // $options_processor->only
$args{"-only"}
$options_processor->only
Truth table66%2/3
A // B
A= $args{"-only"}B= $options_processor->only
| |||||||||||||||||||||||||||||
| 116 | 280 | ▶ | $self->{_color} = _boolean_to_number( $args{-color} // $options_processor->color() ); | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"-color"} // $options_processor->color
MC/DC0%0/2
$args{"-color"} // $options_processor->color
$args{"-color"}
$options_processor->color
Truth table66%2/3
A // B
A= $args{"-color"}B= $options_processor->color
| |||||||||||||||||||||||||||||
| 117 | $self->{_unsafe_allowed} = | ||||||||||||||||||||||||||||
| 118 | 280 | ▶ | _boolean_to_number( $args{'-allow-unsafe'} // $options_processor->allow_unsafe() ); | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"-allow-unsafe"} // $options_processor->allow_unsafe
MC/DC0%0/2
$args{"-allow-unsafe"} // $options_processor->allow_unsafe
$args{"-allow-unsafe"}
$options_processor->allow_unsafe
Truth table66%2/3
A // B
A= $args{"-allow-unsafe"}B= $options_processor->allow_unsafe
| |||||||||||||||||||||||||||||
| 119 | $self->{_criticism_fatal} = | ||||||||||||||||||||||||||||
| 120 | _boolean_to_number( | ||||||||||||||||||||||||||||
| 121 | 280 | ▶ | $args{'-criticism-fatal'} // $options_processor->criticism_fatal() | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"-criticism-fatal"} // $options_processor->criticism_fatal
MC/DC0%0/2
$args{"-criticism-fatal"} // $options_processor->criticism_fatal
$args{"-criticism-fatal"}
$options_processor->criticism_fatal
Truth table66%2/3
A // B
A= $args{"-criticism-fatal"}B= $options_processor->criticism_fatal
| |||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # Construct a Factory with the Profile | ||||||||||||||||||||||||||||
| 126 | 280 | my $factory = | |||||||||||||||||||||||||||
| 127 | Perl::Critic::PolicyFactory->new( | ||||||||||||||||||||||||||||
| 128 | -profile => $profile, | ||||||||||||||||||||||||||||
| 129 | -errors => $errors, | ||||||||||||||||||||||||||||
| 130 | '-profile-strictness' => $self->profile_strictness(), | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | 280 | $self->{_factory} = $factory; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # Initialize internal storage for Policies | ||||||||||||||||||||||||||||
| 135 | 280 | $self->{_all_policies_enabled_or_not} = []; | |||||||||||||||||||||||||||
| 136 | 280 | $self->{_policies} = []; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # "NONE" means don't load any policies | ||||||||||||||||||||||||||||
| 139 | 280 | ▶ | if ( not defined $profile_source or $profile_source ne 'NONE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $profile_source or $profile_source ne "NONE"
MC/DC100%2/2
not defined $profile_source or $profile_source ne "NONE"
not defined $profile_source
$profile_source ne "NONE"
Truth table100%3/3
not(A) or B
A= not defined $profile_sourceB= $profile_source ne "NONE"
| |||||||||||||||||||||||||||||
| 140 | # Heavy lifting here... | ||||||||||||||||||||||||||||
| 141 | 82 | $self->_load_policies($errors); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 280 | ▶ | if ( $errors->has_exceptions() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 4 | $errors->rethrow(); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 276 | return $self; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 1400 | ▶ | sub _boolean_to_number { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
_boolean_to_number: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 154 | 1400 | ▶ | return $_[0] ? $TRUE : $FALSE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 8044 | ▶ | sub add_policy { | ||||||||||||||||||||||||||
|
Subroutine
add_policy: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 8044 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 8044 | ▶ | if ( not $args{-policy} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 1 | throw_internal q{The -policy argument is required}; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 8043 | my $policy = $args{-policy}; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # If the -policy is already a blessed object, then just add it directly. | ||||||||||||||||||||||||||||
| 170 | 8043 | ▶ | if ( blessed $policy ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 7887 | $self->_add_policy_if_enabled($policy); | |||||||||||||||||||||||||||
| 172 | 7887 | return $self; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # NOTE: The "-config" option is supported for backward compatibility. | ||||||||||||||||||||||||||||
| 176 | 156 | ▶ | my $params = $args{-params} || $args{-config}; | ||||||||||||||||||||||||||
|
Condition100%3/3
$args{'-params'} || $args{'-config'}
MC/DC100%2/2
$args{'-params'} || $args{'-config'}
$args{'-params'}
$args{'-config'}
Truth table100%3/3
A || B
A= $args{'-params'}B= $args{'-config'}
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 156 | my $factory = $self->{_factory}; | |||||||||||||||||||||||||||
| 179 | 156 | my $policy_object = | |||||||||||||||||||||||||||
| 180 | $factory->create_policy(-name=>$policy, -params=>$params); | ||||||||||||||||||||||||||||
| 181 | 155 | $self->_add_policy_if_enabled($policy_object); | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 155 | return $self; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 8042 | ▶ | sub _add_policy_if_enabled { | ||||||||||||||||||||||||||
|
Subroutine
_add_policy_if_enabled: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 189 | 8042 | my ( $self, $policy_object ) = @_; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 8042 | ▶ | my $config = $policy_object->__get_config() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | or throw_internal | ||||||||||||||||||||||||||||
| 193 | q{Policy was not set up properly because it does not have } | ||||||||||||||||||||||||||||
| 194 | . q{a value for its config attribute.}; | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 8042 | push @{ $self->{_all_policies_enabled_or_not} }, $policy_object; | |||||||||||||||||||||||||||
| 197 | 8042 | ▶ | if ( $policy_object->initialize_if_enabled( $config ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 7944 | $policy_object->__set_enabled($TRUE); | |||||||||||||||||||||||||||
| 199 | 7944 | push @{ $self->{_policies} }, $policy_object; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | else { | ||||||||||||||||||||||||||||
| 202 | 98 | $policy_object->__set_enabled($FALSE); | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 8042 | return; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 82 | ▶ | sub _load_policies { | ||||||||||||||||||||||||||
|
Subroutine
_load_policies: called CC=17 SCAR=28.3
| |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 82 | my ( $self, $errors ) = @_; | |||||||||||||||||||||||||||
| 213 | 82 | my $factory = $self->{_factory}; | |||||||||||||||||||||||||||
| 214 | 82 | my @policies = $factory->create_all_policies( $errors ); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 82 | ▶ | return if $errors->has_exceptions(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 80 | for my $policy ( @policies ) { | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # If -single-policy is true, only load policies that match it | ||||||||||||||||||||||||||||
| 221 | 11600 | ▶ | if ( $self->single_policy() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 580 | ▶ | if ( $self->_policy_is_single_policy( $policy ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 147 | $self->add_policy( -policy => $policy ); | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | 580 | next; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # Always exclude unsafe policies, unless instructed not to | ||||||||||||||||||||||||||||
| 229 | 11020 | ▶ | next if not ( $policy->is_safe() or $self->unsafe_allowed() ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$policy->is_safe or $self->unsafe_allowed
MC/DC100%2/2
$policy->is_safe or $self->unsafe_allowed
$policy->is_safe
$self->unsafe_allowed
Truth table100%3/3
A or B
A= $policy->is_safeB= $self->unsafe_allowed
| |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | # To load, or not to load -- that is the question. | ||||||||||||||||||||||||||||
| 232 | 11019 | ▶ | my $load_me = $self->only() ? $FALSE : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | ## no critic (ProhibitPostfixControls) | ||||||||||||||||||||||||||||
| 235 | 11019 | ▶ | $load_me = $FALSE if $self->_policy_is_disabled( $policy ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 11019 | ▶ | $load_me = $TRUE if $self->_policy_is_enabled( $policy ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 11019 | ▶ | $load_me = $FALSE if $self->_policy_is_unimportant( $policy ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 11019 | ▶ | $load_me = $FALSE if not $self->_policy_is_thematic( $policy ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 11019 | ▶ | $load_me = $TRUE if $self->_policy_is_included( $policy ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 11019 | ▶ | $load_me = $FALSE if $self->_policy_is_excluded( $policy ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 11019 | ▶ | next if not $load_me; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 7740 | $self->add_policy( -policy => $policy ); | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | # When using -single-policy, only one policy should ever be loaded. | ||||||||||||||||||||||||||||
| 248 | 80 | ▶ | if ($self->single_policy() && scalar $self->policies() != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->single_policy and scalar $self->policies != 1
MC/DC100%2/2
$self->single_policy and scalar $self->policies != 1
$self->single_policy
scalar $self->policies != 1
Truth table100%3/3
A and B
A= $self->single_policyB= scalar $self->policies != 1
| |||||||||||||||||||||||||||||
| 249 | 2 | $self->_add_single_policy_exception_to($errors); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 80 | return; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 11019 | ▶ | sub _policy_is_disabled { | ||||||||||||||||||||||||||
|
Subroutine
_policy_is_disabled: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 258 | 11019 | my ($self, $policy) = @_; | |||||||||||||||||||||||||||
| 259 | 11019 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||
| 260 | 11019 | return $profile->policy_is_disabled( $policy ); | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 11019 | ▶ | sub _policy_is_enabled { | ||||||||||||||||||||||||||
|
Subroutine
_policy_is_enabled: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 266 | 11019 | my ($self, $policy) = @_; | |||||||||||||||||||||||||||
| 267 | 11019 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||
| 268 | 11019 | return $profile->policy_is_enabled( $policy ); | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 11019 | ▶ | sub _policy_is_thematic { | ||||||||||||||||||||||||||
|
Subroutine
_policy_is_thematic: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 274 | 11019 | my ($self, $policy) = @_; | |||||||||||||||||||||||||||
| 275 | 11019 | my $theme = $self->theme(); | |||||||||||||||||||||||||||
| 276 | 11019 | return $theme->policy_is_thematic( -policy => $policy ); | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 11019 | ▶ | sub _policy_is_unimportant { | ||||||||||||||||||||||||||
|
Subroutine
_policy_is_unimportant: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 282 | 11019 | my ($self, $policy) = @_; | |||||||||||||||||||||||||||
| 283 | 11019 | my $policy_severity = $policy->get_severity(); | |||||||||||||||||||||||||||
| 284 | 11019 | my $min_severity = $self->{_severity}; | |||||||||||||||||||||||||||
| 285 | 11019 | return $policy_severity < $min_severity; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 11019 | ▶ | sub _policy_is_included { | ||||||||||||||||||||||||||
|
Subroutine
_policy_is_included: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 291 | 11019 | my ($self, $policy) = @_; | |||||||||||||||||||||||||||
| 292 | 11019 | my $policy_long_name = ref $policy; | |||||||||||||||||||||||||||
| 293 | 11019 | my @inclusions = $self->include(); | |||||||||||||||||||||||||||
| 294 | 11019 | ▶ | return any { $policy_long_name =~ m/$_/ixms } @inclusions; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 11019 | ▶ | sub _policy_is_excluded { | ||||||||||||||||||||||||||
|
Subroutine
_policy_is_excluded: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 300 | 11019 | my ($self, $policy) = @_; | |||||||||||||||||||||||||||
| 301 | 11019 | my $policy_long_name = ref $policy; | |||||||||||||||||||||||||||
| 302 | 11019 | my @exclusions = $self->exclude(); | |||||||||||||||||||||||||||
| 303 | 11019 | ▶ | return any { $policy_long_name =~ m/$_/ixms } @exclusions; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 580 | ▶ | sub _policy_is_single_policy { | ||||||||||||||||||||||||||
|
Subroutine
_policy_is_single_policy: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 309 | 580 | my ($self, $policy) = @_; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 580 | my @patterns = $self->single_policy(); | |||||||||||||||||||||||||||
| 312 | 580 | ▶ | return if not @patterns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 580 | my $policy_long_name = ref $policy; | |||||||||||||||||||||||||||
| 315 | 580 | ▶ | return any { $policy_long_name =~ m/$_/ixms } @patterns; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 16 | ▶ | sub _new_global_value_exception { | ||||||||||||||||||||||||||
|
Subroutine
_new_global_value_exception: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 321 | 16 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | return | ||||||||||||||||||||||||||||
| 324 | 16 | Perl::Critic::Exception::Configuration::Option::Global::ParameterValue | |||||||||||||||||||||||||||
| 325 | ->new(@args); | ||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 2 | ▶ | sub _add_single_policy_exception_to { | ||||||||||||||||||||||||||
|
Subroutine
_add_single_policy_exception_to: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 331 | 2 | my ($self, $errors) = @_; | |||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 2 | my $message_suffix = $EMPTY; | |||||||||||||||||||||||||||
| 334 | 2 | my $patterns = join q{", "}, $self->single_policy(); | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 2 | ▶ | if (scalar $self->policies() == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 1 | $message_suffix = | |||||||||||||||||||||||||||
| 338 | q{did not match any policies (in combination with } | ||||||||||||||||||||||||||||
| 339 | . q{other policy restrictions).}; | ||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | else { | ||||||||||||||||||||||||||||
| 342 | 1 | $message_suffix = qq{matched multiple policies:\n\t}; | |||||||||||||||||||||||||||
| 343 | 1 | ▶ | $message_suffix .= join qq{,\n\t}, apply { chomp } sort $self->policies(); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 2 | $errors->add_exception( | |||||||||||||||||||||||||||
| 347 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 348 | option_name => $SINGLE_POLICY_CONFIG_KEY, | ||||||||||||||||||||||||||||
| 349 | option_value => $patterns, | ||||||||||||||||||||||||||||
| 350 | message_suffix => $message_suffix, | ||||||||||||||||||||||||||||
| 351 | ) | ||||||||||||||||||||||||||||
| 352 | ); | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 2 | return; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 840 | ▶ | sub _validate_and_save_regex { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_regex: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 360 | 840 | my ($self, $option_name, $args_value, $default_value, $errors) = @_; | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 840 | my $full_option_name; | |||||||||||||||||||||||||||
| 363 | my $source; | ||||||||||||||||||||||||||||
| 364 | 840 | my @regexes; | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 840 | ▶ | if ($args_value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 8 | $full_option_name = "-$option_name"; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 8 | ▶ | if (ref $args_value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 4 | @regexes = @{ $args_value }; | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | else { | ||||||||||||||||||||||||||||
| 373 | 4 | @regexes = ( $args_value ); | |||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 840 | ▶ | if (not @regexes) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 832 | $full_option_name = $option_name; | |||||||||||||||||||||||||||
| 379 | 832 | $source = $self->_profile()->source(); | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 832 | ▶ | if (ref $default_value) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 382 | 556 | @regexes = @{ $default_value }; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | elsif ($default_value) { | ||||||||||||||||||||||||||||
| 385 | 1 | @regexes = ( $default_value ); | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 840 | my $found_errors; | |||||||||||||||||||||||||||
| 390 | 840 | foreach my $regex (@regexes) { | |||||||||||||||||||||||||||
| 391 | 18 | eval { qr/$regex/ixms } | |||||||||||||||||||||||||||
| 392 | 18 | ▶ | or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 393 | 3 | ▶ | my $cleaned_error = $EVAL_ERROR || '<unknown reason>'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Perl::Critic::Config::EVAL_ERROR || '<unknown reason>'
MC/DC0%0/1
$Perl::Critic::Config::EVAL_ERROR || '<unknown reason>'
$Perl::Critic::Config::EVAL_ERROR
Truth table50%1/2
A
A= $Perl::Critic::Config::EVAL_ERROR
| |||||||||||||||||||||||||||||
| 394 | 3 | $cleaned_error =~ | |||||||||||||||||||||||||||
| 395 | s/ [ ] at [ ] .* Config [.] pm [ ] line [ ] \d+ [.] \n? \z/./xms; | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 3 | $errors->add_exception( | |||||||||||||||||||||||||||
| 398 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 399 | option_name => $option_name, | ||||||||||||||||||||||||||||
| 400 | option_value => $regex, | ||||||||||||||||||||||||||||
| 401 | source => $source, | ||||||||||||||||||||||||||||
| 402 | message_suffix => qq{is not valid: $cleaned_error}, | ||||||||||||||||||||||||||||
| 403 | ) | ||||||||||||||||||||||||||||
| 404 | ); | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 3 | $found_errors = 1; | |||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 840 | ▶ | if (not $found_errors) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | 837 | my $option_key = $option_name; | |||||||||||||||||||||||||||
| 412 | 837 | $option_key =~ s/ - /_/xmsg; | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 837 | $self->{"_$option_key"} = \@regexes; | |||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 840 | return; | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 280 | ▶ | sub _validate_and_save_profile_strictness { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_profile_strictness: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 423 | 280 | my ($self, $args_value, $errors) = @_; | |||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 280 | my $option_name; | |||||||||||||||||||||||||||
| 426 | my $source; | ||||||||||||||||||||||||||||
| 427 | 280 | my $profile_strictness; | |||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 280 | ▶ | if ($args_value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | 0 | $option_name = '-profile-strictness'; | |||||||||||||||||||||||||||
| 431 | 0 | $profile_strictness = $args_value; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | else { | ||||||||||||||||||||||||||||
| 434 | 280 | $option_name = 'profile-strictness'; | |||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 280 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||
| 437 | 280 | $source = $profile->source(); | |||||||||||||||||||||||||||
| 438 | 280 | $profile_strictness = $profile->options_processor()->profile_strictness(); | |||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 280 | ▶ | if ( not $PROFILE_STRICTNESSES{$profile_strictness} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 442 | 1 | $errors->add_exception( | |||||||||||||||||||||||||||
| 443 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 444 | option_name => $option_name, | ||||||||||||||||||||||||||||
| 445 | option_value => $profile_strictness, | ||||||||||||||||||||||||||||
| 446 | source => $source, | ||||||||||||||||||||||||||||
| 447 | message_suffix => q{is not one of "} | ||||||||||||||||||||||||||||
| 448 | . join ( q{", "}, (sort keys %PROFILE_STRICTNESSES) ) | ||||||||||||||||||||||||||||
| 449 | . q{".}, | ||||||||||||||||||||||||||||
| 450 | ) | ||||||||||||||||||||||||||||
| 451 | ); | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 1 | $profile_strictness = $PROFILE_STRICTNESS_FATAL; | |||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 280 | $self->{_profile_strictness} = $profile_strictness; | |||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 280 | return; | |||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 280 | ▶ | sub _validate_and_save_verbosity { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_verbosity: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 464 | 280 | my ($self, $args_value, $errors) = @_; | |||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 280 | my $option_name; | |||||||||||||||||||||||||||
| 467 | my $source; | ||||||||||||||||||||||||||||
| 468 | 280 | my $verbosity; | |||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 280 | ▶ | if ($args_value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | 0 | $option_name = '-verbose'; | |||||||||||||||||||||||||||
| 472 | 0 | $verbosity = $args_value; | |||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | else { | ||||||||||||||||||||||||||||
| 475 | 280 | $option_name = 'verbose'; | |||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | 280 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||
| 478 | 280 | $source = $profile->source(); | |||||||||||||||||||||||||||
| 479 | 280 | $verbosity = $profile->options_processor()->verbose(); | |||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 280 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
is_integer($verbosity) and not is_valid_numeric_verbosity($verbosity)
MC/DC50%1/2
is_integer($verbosity) and not is_valid_numeric_verbosity($verbosity)
is_integer($verbosity)
not is_valid_numeric_verbosity($verbosity)
Truth table66%2/3
A and not(B)
A= is_integer($verbosity)B= not is_valid_numeric_verbosity($verbosity)
| |||||||||||||||||||||||||||||
| 483 | is_integer($verbosity) | ||||||||||||||||||||||||||||
| 484 | and not is_valid_numeric_verbosity($verbosity) | ||||||||||||||||||||||||||||
| 485 | ) { | ||||||||||||||||||||||||||||
| 486 | 1 | $errors->add_exception( | |||||||||||||||||||||||||||
| 487 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 488 | option_name => $option_name, | ||||||||||||||||||||||||||||
| 489 | option_value => $verbosity, | ||||||||||||||||||||||||||||
| 490 | source => $source, | ||||||||||||||||||||||||||||
| 491 | message_suffix => | ||||||||||||||||||||||||||||
| 492 | 'is not the number of one of the pre-defined verbosity formats.', | ||||||||||||||||||||||||||||
| 493 | ) | ||||||||||||||||||||||||||||
| 494 | ); | ||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | else { | ||||||||||||||||||||||||||||
| 497 | 279 | $self->{_verbose} = $verbosity; | |||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 280 | return; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 280 | ▶ | sub _validate_and_save_severity { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_severity: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 506 | 280 | my ($self, $args_value, $errors) = @_; | |||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 280 | my $option_name; | |||||||||||||||||||||||||||
| 509 | my $source; | ||||||||||||||||||||||||||||
| 510 | 280 | my $severity; | |||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | 280 | ▶ | if ($args_value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 68 | $option_name = '-severity'; | |||||||||||||||||||||||||||
| 514 | 68 | $severity = $args_value; | |||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||
| 516 | else { | ||||||||||||||||||||||||||||
| 517 | 212 | $option_name = 'severity'; | |||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 212 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||
| 520 | 212 | $source = $profile->source(); | |||||||||||||||||||||||||||
| 521 | 212 | $severity = $profile->options_processor()->severity(); | |||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 280 | ▶ | if ( is_integer($severity) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 525 | 274 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$severity >= $Perl::Critic::Config::SEVERITY_LOWEST and $severity <= $Perl::Critic::Config::SEVERITY_HIGHEST
MC/DC50%1/2
$severity >= $Perl::Critic::Config::SEVERITY_LOWEST and $severity <= $Perl::Critic::Config::SEVERITY_HIGHEST
$severity >= $Perl::Critic::Config::SEVERITY_LOWEST
$severity <= $Perl::Critic::Config::SEVERITY_HIGHEST
Truth table66%2/3
A and B
A= $severity >= $Perl::Critic::Config::SEVERITY_LOWESTB= $severity <= $Perl::Critic::Config::SEVERITY_HIGHEST
| |||||||||||||||||||||||||||||
| 526 | $severity >= $SEVERITY_LOWEST and $severity <= $SEVERITY_HIGHEST | ||||||||||||||||||||||||||||
| 527 | ) { | ||||||||||||||||||||||||||||
| 528 | 273 | $self->{_severity} = $severity; | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | else { | ||||||||||||||||||||||||||||
| 531 | 1 | $errors->add_exception( | |||||||||||||||||||||||||||
| 532 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 533 | option_name => $option_name, | ||||||||||||||||||||||||||||
| 534 | option_value => $severity, | ||||||||||||||||||||||||||||
| 535 | source => $source, | ||||||||||||||||||||||||||||
| 536 | message_suffix => | ||||||||||||||||||||||||||||
| 537 | "is not between $SEVERITY_LOWEST (low) and $SEVERITY_HIGHEST (high).", | ||||||||||||||||||||||||||||
| 538 | ) | ||||||||||||||||||||||||||||
| 539 | ); | ||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | 20 | ▶ | elsif ( not any { $_ eq lc $severity } @SEVERITY_NAMES ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 543 | 1 | $errors->add_exception( | |||||||||||||||||||||||||||
| 544 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 545 | option_name => $option_name, | ||||||||||||||||||||||||||||
| 546 | option_value => $severity, | ||||||||||||||||||||||||||||
| 547 | source => $source, | ||||||||||||||||||||||||||||
| 548 | message_suffix => | ||||||||||||||||||||||||||||
| 549 | q{is not one of the valid severity names: "} | ||||||||||||||||||||||||||||
| 550 | . join (q{", "}, @SEVERITY_NAMES) | ||||||||||||||||||||||||||||
| 551 | . q{".}, | ||||||||||||||||||||||||||||
| 552 | ) | ||||||||||||||||||||||||||||
| 553 | ); | ||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||
| 555 | else { | ||||||||||||||||||||||||||||
| 556 | 5 | $self->{_severity} = severity_to_number($severity); | |||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 280 | return; | |||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 280 | ▶ | sub _validate_and_save_top { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_top: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 565 | 280 | my ($self, $args_value, $errors) = @_; | |||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | 280 | my $option_name; | |||||||||||||||||||||||||||
| 568 | my $source; | ||||||||||||||||||||||||||||
| 569 | 280 | my $top; | |||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | 280 | ▶ | if (defined $args_value and $args_value ne q{}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args_value and $args_value ne ""
MC/DC100%2/2
defined $args_value and $args_value ne ""
defined $args_value
$args_value ne ""
Truth table100%3/3
A and B
A= defined $args_valueB= $args_value ne ""
| |||||||||||||||||||||||||||||
| 572 | 2 | $option_name = '-top'; | |||||||||||||||||||||||||||
| 573 | 2 | $top = $args_value; | |||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||
| 575 | else { | ||||||||||||||||||||||||||||
| 576 | 278 | $option_name = 'top'; | |||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 278 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||
| 579 | 278 | $source = $profile->source(); | |||||||||||||||||||||||||||
| 580 | 278 | $top = $profile->options_processor()->top(); | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 280 | ▶ | if ( is_integer($top) and $top >= 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
is_integer($top) and $top >= 0
MC/DC50%1/2
is_integer($top) and $top >= 0
is_integer($top)
$top >= 0
Truth table66%2/3
A and B
A= is_integer($top)B= $top >= 0
| |||||||||||||||||||||||||||||
| 584 | 279 | $self->{_top} = $top; | |||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||
| 586 | else { | ||||||||||||||||||||||||||||
| 587 | 1 | $errors->add_exception( | |||||||||||||||||||||||||||
| 588 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 589 | option_name => $option_name, | ||||||||||||||||||||||||||||
| 590 | option_value => $top, | ||||||||||||||||||||||||||||
| 591 | source => $source, | ||||||||||||||||||||||||||||
| 592 | message_suffix => q{is not a non-negative integer.}, | ||||||||||||||||||||||||||||
| 593 | ) | ||||||||||||||||||||||||||||
| 594 | ); | ||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 280 | return; | |||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | 280 | ▶ | sub _validate_and_save_theme { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_theme: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 603 | 280 | my ($self, $args_value, $errors) = @_; | |||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | 280 | my $option_name; | |||||||||||||||||||||||||||
| 606 | my $source; | ||||||||||||||||||||||||||||
| 607 | 280 | my $theme_rule; | |||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | 280 | ▶ | if ($args_value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 610 | 52 | $option_name = '-theme'; | |||||||||||||||||||||||||||
| 611 | 52 | $theme_rule = $args_value; | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | else { | ||||||||||||||||||||||||||||
| 614 | 228 | $option_name = 'theme'; | |||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | 228 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||
| 617 | 228 | $source = $profile->source(); | |||||||||||||||||||||||||||
| 618 | 228 | $theme_rule = $profile->options_processor()->theme(); | |||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | 280 | ▶ | if ( $theme_rule =~ m/$RULE_INVALID_CHARACTER_REGEX/xms ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 622 | 0 | my $bad_character = $1; | |||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | 0 | $errors->add_exception( | |||||||||||||||||||||||||||
| 625 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 626 | option_name => $option_name, | ||||||||||||||||||||||||||||
| 627 | option_value => $theme_rule, | ||||||||||||||||||||||||||||
| 628 | source => $source, | ||||||||||||||||||||||||||||
| 629 | message_suffix => | ||||||||||||||||||||||||||||
| 630 | qq{contains an illegal character ("$bad_character").}, | ||||||||||||||||||||||||||||
| 631 | ) | ||||||||||||||||||||||||||||
| 632 | ); | ||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||
| 634 | else { | ||||||||||||||||||||||||||||
| 635 | 280 | my $rule_as_code = cook_rule($theme_rule); | |||||||||||||||||||||||||||
| 636 | 280 | $rule_as_code =~ s/ [\w\d]+ / 1 /gxms; | |||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | # eval of an empty string does not reset $@ in Perl 5.6. | ||||||||||||||||||||||||||||
| 639 | 280 | local $EVAL_ERROR = $EMPTY; | |||||||||||||||||||||||||||
| 640 | 280 | eval $rule_as_code; ## no critic (ProhibitStringyEval, RequireCheckingReturnValueOfEval) | |||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | 280 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 643 | 1 | $errors->add_exception( | |||||||||||||||||||||||||||
| 644 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 645 | option_name => $option_name, | ||||||||||||||||||||||||||||
| 646 | option_value => $theme_rule, | ||||||||||||||||||||||||||||
| 647 | source => $source, | ||||||||||||||||||||||||||||
| 648 | message_suffix => q{is not syntactically valid.}, | ||||||||||||||||||||||||||||
| 649 | ) | ||||||||||||||||||||||||||||
| 650 | ); | ||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||
| 652 | else { | ||||||||||||||||||||||||||||
| 653 | eval { | ||||||||||||||||||||||||||||
| 654 | $self->{_theme} = | ||||||||||||||||||||||||||||
| 655 | 279 | Perl::Critic::Theme->new( -rule => $theme_rule ); | |||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||
| 657 | 279 | ▶ | or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 658 | 0 | $errors->add_exception_or_rethrow( $EVAL_ERROR ); | |||||||||||||||||||||||||||
| 659 | }; | ||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | 280 | return; | |||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | 280 | ▶ | sub _validate_and_save_pager { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_pager: called CC=5 SCAR=18.5
| |||||||||||||||||||||||||||||
| 669 | 280 | my ($self, $args_value, $errors) = @_; | |||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | 280 | my $pager; | |||||||||||||||||||||||||||
| 672 | 280 | ▶ | if ( $args_value ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 673 | 0 | $pager = $args_value; | |||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||
| 675 | elsif ( $ENV{PERLCRITIC_PAGER} ) { | ||||||||||||||||||||||||||||
| 676 | 0 | $pager = $ENV{PERLCRITIC_PAGER}; | |||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||
| 678 | else { | ||||||||||||||||||||||||||||
| 679 | 280 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||
| 680 | 280 | $pager = $profile->options_processor()->pager(); | |||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | 280 | ▶ | if ($pager eq '$PAGER') { ## no critic (RequireInterpolationOfMetachars) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 684 | 0 | $pager = $ENV{PAGER}; | |||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||
| 686 | 280 | ▶ | $pager ||= $EMPTY; | ||||||||||||||||||||||||||
|
Condition33%1/3
$pager ||= $Perl::Critic::Config::EMPTY
MC/DC0%0/2
$pager ||= $Perl::Critic::Config::EMPTY
$pager
$Perl::Critic::Config::EMPTY
Truth table33%1/3
A ||= B
A= $pagerB= $Perl::Critic::Config::EMPTY
| |||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | 280 | $self->{_pager} = $pager; | |||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||
| 690 | 280 | return; | |||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | 1400 | ▶ | sub _validate_and_save_color_severity { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_color_severity: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 696 | 1400 | my ($self, $option_name, $args_value, $default_value, $errors) = @_; | |||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | 1400 | my $source; | |||||||||||||||||||||||||||
| 699 | my $color_severity; | ||||||||||||||||||||||||||||
| 700 | 1400 | my $full_option_name; | |||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | 1400 | ▶ | if (defined $args_value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 703 | 5 | $full_option_name = "-$option_name"; | |||||||||||||||||||||||||||
| 704 | 5 | $color_severity = lc $args_value; | |||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||
| 706 | else { | ||||||||||||||||||||||||||||
| 707 | 1395 | $full_option_name = $option_name; | |||||||||||||||||||||||||||
| 708 | 1395 | $source = $self->_profile()->source(); | |||||||||||||||||||||||||||
| 709 | 1395 | $color_severity = lc $default_value; | |||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||
| 711 | 1400 | $color_severity =~ s/ \s+ / /xmsg; | |||||||||||||||||||||||||||
| 712 | 1400 | $color_severity =~ s/ \A\s+ //xms; | |||||||||||||||||||||||||||
| 713 | 1400 | $color_severity =~ s/ \s+\z //xms; | |||||||||||||||||||||||||||
| 714 | 1400 | $full_option_name =~ s/ _ /-/xmsg; | |||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||
| 716 | # Should we really be validating this? | ||||||||||||||||||||||||||||
| 717 | 1400 | my $found_errors; | |||||||||||||||||||||||||||
| 718 | 1400 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 719 | eval { | ||||||||||||||||||||||||||||
| 720 | 1400 | require Term::ANSIColor; | |||||||||||||||||||||||||||
| 721 | 1400 | Term::ANSIColor->VERSION( $_MODULE_VERSION_TERM_ANSICOLOR ); | |||||||||||||||||||||||||||
| 722 | 1400 | 1; | |||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||
| 724 | ) { | ||||||||||||||||||||||||||||
| 725 | 1400 | $found_errors = | |||||||||||||||||||||||||||
| 726 | not Term::ANSIColor::colorvalid( words_from_string($color_severity) ); | ||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | # If we do not have Term::ANSIColor we can not validate, but we store the | ||||||||||||||||||||||||||||
| 730 | # values anyway for the benefit of Perl::Critic::ProfilePrototype. | ||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | 1400 | ▶ | if ($found_errors) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 733 | 5 | $errors->add_exception( | |||||||||||||||||||||||||||
| 734 | $self->_new_global_value_exception( | ||||||||||||||||||||||||||||
| 735 | option_name => $full_option_name, | ||||||||||||||||||||||||||||
| 736 | option_value => $color_severity, | ||||||||||||||||||||||||||||
| 737 | source => $source, | ||||||||||||||||||||||||||||
| 738 | message_suffix => 'is not valid.', | ||||||||||||||||||||||||||||
| 739 | ) | ||||||||||||||||||||||||||||
| 740 | ); | ||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||
| 742 | else { | ||||||||||||||||||||||||||||
| 743 | 1395 | my $option_key = $option_name; | |||||||||||||||||||||||||||
| 744 | 1395 | $option_key =~ s/ - /_/xmsg; | |||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||
| 746 | 1395 | $self->{"_$option_key"} = $color_severity; | |||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||
| 749 | 1400 | return; | |||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||
| 752 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||
| 754 | 280 | ▶ | sub _validate_and_save_program_extensions { | ||||||||||||||||||||||||||
|
Subroutine
_validate_and_save_program_extensions: called CC=2 SCAR=7.3
| |||||||||||||||||||||||||||||
| 755 | 280 | my ($self, $args_value, $errors) = @_; | |||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||
| 757 | 280 | delete $self->{_program_extensions_as_regexes}; | |||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | my $extension_list = q{ARRAY} eq ref $args_value ? | ||||||||||||||||||||||||||||
| 760 | 0 | ▶ | [map {words_from_string($_)} @{ $args_value }] : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 761 | $self->_profile()->options_processor()->program_extensions(); | ||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | 280 | my %program_extensions = hashify( @{ $extension_list } ); | |||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||
| 765 | 280 | $self->{_program_extensions} = [keys %program_extensions]; | |||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||
| 767 | 280 | return; | |||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||
| 771 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 772 | # Begin ACCESSOR methods | ||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||
| 774 | 26103 | ▶ | sub _profile { | ||||||||||||||||||||||||||
|
Subroutine
_profile: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 775 | 26103 | my ($self) = @_; | |||||||||||||||||||||||||||
| 776 | 26103 | return $self->{_profile}; | |||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||
| 779 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||
| 781 | 2 | ▶ | sub all_policies_enabled_or_not { | ||||||||||||||||||||||||||
|
Subroutine
all_policies_enabled_or_not: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 782 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 783 | 2 | return @{ $self->{_all_policies_enabled_or_not} }; | |||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||
| 786 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | 206 | ▶ | sub policies { | ||||||||||||||||||||||||||
|
Subroutine
policies: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 789 | 206 | my ($self) = @_; | |||||||||||||||||||||||||||
| 790 | 206 | return @{ $self->{_policies} }; | |||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||
| 793 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||
| 795 | 11023 | ▶ | sub exclude { | ||||||||||||||||||||||||||
|
Subroutine
exclude: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 796 | 11023 | my ($self) = @_; | |||||||||||||||||||||||||||
| 797 | 11023 | return @{ $self->{_exclude} }; | |||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||
| 800 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||
| 802 | 93 | ▶ | sub force { | ||||||||||||||||||||||||||
|
Subroutine
force: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 803 | 93 | my ($self) = @_; | |||||||||||||||||||||||||||
| 804 | 93 | return $self->{_force}; | |||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||
| 807 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||
| 809 | 11023 | ▶ | sub include { | ||||||||||||||||||||||||||
|
Subroutine
include: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 810 | 11023 | my ($self) = @_; | |||||||||||||||||||||||||||
| 811 | 11023 | return @{ $self->{_include} }; | |||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||
| 814 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||
| 816 | 11027 | ▶ | sub only { | ||||||||||||||||||||||||||
|
Subroutine
only: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 817 | 11027 | my ($self) = @_; | |||||||||||||||||||||||||||
| 818 | 11027 | return $self->{_only}; | |||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||
| 821 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||
| 823 | 283 | ▶ | sub profile_strictness { | ||||||||||||||||||||||||||
|
Subroutine
profile_strictness: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 824 | 283 | my ($self) = @_; | |||||||||||||||||||||||||||
| 825 | 283 | return $self->{_profile_strictness}; | |||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||
| 828 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||
| 830 | 12 | ▶ | sub severity { | ||||||||||||||||||||||||||
|
Subroutine
severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 831 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||
| 832 | 12 | return $self->{_severity}; | |||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||
| 835 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | 12265 | ▶ | sub single_policy { | ||||||||||||||||||||||||||
|
Subroutine
single_policy: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 838 | 12265 | my ($self) = @_; | |||||||||||||||||||||||||||
| 839 | 12265 | return @{ $self->{_single_policy} }; | |||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||
| 842 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||
| 844 | 11026 | ▶ | sub theme { | ||||||||||||||||||||||||||
|
Subroutine
theme: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 845 | 11026 | my ($self) = @_; | |||||||||||||||||||||||||||
| 846 | 11026 | return $self->{_theme}; | |||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||
| 849 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||
| 851 | 71 | ▶ | sub top { | ||||||||||||||||||||||||||
|
Subroutine
top: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 852 | 71 | my ($self) = @_; | |||||||||||||||||||||||||||
| 853 | 71 | return $self->{_top}; | |||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||
| 856 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||
| 858 | 7 | ▶ | sub verbose { | ||||||||||||||||||||||||||
|
Subroutine
verbose: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 859 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 860 | 7 | return $self->{_verbose}; | |||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||
| 863 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||
| 865 | 6 | ▶ | sub color { | ||||||||||||||||||||||||||
|
Subroutine
color: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 866 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 867 | 6 | return $self->{_color}; | |||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||
| 870 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||
| 872 | 4 | ▶ | sub pager { | ||||||||||||||||||||||||||
|
Subroutine
pager: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 873 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 874 | 4 | return $self->{_pager}; | |||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||
| 877 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | 7 | ▶ | sub unsafe_allowed { | ||||||||||||||||||||||||||
|
Subroutine
unsafe_allowed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 880 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 881 | 7 | return $self->{_unsafe_allowed}; | |||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||
| 884 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||
| 886 | 3 | ▶ | sub criticism_fatal { | ||||||||||||||||||||||||||
|
Subroutine
criticism_fatal: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 887 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 888 | 3 | return $self->{_criticism_fatal}; | |||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||
| 891 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||
| 893 | 0 | ▶ | sub site_policy_names { | ||||||||||||||||||||||||||
|
Subroutine
site_policy_names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 894 | 0 | return Perl::Critic::PolicyFactory::site_policy_names(); | |||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||
| 897 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||
| 899 | 6 | ▶ | sub color_severity_highest { | ||||||||||||||||||||||||||
|
Subroutine
color_severity_highest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 900 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 901 | 6 | return $self->{_color_severity_highest}; | |||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||
| 904 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||
| 906 | 6 | ▶ | sub color_severity_high { | ||||||||||||||||||||||||||
|
Subroutine
color_severity_high: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 907 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 908 | 6 | return $self->{_color_severity_high}; | |||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||
| 911 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||
| 913 | 6 | ▶ | sub color_severity_medium { | ||||||||||||||||||||||||||
|
Subroutine
color_severity_medium: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 914 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 915 | 6 | return $self->{_color_severity_medium}; | |||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||
| 918 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||
| 920 | 6 | ▶ | sub color_severity_low { | ||||||||||||||||||||||||||
|
Subroutine
color_severity_low: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 921 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 922 | 6 | return $self->{_color_severity_low}; | |||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||
| 925 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||
| 927 | 6 | ▶ | sub color_severity_lowest { | ||||||||||||||||||||||||||
|
Subroutine
color_severity_lowest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 928 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 929 | 6 | return $self->{_color_severity_lowest}; | |||||||||||||||||||||||||||
| 930 | } | ||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||
| 932 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||
| 934 | 91 | ▶ | sub program_extensions { | ||||||||||||||||||||||||||
|
Subroutine
program_extensions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 935 | 91 | my ($self) = @_; | |||||||||||||||||||||||||||
| 936 | 91 | return @{ $self->{_program_extensions} }; | |||||||||||||||||||||||||||
| 937 | } | ||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||
| 939 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||
| 941 | 87 | ▶ | sub program_extensions_as_regexes { | ||||||||||||||||||||||||||
|
Subroutine
program_extensions_as_regexes: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 942 | 87 | my ($self) = @_; | |||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||
| 944 | 0 | return @{ $self->{_program_extensions_as_regexes} } | |||||||||||||||||||||||||||
| 945 | 87 | ▶ | if $self->{_program_extensions_as_regexes}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||
| 947 | 87 | my %program_extensions = hashify( $self->program_extensions() ); | |||||||||||||||||||||||||||
| 948 | 87 | $program_extensions{'.PL'} = 1; | |||||||||||||||||||||||||||
| 949 | return @{ | ||||||||||||||||||||||||||||
| 950 | 87 | $self->{_program_extensions_as_regexes} = [ | |||||||||||||||||||||||||||
| 951 | 87 | map { qr< @{[quotemeta $_]} \z >smx } sort keys %program_extensions | |||||||||||||||||||||||||||
| 952 | ] | ||||||||||||||||||||||||||||
| 953 | }; | ||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | 40 | 1; | |||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||
| 958 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||
| 960 | __END__ | ||||||||||||||||||||||||||||