« lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitQuotesAsQuotelikeOperatorDelimiters.pm
↑ Summary
lib/Perl/Critic/Exception/AggregateConfiguration.pm »
| 1 | package Perl::Critic::Policy; | ||||||||||||||||||||
| 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 File::Spec (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 40 | ▶ | use String::Format qw< stringf >; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 40 | ▶ | use overload ( q<""> => 'to_string', cmp => '_compare' ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 40 | ▶ | use Perl::Critic::Utils qw< | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | :characters | ||||||||||||||||||||
| 17 | :booleans | ||||||||||||||||||||
| 18 | :severities | ||||||||||||||||||||
| 19 | :data_conversion | ||||||||||||||||||||
| 20 | interpolate | ||||||||||||||||||||
| 21 | is_integer | ||||||||||||||||||||
| 22 | policy_long_name | ||||||||||||||||||||
| 23 | policy_short_name | ||||||||||||||||||||
| 24 | severity_to_number | ||||||||||||||||||||
| 25 | 40 | >; | |||||||||||||||||||
| 26 | 40 | ▶ | use Perl::Critic::Utils::POD qw< | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | get_module_abstract_for_module | ||||||||||||||||||||
| 28 | get_raw_module_abstract_for_module | ||||||||||||||||||||
| 29 | 40 | >; | |||||||||||||||||||
| 30 | 40 | ▶ | use Perl::Critic::Exception::AggregateConfiguration; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 40 | ▶ | use Perl::Critic::Exception::Configuration; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 40 | ▶ | use Perl::Critic::Exception::Configuration::Option::Policy::ExtraParameter; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 40 | ▶ | use Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | use Perl::Critic::Exception::Fatal::PolicyDefinition | ||||||||||||||||||||
| 35 | 40 | ▶ | qw< throw_policy_definition >; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 40 | ▶ | use Perl::Critic::PolicyConfig qw<>; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | 40 | ▶ | use Perl::Critic::PolicyParameter qw<>; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | 40 | ▶ | use Perl::Critic::Violation qw<>; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 40 | ▶ | use Exception::Class; # this must come after "use P::C::Exception::*" | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 40 | Readonly::Scalar my $NO_LIMIT => 'no_limit'; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 40 | my $format = '%p'; #Default stringy format | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 12979 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||
| 55 | 12979 | my ($class, %config) = @_; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 12979 | my $self = bless {}, $class; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 12979 | my $config_object; | |||||||||||||||||||
| 60 | 12979 | ▶ | if ($config{_config_object}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | $config_object = $config{_config_object}; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||
| 64 | 12979 | $config_object = | |||||||||||||||||||
| 65 | Perl::Critic::PolicyConfig->new( | ||||||||||||||||||||
| 66 | $self->get_short_name(), | ||||||||||||||||||||
| 67 | \%config, | ||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 12979 | $self->__set_config( $config_object ); | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 12979 | my @parameters; | |||||||||||||||||||
| 74 | 12979 | my $parameter_metadata_available = 0; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 12979 | ▶ | if ( $class->can('supported_parameters') ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 12919 | $parameter_metadata_available = 1; | |||||||||||||||||||
| 78 | @parameters = | ||||||||||||||||||||
| 79 | map | ||||||||||||||||||||
| 80 | 12919 | { Perl::Critic::PolicyParameter->new($_) } | |||||||||||||||||||
| 81 | $class->supported_parameters(); | ||||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | 12979 | $self->{_parameter_metadata_available} = $parameter_metadata_available; | |||||||||||||||||||
| 84 | 12979 | $self->{_parameters} = \@parameters; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 12979 | my $errors = Perl::Critic::Exception::AggregateConfiguration->new(); | |||||||||||||||||||
| 87 | 12979 | foreach my $parameter ( @parameters ) { | |||||||||||||||||||
| 88 | eval { | ||||||||||||||||||||
| 89 | 9709 | $parameter->parse_and_validate_config_value( $self, $config_object ); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | 9709 | ▶ | or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | 9709 | $errors->add_exception_or_rethrow($EVAL_ERROR); | |||||||||||||||||||
| 93 | }; | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 9709 | $config_object->remove( $parameter->get_name() ); | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 12979 | ▶ | if ($parameter_metadata_available) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | 12919 | $config_object->handle_extra_parameters( $self, $errors ); | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 12979 | ▶ | if ( $errors->has_exceptions() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | 146 | $errors->rethrow(); | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 12833 | return $self; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 11164 | ▶ | sub is_safe { | ||||||||||||||||||
|
Subroutine
is_safe: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 112 | 11164 | return $TRUE; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 7325 | ▶ | sub initialize_if_enabled { | ||||||||||||||||||
|
Subroutine
initialize_if_enabled: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 118 | 7325 | return $TRUE; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 4261 | ▶ | sub prepare_to_scan_document { | ||||||||||||||||||
|
Subroutine
prepare_to_scan_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 124 | 4261 | return $TRUE; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 8947 | ▶ | sub __get_parameter_name { | ||||||||||||||||||
|
Subroutine
__get_parameter_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 130 | 8947 | my ( $self, $parameter ) = @_; | |||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 8947 | return '_' . $parameter->get_name(); | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 8848 | ▶ | sub __set_parameter_value { | ||||||||||||||||||
|
Subroutine
__set_parameter_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 138 | 8848 | my ( $self, $parameter, $value ) = @_; | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 8848 | $self->{ $self->__get_parameter_name($parameter) } = $value; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 8848 | return; | |||||||||||||||||||
| 143 | } | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 12627 | ▶ | sub __set_base_parameters { | ||||||||||||||||||
|
Subroutine
__set_base_parameters: called CC=5 SCAR=16.1
| |||||||||||||||||||||
| 148 | 12627 | my ($self) = @_; | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 12627 | my $config = $self->__get_config(); | |||||||||||||||||||
| 151 | 12627 | my $errors = Perl::Critic::Exception::AggregateConfiguration->new(); | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 12627 | $self->_set_maximum_violations_per_document($errors); | |||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 12627 | my $user_severity = $config->get_severity(); | |||||||||||||||||||
| 156 | 12627 | ▶ | if ( defined $user_severity ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | 866 | my $normalized_severity = severity_to_number( $user_severity ); | |||||||||||||||||||
| 158 | 865 | $self->set_severity( $normalized_severity ); | |||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 12626 | my $user_set_themes = $config->get_set_themes(); | |||||||||||||||||||
| 162 | 12626 | ▶ | if ( defined $user_set_themes ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 163 | 145 | my @set_themes = words_from_string( $user_set_themes ); | |||||||||||||||||||
| 164 | 145 | $self->set_themes( @set_themes ); | |||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | 12626 | my $user_add_themes = $config->get_add_themes(); | |||||||||||||||||||
| 168 | 12626 | ▶ | if ( defined $user_add_themes ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 169 | 147 | my @add_themes = words_from_string( $user_add_themes ); | |||||||||||||||||||
| 170 | 147 | $self->add_themes( @add_themes ); | |||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 12626 | ▶ | if ( $errors->has_exceptions() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | 0 | $errors->rethrow(); | |||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | 12626 | return; | |||||||||||||||||||
| 178 | } | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | 12627 | ▶ | sub _set_maximum_violations_per_document { | ||||||||||||||||||
|
Subroutine
_set_maximum_violations_per_document: called CC=4 SCAR=15.2
| |||||||||||||||||||||
| 183 | 12627 | my ($self, $errors) = @_; | |||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 12627 | my $config = $self->__get_config(); | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 12627 | ▶ | if ( $config->is_maximum_violations_per_document_unlimited() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 188 | 12623 | return; | |||||||||||||||||||
| 189 | } | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 4 | my $user_maximum_violations = | |||||||||||||||||||
| 192 | $config->get_maximum_violations_per_document(); | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 4 | ▶ | if ( not is_integer($user_maximum_violations) ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 195 | 0 | $errors->add_exception( | |||||||||||||||||||
| 196 | new_parameter_value_exception( | ||||||||||||||||||||
| 197 | 'maximum_violations_per_document', | ||||||||||||||||||||
| 198 | $user_maximum_violations, | ||||||||||||||||||||
| 199 | undef, | ||||||||||||||||||||
| 200 | "does not look like an integer.\n" | ||||||||||||||||||||
| 201 | ) | ||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 0 | return; | |||||||||||||||||||
| 205 | } | ||||||||||||||||||||
| 206 | elsif ( $user_maximum_violations < 0 ) { | ||||||||||||||||||||
| 207 | 0 | $errors->add_exception( | |||||||||||||||||||
| 208 | new_parameter_value_exception( | ||||||||||||||||||||
| 209 | 'maximum_violations_per_document', | ||||||||||||||||||||
| 210 | $user_maximum_violations, | ||||||||||||||||||||
| 211 | undef, | ||||||||||||||||||||
| 212 | "is not greater than or equal to zero.\n" | ||||||||||||||||||||
| 213 | ) | ||||||||||||||||||||
| 214 | ); | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | 0 | return; | |||||||||||||||||||
| 217 | } | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | $self->set_maximum_violations_per_document( | ||||||||||||||||||||
| 220 | 4 | $user_maximum_violations | |||||||||||||||||||
| 221 | ); | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | 4 | return; | |||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | # Unparsed configuration, P::C::PolicyConfig. Compare with get_parameters(). | ||||||||||||||||||||
| 229 | 33296 | ▶ | sub __get_config { | ||||||||||||||||||
|
Subroutine
__get_config: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 230 | 33296 | my ($self) = @_; | |||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | 33296 | return $self->{_config}; | |||||||||||||||||||
| 233 | } | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | 25606 | ▶ | sub __set_config { | ||||||||||||||||||
|
Subroutine
__set_config: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 236 | 25606 | my ($self, $config) = @_; | |||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | 25606 | $self->{_config} = $config; | |||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | 25606 | return; | |||||||||||||||||||
| 241 | } | ||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | 0 | ▶ | sub get_long_name { | ||||||||||||||||||
|
Subroutine
get_long_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 246 | 0 | my ($self) = @_; | |||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | 0 | return policy_long_name(ref $self); | |||||||||||||||||||
| 249 | } | ||||||||||||||||||||
| 250 | |||||||||||||||||||||
| 251 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | 61416 | ▶ | sub get_short_name { | ||||||||||||||||||
|
Subroutine
get_short_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 254 | 61416 | my ($self) = @_; | |||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | 61416 | return policy_short_name(ref $self); | |||||||||||||||||||
| 257 | } | ||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | 147 | ▶ | sub is_enabled { | ||||||||||||||||||
|
Subroutine
is_enabled: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 262 | 147 | my ($self) = @_; | |||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | 147 | return $self->{_enabled}; | |||||||||||||||||||
| 265 | } | ||||||||||||||||||||
| 266 | |||||||||||||||||||||
| 267 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | 8042 | ▶ | sub __set_enabled { | ||||||||||||||||||
|
Subroutine
__set_enabled: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 270 | 8042 | my ($self, $new_value) = @_; | |||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | 8042 | $self->{_enabled} = $new_value; | |||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | 8042 | return; | |||||||||||||||||||
| 275 | } | ||||||||||||||||||||
| 276 | |||||||||||||||||||||
| 277 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 278 | |||||||||||||||||||||
| 279 | 1 | ▶ | sub applies_to { | ||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 280 | 1 | return qw(PPI::Element); | |||||||||||||||||||
| 281 | } | ||||||||||||||||||||
| 282 | |||||||||||||||||||||
| 283 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 284 | |||||||||||||||||||||
| 285 | 6 | ▶ | sub set_maximum_violations_per_document { | ||||||||||||||||||
|
Subroutine
set_maximum_violations_per_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 286 | 6 | my ($self, $maximum_violations_per_document) = @_; | |||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | $self->{_maximum_violations_per_document} = | ||||||||||||||||||||
| 289 | 6 | $maximum_violations_per_document; | |||||||||||||||||||
| 290 | |||||||||||||||||||||
| 291 | 6 | return $self; | |||||||||||||||||||
| 292 | } | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 295 | |||||||||||||||||||||
| 296 | 5503 | ▶ | sub get_maximum_violations_per_document { | ||||||||||||||||||
|
Subroutine
get_maximum_violations_per_document: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 297 | 5503 | my ($self) = @_; | |||||||||||||||||||
| 298 | |||||||||||||||||||||
| 299 | return | ||||||||||||||||||||
| 300 | exists $self->{_maximum_violations_per_document} | ||||||||||||||||||||
| 301 | ? $self->{_maximum_violations_per_document} | ||||||||||||||||||||
| 302 | 5503 | ▶ | : $self->default_maximum_violations_per_document(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 303 | } | ||||||||||||||||||||
| 304 | |||||||||||||||||||||
| 305 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 306 | |||||||||||||||||||||
| 307 | 5370 | ▶ | sub default_maximum_violations_per_document { | ||||||||||||||||||
|
Subroutine
default_maximum_violations_per_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 308 | 5370 | return; | |||||||||||||||||||
| 309 | } | ||||||||||||||||||||
| 310 | |||||||||||||||||||||
| 311 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 312 | |||||||||||||||||||||
| 313 | 866 | ▶ | sub set_severity { | ||||||||||||||||||
|
Subroutine
set_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 314 | 866 | my ($self, $severity) = @_; | |||||||||||||||||||
| 315 | 866 | $self->{_severity} = $severity; | |||||||||||||||||||
| 316 | 866 | return $self; | |||||||||||||||||||
| 317 | } | ||||||||||||||||||||
| 318 | |||||||||||||||||||||
| 319 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 320 | |||||||||||||||||||||
| 321 | 12455 | ▶ | sub get_severity { | ||||||||||||||||||
|
Subroutine
get_severity: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 322 | 12455 | my ($self) = @_; | |||||||||||||||||||
| 323 | 12455 | ▶ | return $self->{_severity} || $self->default_severity(); | ||||||||||||||||||
|
Condition66%2/3
$self->{'_severity'} || $self->default_severity
MC/DC0%0/2
$self->{'_severity'} || $self->default_severity
$self->{'_severity'}
$self->default_severity
Truth table66%2/3
A || B
A= $self->{'_severity'}B= $self->default_severity
| |||||||||||||||||||||
| 324 | } | ||||||||||||||||||||
| 325 | |||||||||||||||||||||
| 326 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 327 | |||||||||||||||||||||
| 328 | 3 | ▶ | sub default_severity { | ||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 329 | 3 | return $SEVERITY_LOWEST; | |||||||||||||||||||
| 330 | } | ||||||||||||||||||||
| 331 | |||||||||||||||||||||
| 332 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 333 | |||||||||||||||||||||
| 334 | 146 | ▶ | sub set_themes { | ||||||||||||||||||
|
Subroutine
set_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 335 | 146 | my ($self, @themes) = @_; | |||||||||||||||||||
| 336 | 146 | $self->{_themes} = [ sort @themes ]; | |||||||||||||||||||
| 337 | 146 | return $self; | |||||||||||||||||||
| 338 | } | ||||||||||||||||||||
| 339 | |||||||||||||||||||||
| 340 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 341 | |||||||||||||||||||||
| 342 | 12730 | ▶ | sub get_themes { | ||||||||||||||||||
|
Subroutine
get_themes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 343 | 12730 | my ($self) = @_; | |||||||||||||||||||
| 344 | 12730 | ▶ | my @themes = defined $self->{_themes} ? @{ $self->{_themes} } : $self->default_themes(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 345 | 12730 | my @sorted_themes = sort @themes; | |||||||||||||||||||
| 346 | 12730 | return @sorted_themes; | |||||||||||||||||||
| 347 | } | ||||||||||||||||||||
| 348 | |||||||||||||||||||||
| 349 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 350 | |||||||||||||||||||||
| 351 | 148 | ▶ | sub add_themes { | ||||||||||||||||||
|
Subroutine
add_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 352 | 148 | my ($self, @additional_themes) = @_; | |||||||||||||||||||
| 353 | #By hashifying the themes, we squish duplicates | ||||||||||||||||||||
| 354 | 148 | my %merged = hashify( $self->get_themes(), @additional_themes); | |||||||||||||||||||
| 355 | 148 | $self->{_themes} = [ keys %merged]; | |||||||||||||||||||
| 356 | 148 | return $self; | |||||||||||||||||||
| 357 | } | ||||||||||||||||||||
| 358 | |||||||||||||||||||||
| 359 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 360 | |||||||||||||||||||||
| 361 | 4 | ▶ | sub default_themes { | ||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 362 | 4 | return (); | |||||||||||||||||||
| 363 | } | ||||||||||||||||||||
| 364 | |||||||||||||||||||||
| 365 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 366 | |||||||||||||||||||||
| 367 | 723 | ▶ | sub get_abstract { | ||||||||||||||||||
|
Subroutine
get_abstract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 368 | 723 | my ($self) = @_; | |||||||||||||||||||
| 369 | |||||||||||||||||||||
| 370 | 723 | return get_module_abstract_for_module( ref $self ); | |||||||||||||||||||
| 371 | } | ||||||||||||||||||||
| 372 | |||||||||||||||||||||
| 373 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 374 | |||||||||||||||||||||
| 375 | 0 | ▶ | sub get_raw_abstract { | ||||||||||||||||||
|
Subroutine
get_raw_abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 376 | 0 | my ($self) = @_; | |||||||||||||||||||
| 377 | |||||||||||||||||||||
| 378 | 0 | return get_raw_module_abstract_for_module( ref $self ); | |||||||||||||||||||
| 379 | } | ||||||||||||||||||||
| 380 | |||||||||||||||||||||
| 381 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 382 | |||||||||||||||||||||
| 383 | 1732 | ▶ | sub parameter_metadata_available { | ||||||||||||||||||
|
Subroutine
parameter_metadata_available: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 384 | 1732 | my ($self) = @_; | |||||||||||||||||||
| 385 | |||||||||||||||||||||
| 386 | 1732 | return $self->{_parameter_metadata_available}; | |||||||||||||||||||
| 387 | } | ||||||||||||||||||||
| 388 | |||||||||||||||||||||
| 389 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 390 | |||||||||||||||||||||
| 391 | 1007 | ▶ | sub get_parameters { | ||||||||||||||||||
|
Subroutine
get_parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 392 | 1007 | my ($self) = @_; | |||||||||||||||||||
| 393 | |||||||||||||||||||||
| 394 | 1007 | return $self->{_parameters}; | |||||||||||||||||||
| 395 | } | ||||||||||||||||||||
| 396 | |||||||||||||||||||||
| 397 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 398 | |||||||||||||||||||||
| 399 | 1 | ▶ | sub violates { | ||||||||||||||||||
|
Subroutine
violates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 400 | 1 | my ($self) = @_; | |||||||||||||||||||
| 401 | |||||||||||||||||||||
| 402 | 1 | return throw_policy_definition | |||||||||||||||||||
| 403 | $self->get_short_name() . q/ does not implement violates()./; | ||||||||||||||||||||
| 404 | } | ||||||||||||||||||||
| 405 | |||||||||||||||||||||
| 406 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 407 | |||||||||||||||||||||
| 408 | 277 | ▶ | sub violation { ## no critic (ArgUnpacking) | ||||||||||||||||||
|
Subroutine
violation: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 409 | 277 | my ( $self, $desc, $expl, $elem ) = @_; | |||||||||||||||||||
| 410 | # HACK!! Use goto instead of an explicit call because P::C::V::new() uses caller() | ||||||||||||||||||||
| 411 | 277 | my $sev = $self->get_severity(); | |||||||||||||||||||
| 412 | 277 | @_ = ('Perl::Critic::Violation', $desc, $expl, $elem, $sev ); | |||||||||||||||||||
| 413 | 277 | goto &Perl::Critic::Violation::new; | |||||||||||||||||||
| 414 | } | ||||||||||||||||||||
| 415 | |||||||||||||||||||||
| 416 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 417 | |||||||||||||||||||||
| 418 | 8 | ▶ | sub new_parameter_value_exception { | ||||||||||||||||||
|
Subroutine
new_parameter_value_exception: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 419 | 8 | my ( $self, $option_name, $option_value, $source, $message_suffix ) = @_; | |||||||||||||||||||
| 420 | |||||||||||||||||||||
| 421 | 8 | return Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue->new( | |||||||||||||||||||
| 422 | policy => $self->get_short_name(), | ||||||||||||||||||||
| 423 | option_name => $option_name, | ||||||||||||||||||||
| 424 | option_value => $option_value, | ||||||||||||||||||||
| 425 | source => $source, | ||||||||||||||||||||
| 426 | message_suffix => $message_suffix | ||||||||||||||||||||
| 427 | ); | ||||||||||||||||||||
| 428 | } | ||||||||||||||||||||
| 429 | |||||||||||||||||||||
| 430 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 431 | |||||||||||||||||||||
| 432 | ## no critic (Subroutines::RequireFinalReturn) | ||||||||||||||||||||
| 433 | 8 | ▶ | sub throw_parameter_value_exception { | ||||||||||||||||||
|
Subroutine
throw_parameter_value_exception: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 434 | 8 | my ( $self, $option_name, $option_value, $source, $message_suffix ) = @_; | |||||||||||||||||||
| 435 | |||||||||||||||||||||
| 436 | 8 | $self->new_parameter_value_exception( | |||||||||||||||||||
| 437 | $option_name, $option_value, $source, $message_suffix | ||||||||||||||||||||
| 438 | ) | ||||||||||||||||||||
| 439 | ->throw(); | ||||||||||||||||||||
| 440 | } | ||||||||||||||||||||
| 441 | ## use critic | ||||||||||||||||||||
| 442 | |||||||||||||||||||||
| 443 | |||||||||||||||||||||
| 444 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 445 | |||||||||||||||||||||
| 446 | # Static methods. | ||||||||||||||||||||
| 447 | |||||||||||||||||||||
| 448 | 3 | ▶ | sub set_format { return $format = $_[0] } ## no critic(ArgUnpacking) | ||||||||||||||||||
|
Subroutine
set_format: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 449 | 47038 | ▶ | sub get_format { return $format } | ||||||||||||||||||
|
Subroutine
get_format: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 450 | |||||||||||||||||||||
| 451 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 452 | |||||||||||||||||||||
| 453 | 47036 | ▶ | sub to_string { | ||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.8
Pod
documented
| |||||||||||||||||||||
| 454 | 47036 | my ($self, @args) = @_; | |||||||||||||||||||
| 455 | |||||||||||||||||||||
| 456 | # Wrap the more expensive ones in sub{} to postpone evaluation | ||||||||||||||||||||
| 457 | my %fspec = ( | ||||||||||||||||||||
| 458 | 0 | ▶ | 'P' => sub { $self->get_long_name() }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 459 | 47036 | ▶ | 'p' => sub { $self->get_short_name() }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 460 | 723 | ▶ | 'a' => sub { $self->get_abstract() // $EMPTY }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
Condition33%1/3
$self->get_abstract // $Perl::Critic::Policy::EMPTY
MC/DC0%0/2
$self->get_abstract // $Perl::Critic::Policy::EMPTY
$self->get_abstract
$Perl::Critic::Policy::EMPTY
Truth table33%1/3
A // B
A= $self->get_abstractB= $Perl::Critic::Policy::EMPTY
| |||||||||||||||||||||
| 461 | 723 | ▶ | 'O' => sub { $self->_format_parameters(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 462 | 723 | ▶ | 'U' => sub { $self->_format_lack_of_parameter_metadata(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 463 | 0 | ▶ | 'S' => sub { $self->default_severity() }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 464 | 870 | ▶ | 's' => sub { $self->get_severity() }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 465 | 0 | ▶ | 'T' => sub { join $SPACE, $self->default_themes() }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 466 | 870 | ▶ | 't' => sub { join $SPACE, $self->get_themes() }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 467 | 0 | ▶ | 'V' => sub { $self->default_maximum_violations_per_document() // $NO_LIMIT }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$self->default_maximum_violations_per_document // $NO_LIMIT
MC/DC0%0/2
$self->default_maximum_violations_per_document // $NO_LIMIT
$self->default_maximum_violations_per_document
$NO_LIMIT
Truth table0%0/3
A // B
A= $self->default_maximum_violations_per_documentB= $NO_LIMIT
| |||||||||||||||||||||
| 468 | 723 | ▶ | 'v' => sub { $self->get_maximum_violations_per_document() // $NO_LIMIT }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Condition66%2/3
$self->get_maximum_violations_per_document // $NO_LIMIT
MC/DC0%0/2
$self->get_maximum_violations_per_document // $NO_LIMIT
$self->get_maximum_violations_per_document
$NO_LIMIT
Truth table66%2/3
A // B
A= $self->get_maximum_violations_per_documentB= $NO_LIMIT
| |||||||||||||||||||||
| 469 | 47036 | ); | |||||||||||||||||||
| 470 | 47036 | return stringf(get_format(), %fspec); | |||||||||||||||||||
| 471 | } | ||||||||||||||||||||
| 472 | |||||||||||||||||||||
| 473 | 723 | ▶ | sub _format_parameters { | ||||||||||||||||||
|
Subroutine
_format_parameters: called CC=3 SCAR=11.7
| |||||||||||||||||||||
| 474 | 723 | my ($self, $parameter_format) = @_; | |||||||||||||||||||
| 475 | |||||||||||||||||||||
| 476 | 723 | ▶ | return $EMPTY if not $self->parameter_metadata_available(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 477 | |||||||||||||||||||||
| 478 | 723 | my $separator; | |||||||||||||||||||
| 479 | 723 | ▶ | if ($parameter_format) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 480 | 723 | $separator = $EMPTY; | |||||||||||||||||||
| 481 | } else { | ||||||||||||||||||||
| 482 | 0 | $separator = $SPACE; | |||||||||||||||||||
| 483 | 0 | $parameter_format = '%n'; | |||||||||||||||||||
| 484 | } | ||||||||||||||||||||
| 485 | |||||||||||||||||||||
| 486 | return | ||||||||||||||||||||
| 487 | join | ||||||||||||||||||||
| 488 | $separator, | ||||||||||||||||||||
| 489 | 723 | map { $_->to_formatted_string($parameter_format) } @{ $self->get_parameters() }; | |||||||||||||||||||
| 490 | } | ||||||||||||||||||||
| 491 | |||||||||||||||||||||
| 492 | 723 | ▶ | sub _format_lack_of_parameter_metadata { | ||||||||||||||||||
|
Subroutine
_format_lack_of_parameter_metadata: called CC=3 SCAR=16.5
| |||||||||||||||||||||
| 493 | 723 | my ($self, $message) = @_; | |||||||||||||||||||
| 494 | |||||||||||||||||||||
| 495 | 723 | ▶ | return $EMPTY if $self->parameter_metadata_available(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 496 | 0 | ▶ | return interpolate($message) if $message; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 497 | |||||||||||||||||||||
| 498 | return | ||||||||||||||||||||
| 499 | 0 | 'Cannot programmatically discover what parameters this policy takes.'; | |||||||||||||||||||
| 500 | } | ||||||||||||||||||||
| 501 | |||||||||||||||||||||
| 502 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 503 | # Apparently, some perls do not implicitly stringify overloading | ||||||||||||||||||||
| 504 | # objects before doing a comparison. This causes a couple of our | ||||||||||||||||||||
| 505 | # sorting tests to fail. To work around this, we overload C<cmp> to | ||||||||||||||||||||
| 506 | # do it explicitly. | ||||||||||||||||||||
| 507 | # | ||||||||||||||||||||
| 508 | # 20060503 - More information: This problem has been traced to | ||||||||||||||||||||
| 509 | # Test::Simple versions <= 0.60, not perl itself. Upgrading to | ||||||||||||||||||||
| 510 | # Test::Simple v0.62 will fix the problem. But rather than forcing | ||||||||||||||||||||
| 511 | # everyone to upgrade, I have decided to leave this workaround in | ||||||||||||||||||||
| 512 | # place. | ||||||||||||||||||||
| 513 | |||||||||||||||||||||
| 514 | 142 | ▶ | sub _compare { return "$_[0]" cmp "$_[1]" } | ||||||||||||||||||
|
Subroutine
_compare: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 515 | |||||||||||||||||||||
| 516 | 40 | 1; | |||||||||||||||||||
| 517 | |||||||||||||||||||||
| 518 | __END__ | ||||||||||||||||||||