« blib/lib/Perl/Critic/Policy/InputOutput/ProhibitReadlineInForLoop.pm
↑ Summary
blib/lib/Perl/Critic/PolicyParameter/Behavior/Boolean.pm »
| 1 | package Perl::Critic::ProfilePrototype; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 2 | ▶ | use Perl::Critic::Config qw{}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use Perl::Critic::Policy qw{}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 2 | ▶ | use Perl::Critic::Utils qw{ :characters }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 2 | ▶ | use overload ( q{""} => 'to_string' ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 2 | our $VERSION = '1.150'; | |||||||||||
| 13 | |||||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||||
| 15 | |||||||||||||
| 16 | sub new { | ||||||||||||
| 17 | 2 | ▶ | my ($class, %args) = @_; | ||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 18 | 2 | my $self = bless {}, $class; | |||||||||||
| 19 | |||||||||||||
| 20 | 2 | ▶ | my $policies = $args{-policies} || []; | ||||||||||
|
Condition100%2/2
$args{'-policies'} || []
MC/DC100%1/1
$args{'-policies'} || []
$args{'-policies'}
Truth table100%2/2
A
A= $args{'-policies'}
| |||||||||||||
| 21 | 2 | $self->{_policies} = [ sort _by_type @{ $policies } ]; | |||||||||||
| 22 | |||||||||||||
| 23 | 2 | ▶ | $self->{_comment_out_parameters} = $args{'-comment-out-parameters'} // 1; | ||||||||||
|
Condition100%2/2
$args{"-comment-out-parameters"} // 1
MC/DC100%1/1
$args{"-comment-out-parameters"} // 1
$args{"-comment-out-parameters"}
Truth table100%2/2
A
A= $args{"-comment-out-parameters"}
| |||||||||||||
| 24 | |||||||||||||
| 25 | 2 | my $configuration = $args{'-config'}; | |||||||||||
| 26 | 2 | ▶ | if (not $configuration) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 1 | $configuration = Perl::Critic::Config->new(-profile => $EMPTY); | |||||||||||
| 28 | } | ||||||||||||
| 29 | 2 | $self->{_configuration} = $configuration; | |||||||||||
| 30 | |||||||||||||
| 31 | |||||||||||||
| 32 | 2 | return $self; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | #----------------------------------------------------------------------------- | ||||||||||||
| 36 | |||||||||||||
| 37 | sub _get_policies { | ||||||||||||
| 38 | 1 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
_get_policies: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | |||||||||||||
| 40 | 1 | return $self->{_policies}; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | sub _comment_out_parameters { | ||||||||||||
| 44 | 2 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
_comment_out_parameters: called CC=1 SCAR=0.0
| |||||||||||||
| 45 | |||||||||||||
| 46 | 2 | return $self->{_comment_out_parameters}; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | sub _configuration { | ||||||||||||
| 50 | 1 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
_configuration: called CC=1 SCAR=0.0
| |||||||||||||
| 51 | |||||||||||||
| 52 | 1 | return $self->{_configuration}; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | #----------------------------------------------------------------------------- | ||||||||||||
| 56 | |||||||||||||
| 57 | sub _line_prefix { | ||||||||||||
| 58 | 2 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
_line_prefix: called CC=2 SCAR=7.2
| |||||||||||||
| 59 | |||||||||||||
| 60 | 2 | ▶ | return $self->_comment_out_parameters() ? q{# } : $EMPTY; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | #----------------------------------------------------------------------------- | ||||||||||||
| 64 | |||||||||||||
| 65 | sub to_string { | ||||||||||||
| 66 | 1 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
to_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 67 | |||||||||||||
| 68 | 1 | my $prefix = $self->_line_prefix(); | |||||||||||
| 69 | 1 | my $configuration = $self->_configuration(); | |||||||||||
| 70 | |||||||||||||
| 71 | 1 | my $prototype = "# Globals\n"; | |||||||||||
| 72 | |||||||||||||
| 73 | 1 | $prototype .= $prefix; | |||||||||||
| 74 | 1 | $prototype .= q{severity = }; | |||||||||||
| 75 | 1 | $prototype .= $configuration->severity(); | |||||||||||
| 76 | 1 | $prototype .= "\n"; | |||||||||||
| 77 | |||||||||||||
| 78 | 1 | $prototype .= $prefix; | |||||||||||
| 79 | 1 | $prototype .= q{force = }; | |||||||||||
| 80 | 1 | $prototype .= $configuration->force(); | |||||||||||
| 81 | 1 | $prototype .= "\n"; | |||||||||||
| 82 | |||||||||||||
| 83 | 1 | $prototype .= $prefix; | |||||||||||
| 84 | 1 | $prototype .= q{only = }; | |||||||||||
| 85 | 1 | $prototype .= $configuration->only(); | |||||||||||
| 86 | 1 | $prototype .= "\n"; | |||||||||||
| 87 | |||||||||||||
| 88 | 1 | $prototype .= $prefix; | |||||||||||
| 89 | 1 | $prototype .= q{allow-unsafe = }; | |||||||||||
| 90 | 1 | $prototype .= $configuration->unsafe_allowed(); | |||||||||||
| 91 | 1 | $prototype .= "\n"; | |||||||||||
| 92 | |||||||||||||
| 93 | 1 | $prototype .= $prefix; | |||||||||||
| 94 | 1 | $prototype .= q{profile-strictness = }; | |||||||||||
| 95 | 1 | $prototype .= $configuration->profile_strictness(); | |||||||||||
| 96 | 1 | $prototype .= "\n"; | |||||||||||
| 97 | |||||||||||||
| 98 | 1 | $prototype .= $prefix; | |||||||||||
| 99 | 1 | $prototype .= q{color = }; | |||||||||||
| 100 | 1 | $prototype .= $configuration->color(); | |||||||||||
| 101 | 1 | $prototype .= "\n"; | |||||||||||
| 102 | |||||||||||||
| 103 | 1 | $prototype .= $prefix; | |||||||||||
| 104 | 1 | $prototype .= q{pager = }; | |||||||||||
| 105 | 1 | $prototype .= $configuration->pager(); | |||||||||||
| 106 | 1 | $prototype .= "\n"; | |||||||||||
| 107 | |||||||||||||
| 108 | 1 | $prototype .= $prefix; | |||||||||||
| 109 | 1 | $prototype .= q{top = }; | |||||||||||
| 110 | 1 | $prototype .= $configuration->top(); | |||||||||||
| 111 | 1 | $prototype .= "\n"; | |||||||||||
| 112 | |||||||||||||
| 113 | 1 | $prototype .= $prefix; | |||||||||||
| 114 | 1 | $prototype .= q{verbose = }; | |||||||||||
| 115 | 1 | $prototype .= $configuration->verbose(); | |||||||||||
| 116 | 1 | $prototype .= "\n"; | |||||||||||
| 117 | |||||||||||||
| 118 | 1 | $prototype .= $prefix; | |||||||||||
| 119 | 1 | $prototype .= q{include = }; | |||||||||||
| 120 | 1 | $prototype .= join $SPACE, $configuration->include(); | |||||||||||
| 121 | 1 | $prototype .= "\n"; | |||||||||||
| 122 | |||||||||||||
| 123 | 1 | $prototype .= $prefix; | |||||||||||
| 124 | 1 | $prototype .= q{exclude = }; | |||||||||||
| 125 | 1 | $prototype .= join $SPACE, $configuration->exclude(); | |||||||||||
| 126 | 1 | $prototype .= "\n"; | |||||||||||
| 127 | |||||||||||||
| 128 | 1 | $prototype .= $prefix; | |||||||||||
| 129 | 1 | $prototype .= q{single-policy = }; | |||||||||||
| 130 | 1 | $prototype .= join $SPACE, $configuration->single_policy(); | |||||||||||
| 131 | 1 | $prototype .= "\n"; | |||||||||||
| 132 | |||||||||||||
| 133 | 1 | $prototype .= $prefix; | |||||||||||
| 134 | 1 | $prototype .= q{theme = }; | |||||||||||
| 135 | 1 | $prototype .= $configuration->theme()->rule(); | |||||||||||
| 136 | 1 | $prototype .= "\n"; | |||||||||||
| 137 | |||||||||||||
| 138 | 1 | foreach my $item (qw< | |||||||||||
| 139 | color-severity-highest | ||||||||||||
| 140 | color-severity-high | ||||||||||||
| 141 | color-severity-medium | ||||||||||||
| 142 | color-severity-low | ||||||||||||
| 143 | color-severity-lowest | ||||||||||||
| 144 | >) { | ||||||||||||
| 145 | 5 | ( my $accessor = $item ) =~ s/ - /_/gmsx; | |||||||||||
| 146 | 5 | $prototype .= $prefix; | |||||||||||
| 147 | 5 | $prototype .= "$item = "; | |||||||||||
| 148 | 5 | $prototype .= $configuration->$accessor; | |||||||||||
| 149 | 5 | $prototype .= "\n"; | |||||||||||
| 150 | } | ||||||||||||
| 151 | |||||||||||||
| 152 | 1 | $prototype .= $prefix; | |||||||||||
| 153 | 1 | $prototype .= q{program-extensions = }; | |||||||||||
| 154 | 1 | $prototype .= join $SPACE, $configuration->program_extensions(); | |||||||||||
| 155 | |||||||||||||
| 156 | 1 | Perl::Critic::Policy::set_format( $self->_proto_format() ); | |||||||||||
| 157 | |||||||||||||
| 158 | 1 | my $policy_prototypes = join qq{\n}, map { "$_" } @{ $self->_get_policies() }; | |||||||||||
| 159 | 1 | $policy_prototypes =~ s/\s+ \z//xms; # Trim trailing whitespace | |||||||||||
| 160 | 1 | return $prototype . "\n\n" . $policy_prototypes . "\n"; | |||||||||||
| 161 | } | ||||||||||||
| 162 | |||||||||||||
| 163 | #----------------------------------------------------------------------------- | ||||||||||||
| 164 | |||||||||||||
| 165 | # About "%{\\n%\\x7b# \\x7df\n${prefix}%n = %D\\n}O" below: | ||||||||||||
| 166 | # | ||||||||||||
| 167 | # The %0 format for a policy specifies how to format parameters. | ||||||||||||
| 168 | # For a parameter %f specifies the full description. | ||||||||||||
| 169 | # | ||||||||||||
| 170 | # The problem is that both of these need to take options, but String::Format | ||||||||||||
| 171 | # doesn't allow nesting of {}. So, to get the option to the %f, the braces | ||||||||||||
| 172 | # are hex encoded. I.e., assuming that comment_out_parameters is in effect, | ||||||||||||
| 173 | # the parameter sees: | ||||||||||||
| 174 | # | ||||||||||||
| 175 | # \n%{# }f\n# %n = %D\n | ||||||||||||
| 176 | |||||||||||||
| 177 | sub _proto_format { | ||||||||||||
| 178 | 1 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
_proto_format: called CC=1 SCAR=0.0
| |||||||||||||
| 179 | |||||||||||||
| 180 | 1 | my $prefix = $self->_line_prefix(); | |||||||||||
| 181 | |||||||||||||
| 182 | 1 | return <<"END_OF_FORMAT"; | |||||||||||
| 183 | # %a | ||||||||||||
| 184 | [%p] | ||||||||||||
| 185 | ${prefix}set_themes = %t | ||||||||||||
| 186 | ${prefix}add_themes = | ||||||||||||
| 187 | ${prefix}severity = %s | ||||||||||||
| 188 | ${prefix}maximum_violations_per_document = %v | ||||||||||||
| 189 | %{\\n%\\x7b# \\x7df\\n${prefix}%n = %D\\n}O%{${prefix}Cannot programmatically discover what parameters this policy takes.\\n}U | ||||||||||||
| 190 | END_OF_FORMAT | ||||||||||||
| 191 | |||||||||||||
| 192 | } | ||||||||||||
| 193 | |||||||||||||
| 194 | #----------------------------------------------------------------------------- | ||||||||||||
| 195 | |||||||||||||
| 196 | 142 | ▶ | sub _by_type { return ref $a cmp ref $b } | ||||||||||
|
Subroutine
_by_type: called CC=1 SCAR=0.0
| |||||||||||||
| 197 | |||||||||||||
| 198 | 2 | 1; | |||||||||||
| 199 | |||||||||||||
| 200 | __END__ | ||||||||||||
| 201 | |||||||||||||
| 202 | =pod | ||||||||||||
| 203 | |||||||||||||
| 204 | =head1 NAME | ||||||||||||
| 205 | |||||||||||||
| 206 | Perl::Critic::ProfilePrototype - Generate an initial Perl::Critic profile. | ||||||||||||
| 207 | |||||||||||||
| 208 | |||||||||||||
| 209 | =head1 DESCRIPTION | ||||||||||||
| 210 | |||||||||||||
| 211 | This is a helper class that generates a prototype of a | ||||||||||||
| 212 | L<Perl::Critic|Perl::Critic> profile (e.g. a F<.perlcriticrc> file). | ||||||||||||
| 213 | There are no user-serviceable parts here. | ||||||||||||
| 214 | |||||||||||||
| 215 | |||||||||||||
| 216 | =head1 INTERFACE SUPPORT | ||||||||||||
| 217 | |||||||||||||
| 218 | This is considered to be a non-public class. Its interface is subject | ||||||||||||
| 219 | to change without notice. | ||||||||||||
| 220 | |||||||||||||
| 221 | |||||||||||||
| 222 | =head1 CONSTRUCTOR | ||||||||||||
| 223 | |||||||||||||
| 224 | =over | ||||||||||||
| 225 | |||||||||||||
| 226 | =item C<< new( -policies => \@POLICY_OBJECTS ) >> | ||||||||||||
| 227 | |||||||||||||
| 228 | Returns a reference to a new C<Perl::Critic::ProfilePrototype> object. | ||||||||||||
| 229 | |||||||||||||
| 230 | |||||||||||||
| 231 | =back | ||||||||||||
| 232 | |||||||||||||
| 233 | |||||||||||||
| 234 | =head1 METHODS | ||||||||||||
| 235 | |||||||||||||
| 236 | =over | ||||||||||||
| 237 | |||||||||||||
| 238 | =item to_string() | ||||||||||||
| 239 | |||||||||||||
| 240 | Returns a string representation of this C<ProfilePrototype>. See | ||||||||||||
| 241 | L<"OVERLOADS"> for more information. | ||||||||||||
| 242 | |||||||||||||
| 243 | |||||||||||||
| 244 | =back | ||||||||||||
| 245 | |||||||||||||
| 246 | |||||||||||||
| 247 | =head1 OVERLOADS | ||||||||||||
| 248 | |||||||||||||
| 249 | When a | ||||||||||||
| 250 | L<Perl::Critic::ProfilePrototype|Perl::Critic::ProfilePrototype> is | ||||||||||||
| 251 | evaluated in string context, it produces a multi-line summary of the | ||||||||||||
| 252 | policy name, default themes, and default severity for each | ||||||||||||
| 253 | L<Perl::Critic::Policy|Perl::Critic::Policy> object that was given to | ||||||||||||
| 254 | the constructor of this C<ProfilePrototype>. If the Policy supports | ||||||||||||
| 255 | an additional parameters, they will also be listed (but | ||||||||||||
| 256 | commented-out). The format is suitable for use as a F<.perlcriticrc> | ||||||||||||
| 257 | file. | ||||||||||||
| 258 | |||||||||||||
| 259 | |||||||||||||
| 260 | =head1 AUTHOR | ||||||||||||
| 261 | |||||||||||||
| 262 | Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> | ||||||||||||
| 263 | |||||||||||||
| 264 | |||||||||||||
| 265 | =head1 COPYRIGHT | ||||||||||||
| 266 | |||||||||||||
| 267 | Copyright (c) 2005-2023 Imaginative Software Systems | ||||||||||||
| 268 | |||||||||||||
| 269 | This program is free software; you can redistribute it and/or modify | ||||||||||||
| 270 | it under the same terms as Perl itself. The full text of this license | ||||||||||||
| 271 | can be found in the LICENSE file included with this module. | ||||||||||||
| 272 | |||||||||||||
| 273 | =cut | ||||||||||||
| 274 | |||||||||||||
| 275 | # Local Variables: | ||||||||||||
| 276 | # mode: cperl | ||||||||||||
| 277 | # cperl-indent-level: 4 | ||||||||||||
| 278 | # fill-column: 78 | ||||||||||||
| 279 | # indent-tabs-mode: nil | ||||||||||||
| 280 | # c-indentation-style: bsd | ||||||||||||
| 281 | # End: | ||||||||||||
| 282 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : | ||||||||||||