line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::logicLAB::RequireParamsValidate; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: ProhibitShellDispatch.pm 8114 2013-07-25 12:57:04Z jonasbn $ |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
887828
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
130
|
|
6
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
109
|
|
7
|
3
|
|
|
3
|
|
20
|
use base 'Perl::Critic::Policy'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
15424
|
|
8
|
3
|
|
|
3
|
|
571924
|
use Perl::Critic::Utils qw{ $SEVERITY_MEDIUM }; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
729
|
|
9
|
3
|
|
|
3
|
|
17397
|
use Data::Dumper; |
|
3
|
|
|
|
|
19712
|
|
|
3
|
|
|
|
|
2090
|
|
10
|
3
|
|
|
3
|
|
35
|
use List::MoreUtils qw(any); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
269
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
88
|
use 5.006; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
256
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Use Params::Validate for public facing APIs}; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $warning => |
18
|
|
|
|
|
|
|
q{Parameter validation not complying with required standard}; |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
19
|
use constant supported_parameters => (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
248
|
|
21
|
3
|
|
|
3
|
|
50
|
use constant default_severity => $SEVERITY_MEDIUM; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
160
|
|
22
|
3
|
|
|
3
|
|
28
|
use constant default_themes => qw(logiclab); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1051
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
## no critic (RequireParamsValidate); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub applies_to { |
27
|
|
|
|
|
|
|
return ( |
28
|
1
|
|
|
1
|
1
|
5242256
|
qw( |
29
|
|
|
|
|
|
|
PPI::Statement::Sub |
30
|
|
|
|
|
|
|
) |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub violates { |
35
|
4
|
|
|
4
|
1
|
437
|
my ( $self, $elem ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#For debugging removing all whitespace |
38
|
4
|
|
|
|
|
25
|
$elem->prune('PPI::Token::Whitespace'); |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
5265
|
my $words = $elem->find('PPI::Token::Word'); |
41
|
|
|
|
|
|
|
|
42
|
4
|
100
|
66
|
|
|
2848
|
if ( $words->[0]->content eq 'sub' |
43
|
|
|
|
|
|
|
and $words->[1]->content !~ m/\b_\w+\b/xsm ) |
44
|
|
|
|
|
|
|
{ |
45
|
3
|
|
|
|
|
63
|
return $self->_assert_params_validate( $elem, $words ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
19
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _assert_params_validate { |
52
|
3
|
|
|
3
|
|
7
|
my ( $self, $elem, $elements ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
9
|
my @params_validate_keywords = qw(validate validate_pos validate_with); |
55
|
3
|
|
|
|
|
4
|
my $ok; |
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
6
|
foreach my $word ( @{$elements} ) { |
|
3
|
|
|
|
|
7
|
|
58
|
9
|
100
|
|
25
|
|
75
|
if ( any { $word->content eq $_ } @params_validate_keywords ) { |
|
25
|
|
|
|
|
104
|
|
59
|
1
|
|
|
|
|
7
|
$ok++; |
60
|
1
|
|
|
|
|
3
|
last; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
3
|
100
|
|
|
|
23
|
if ($ok) { |
65
|
1
|
|
|
|
|
6
|
return; |
66
|
|
|
|
|
|
|
} else { |
67
|
2
|
|
|
|
|
24
|
return $self->violation( $warning, $EXPL, $elem ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Perl::Critic::Policy::logicLAB::RequireParamsValidate - simple policy for enforcing use of Params::Validate |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 AFFILIATION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This policy is a policy in the Perl::Critic::logicLAB distribution. The policy |
82
|
|
|
|
|
|
|
is themed: logiclab. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 VERSION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This documentation describes version 0.01. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SYNOPSIS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# ok |
91
|
|
|
|
|
|
|
sub foo { |
92
|
|
|
|
|
|
|
validate( |
93
|
|
|
|
|
|
|
@_, { |
94
|
|
|
|
|
|
|
foo => 1, # mandatory |
95
|
|
|
|
|
|
|
bar => 0, # optional |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#... |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# not ok |
103
|
|
|
|
|
|
|
sub bar { |
104
|
|
|
|
|
|
|
return 1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# ok |
108
|
|
|
|
|
|
|
sub _baz { |
109
|
|
|
|
|
|
|
return 1; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Invocation of policy: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$ perlcritic --single-policy logicLAB::RequireParamsValidate lib |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Explanation: |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Use Params::Validate for public facing APIs |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Description: |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Parameter validation not complying with required standard |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
No special requirements or environment required. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 DEPENDENCIES AND REQUIREMENTS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=over |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * L<Module::Build> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * L<Perl::Critic> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * L<Perl::Critic::Utils> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * L<Perl::Critic::Policy> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * L<Test::More> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * L<Test::Class> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * L<Test::Perl::Critic> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * L<Data::Dumper> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * L<File::Spec> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * L<List::MoreUtils> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * L<Params::Validate> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This distribution has no known incompatibilities. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
There are no known bugs or limitations |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 TEST AND QUALITY |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
The following policies have been disabled for this distribution |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitConstantPragma> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Constants are good, - see the link below. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=over |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item * L<https://logiclab.jira.com/wiki/display/OPEN/Perl-Critic-Policy-ValuesAndExpressions-ProhibitConstantPragma> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=back |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item * L<Perl::Critic::Policy::NamingConventions::Capitalization> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
See also F<t/perlcriticrc> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 TEST COVERAGE |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Coverage test executed the following way, the coverage report is based on the |
190
|
|
|
|
|
|
|
version described in this documentation (see L</VERSION>). |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
./Build testcover |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
195
|
|
|
|
|
|
|
File stmt bran cond sub pod time total |
196
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
197
|
|
|
|
|
|
|
.../RequireParamsValidate.pm 100.0 100.0 66.7 100.0 100.0 100.0 98.6 |
198
|
|
|
|
|
|
|
Total 100.0 100.0 66.7 100.0 100.0 100.0 98.6 |
199
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 SEE ALSO |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=over |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item * L<Perl::Critic> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * L<https://metacpan.org/pod/Params::Validate> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=back |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 AUTHOR |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=over |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * Jonas B. Nielsen, jonasbn C<< <jonasbn@cpan.org> >> |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENT |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=over |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * Jeffrey Ryan Thalhammer (THALJEF) and the Perl::Critic contributors for |
224
|
|
|
|
|
|
|
Perl::Critic |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=back |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Copyright (c) 2013-2014 Jonas B. Nielsen, jonasbn. All rights reserved. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Perl::Critic::Policy::logicLAB::RequirePackageNamePattern; is released under |
233
|
|
|
|
|
|
|
the Artistic License 2.0 |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
The distribution is licensed under the Artistic License 2.0, as specified by |
236
|
|
|
|
|
|
|
the license file included in this distribution. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |