« lib/Perl/Critic/Policy/InputOutput/ProhibitReadlineInForLoop.pm
↑ Summary
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.156'; | |||||||||||
| 13 | |||||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||||
| 15 | |||||||||||||
| 16 | 2 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 17 | 2 | my ($class, %args) = @_; | |||||||||||
| 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 | 1 | ▶ | sub _get_policies { | ||||||||||
|
Subroutine
_get_policies: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | 1 | my ($self) = @_; | |||||||||||
| 39 | |||||||||||||
| 40 | 1 | return $self->{_policies}; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | 2 | ▶ | sub _comment_out_parameters { | ||||||||||
|
Subroutine
_comment_out_parameters: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | 2 | my ($self) = @_; | |||||||||||
| 45 | |||||||||||||
| 46 | 2 | return $self->{_comment_out_parameters}; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 1 | ▶ | sub _configuration { | ||||||||||
|
Subroutine
_configuration: called CC=1 SCAR=0.0
| |||||||||||||
| 50 | 1 | my ($self) = @_; | |||||||||||
| 51 | |||||||||||||
| 52 | 1 | return $self->{_configuration}; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | #----------------------------------------------------------------------------- | ||||||||||||
| 56 | |||||||||||||
| 57 | 2 | ▶ | sub _line_prefix { | ||||||||||
|
Subroutine
_line_prefix: called CC=2 SCAR=7.2
| |||||||||||||
| 58 | 2 | my ($self) = @_; | |||||||||||
| 59 | |||||||||||||
| 60 | 2 | ▶ | return $self->_comment_out_parameters() ? q{# } : $EMPTY; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | #----------------------------------------------------------------------------- | ||||||||||||
| 64 | |||||||||||||
| 65 | 1 | ▶ | sub to_string { | ||||||||||
|
Subroutine
to_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 66 | 1 | my ($self) = @_; | |||||||||||
| 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 | 1 | ▶ | sub _proto_format { | ||||||||||
|
Subroutine
_proto_format: called CC=1 SCAR=0.0
| |||||||||||||
| 178 | 1 | my ($self) = @_; | |||||||||||
| 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__ | ||||||||||||