line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::logicLAB::ModuleBlacklist; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
9013
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
72
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
5
|
2
|
|
|
2
|
|
45
|
use 5.008; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
891
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use base 'Perl::Critic::Policy'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2650
|
|
8
|
2
|
|
|
2
|
|
502145
|
use Perl::Critic::Utils qw{ $SEVERITY_MEDIUM :booleans}; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
177
|
|
9
|
2
|
|
|
2
|
|
207
|
use Carp qw(carp); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
101
|
|
10
|
2
|
|
|
2
|
|
1748
|
use Data::Dumper; |
|
2
|
|
|
|
|
8950
|
|
|
2
|
|
|
|
|
260
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
18
|
use constant supported_parameters => qw(modules debug); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
154
|
|
15
|
2
|
|
|
2
|
|
11
|
use constant default_severity => $SEVERITY_MEDIUM; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
99
|
|
16
|
2
|
|
|
2
|
|
9
|
use constant default_themes => qw(logiclab); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1505
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub applies_to { |
19
|
|
|
|
|
|
|
return ( |
20
|
9
|
|
|
9
|
1
|
274810
|
qw( |
21
|
|
|
|
|
|
|
PPI::Statement::Include |
22
|
|
|
|
|
|
|
) |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub violates { |
27
|
17
|
|
|
17
|
1
|
1000
|
my ( $self, $elem ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#Policy not configured, nothing to assert |
30
|
17
|
50
|
|
|
|
80
|
if ( not $self->{_modules} ) { |
31
|
0
|
|
|
|
|
0
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
17
|
|
|
|
|
83
|
my @children = $elem->children; |
35
|
|
|
|
|
|
|
|
36
|
17
|
100
|
100
|
|
|
184
|
if ( $children[0]->content eq 'use' or $children[0]->content eq 'require') { |
|
|
50
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
16
|
|
|
|
|
194
|
my $package = $children[2]->content; |
39
|
|
|
|
|
|
|
|
40
|
16
|
50
|
|
|
|
149
|
if ( $self->{debug} ) { |
41
|
0
|
|
|
|
|
0
|
print STDERR "located include: $package\n"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
16
|
|
|
|
|
26
|
foreach my $module ( keys %{ $self->{_modules} } ) { |
|
16
|
|
|
|
|
100
|
|
45
|
|
|
|
|
|
|
|
46
|
42
|
100
|
|
|
|
108
|
if ( $package eq $module ) { |
47
|
|
|
|
|
|
|
|
48
|
8
|
100
|
|
|
|
57
|
if ( defined $self->{_modules}->{$module} ) { |
49
|
4
|
|
|
|
|
13
|
my $recommendation = $self->{_modules}->{$module}; |
50
|
4
|
|
|
|
|
36
|
return $self->violation( |
51
|
|
|
|
|
|
|
"Blacklisted: $package is not recommended by required standard", |
52
|
|
|
|
|
|
|
"Use recommended module: $recommendation instead of $package", |
53
|
|
|
|
|
|
|
$elem, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} else { |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
40
|
return $self->violation( |
59
|
|
|
|
|
|
|
"Blacklisted: $package is not recommended by required standard", |
60
|
|
|
|
|
|
|
"Use alternative implementation or module instead of $package", |
61
|
|
|
|
|
|
|
$elem, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#we ignore negative use statements, they are for pragma [issue1] |
68
|
|
|
|
|
|
|
} elsif ( $children[0]->content eq 'no' ) { |
69
|
1
|
50
|
|
|
|
31
|
if ( $self->{debug} ) { |
70
|
0
|
|
|
|
|
0
|
print STDERR "located 'no' use/require statement\n"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} else { |
73
|
0
|
|
|
|
|
0
|
carp 'Unable to locate package keyword'; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
9
|
|
|
|
|
37
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub initialize_if_enabled { |
80
|
1
|
|
|
1
|
1
|
19294449
|
my ( $self, $config ) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#debug - order is significant, since we might need debugging |
83
|
1
|
|
33
|
|
|
9
|
$self->{debug} = $config->get('debug') || $FALSE; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#Names: |
86
|
|
|
|
|
|
|
#fetching list of blacklisted modules |
87
|
1
|
|
|
|
|
18
|
my $modules = $config->get('modules'); |
88
|
|
|
|
|
|
|
|
89
|
1
|
50
|
|
|
|
11
|
if ( $self->{debug} ) { |
90
|
0
|
|
|
|
|
0
|
carp "Blacklisted modules are: $modules\n"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#parsing blacklisted modules, see also _parse_blacklist |
94
|
1
|
50
|
|
|
|
9
|
if ($modules) { |
95
|
1
|
|
50
|
|
|
7
|
$self->{_modules} = $self->_parse_modules($modules) || q{}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
6
|
return $TRUE; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _parse_modules { |
102
|
1
|
|
|
1
|
|
3
|
my ( $self, $config_string ) = @_; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#first we split on commas |
105
|
1
|
|
|
|
|
12
|
my @parameters = split /\s*,\s*/, $config_string; |
106
|
1
|
|
|
|
|
4
|
my %modules; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#then we split on fat commas, to locate recommendations |
109
|
1
|
|
|
|
|
4
|
foreach my $parameter (@parameters) { |
110
|
3
|
100
|
|
|
|
15
|
if ( $parameter =~ m/\s*=>\s*/ ) { |
111
|
2
|
|
|
|
|
12
|
my @p = split /\s*=>\s*/, $parameter; |
112
|
|
|
|
|
|
|
|
113
|
2
|
|
|
|
|
9
|
$modules{ $p[0] } = $p[1]; |
114
|
|
|
|
|
|
|
} else { |
115
|
1
|
|
|
|
|
4
|
$modules{$parameter} = undef; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
7
|
return \%modules; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=pod |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=encoding utf8 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Perl::Critic::Policy::logicLAB::ModuleBlacklist - blacklist modules you want to prohibit use of |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AFFILIATION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This policy is a policy in the Perl::Critic::logicLAB distribution. The policy |
137
|
|
|
|
|
|
|
is themed: logiclab. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 VERSION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This documentation describes version 0.03 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 DESCRIPTION |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This policy can be used to specify a list of unwanted modules. Using a blacklisting, so if the |
146
|
|
|
|
|
|
|
modules are used in the evaluated code a violation is triggered. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
In addition to blacklisting modules it is possible to recommend alternatives to |
149
|
|
|
|
|
|
|
blacklisted modules. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 modules |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
You can blacklist modules using the configuration parameter B<modules> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
[logicLAB::ModuleBlacklist] |
158
|
|
|
|
|
|
|
modules = IDNA::Punycode |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
If you want to blacklist multiple modules specify using a comma separated list: |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
[logicLAB::ModuleBlacklist] |
163
|
|
|
|
|
|
|
modules = Try::Tiny, Contextual::Return, IDNA::Punycode |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
If you want to recommend alternatives to, use fat comma in addition |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
[logicLAB::ModuleBlacklist] |
168
|
|
|
|
|
|
|
modules = Try::Tiny => TryCatch, Contextual::Return, IDNA::Punycode => Net::IDN::Encode |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 DEPENDENCIES AND REQUIREMENTS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=over |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * L<Perl> 5.8.0 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * L<Module::Build> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * L<Perl::Critic> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * L<Perl::Critic::Utils> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * L<Perl::Critic::Policy> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * L<Test::More> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * L<Test::Perl::Critic> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * L<Data::Dumper> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * L<Carp> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This distribution has no known incompatibilities. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
There are no known bugs or limitations |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 TEST AND QUALITY |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
The following policies have been disabled for this distribution |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=over |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitConstantPragma> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Constants are good, - see the link below. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=over |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * L<https://logiclab.jira.com/wiki/display/OPEN/Perl-Critic-Policy-ValuesAndExpressions-ProhibitConstantPragma> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=back |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * L<Perl::Critic::Policy::NamingConventions::Capitalization> |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=back |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
See also F<t/perlcriticrc> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 TEST COVERAGE |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Coverage test executed the following way, the coverage report is based on the |
227
|
|
|
|
|
|
|
version described in this documentation (see L</VERSION>). |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
./Build testcover |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
232
|
|
|
|
|
|
|
File stmt bran cond sub pod time total |
233
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
234
|
|
|
|
|
|
|
...gicLAB/ModuleBlacklist.pm 88.9 63.6 40.0 100.0 100.0 100.0 83.6 |
235
|
|
|
|
|
|
|
Total 88.9 63.6 40.0 100.0 100.0 100.0 83.6 |
236
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 BUG REPORTING |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Please report issues via CPAN RT: |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Perl-Critic-Policy-logicLAB-ModuleBlacklist |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
or by sending mail to |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
bug-Perl-Critic-Policy-logicLAB-ModuleBlacklist@rt.cpan.org |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 SEE ALSO |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=over |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item * L<Perl::Critic> |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * L<http://logiclab.jira.com/wiki/display/PCLL/Home> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=back |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 MOTIVATION |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
I once read an article which compared programming languages to |
261
|
|
|
|
|
|
|
natural languages. Programming languages in themselves are not |
262
|
|
|
|
|
|
|
large as such, but if you also regard the APIs, data structures |
263
|
|
|
|
|
|
|
and components a computer programmer use on a daily basis, the |
264
|
|
|
|
|
|
|
amount is enormous. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Where I work We try to keep a more simple code base, the complexity |
267
|
|
|
|
|
|
|
is in our business and that is our primary problem area, so it should |
268
|
|
|
|
|
|
|
not be difficult to understand the code used to model this complexity. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
So sometimes it is necessary to make a decision on what should be |
271
|
|
|
|
|
|
|
allowed in our code base and what should not. This policy aims to |
272
|
|
|
|
|
|
|
support this coding practice. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
The practice it basically to prohibit problematic components and |
275
|
|
|
|
|
|
|
recommend alternatives where possible. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head1 AUTHOR |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=over |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item * Jonas B. Nielsen, jonasbn C<< <jonasbn@cpan.org> >> |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=back |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENT |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=over |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item * Jeffrey Ryan Thalhammer (THALJEF) and the Perl::Critic contributors for |
290
|
|
|
|
|
|
|
Perl::Critic |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=item * Milan Å orm for the first and second bug reports on this policy |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=back |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
Copyright (c) 2014 Jonas B. Nielsen, jonasbn. All rights reserved. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Perl::Critic::Policy::logicLAB::ModuleBlacklist; is released under |
301
|
|
|
|
|
|
|
the Artistic License 2.0 |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
The distribution is licensed under the Artistic License 2.0, as specified by |
304
|
|
|
|
|
|
|
the license file included in this distribution. |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=cut |