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