Login
Optimized by moving more regexes.
[gknop/Perl-Critic.git] / lib / Perl / Critic / Policy / Modules / ProhibitEvilModules.pm
CommitLineData
d59eec4b
JRT
1package Perl::Critic::Policy::Modules::ProhibitEvilModules;
2
3use strict;
4use warnings;
5use Perl::Critic::Utils;
6use Perl::Critic::Violation;
7use base 'Perl::Critic::Policy';
8
9ad4bbe8 9our $VERSION = '0.14';
d59eec4b
JRT
10$VERSION = eval $VERSION; ## no critic
11
12my $expl = q{Find an alternative module};
13my $desc = q{Prohibited module used};
14
15#----------------------------------------------------------------------------
16
90c7f9ef 17sub default_severity { return $SEVERITY_HIGHEST }
2c943bed
JRT
18sub applies_to { return 'PPI::Statement::Include' }
19
20#----------------------------------------------------------------------------
21
d59eec4b
JRT
22sub new {
23 my ( $class, %args ) = @_;
24 my $self = bless {}, $class;
25
26 #Set config, if defined
27 if ( defined $args{modules} ) {
28 for my $module ( split m{ \s+ }mx, $args{modules} ) {
29 $self->{_evil_modules}->{$module} = 1;
30 }
31 }
32 return $self;
33}
34
2c943bed 35#----------------------------------------------------------------------------
d59eec4b
JRT
36
37sub violates {
38 my ( $self, $elem, $doc ) = @_;
39 if ( exists $self->{_evil_modules}->{ $elem->module() } ) {
6bf9b465
JRT
40 my $sev = $self->get_severity();
41 return Perl::Critic::Violation->new( $desc, $expl, $elem, $sev );
d59eec4b
JRT
42 }
43 return; #ok!
44}
45
461;
47
48__END__
49
2c943bed
JRT
50#----------------------------------------------------------------------------
51
d59eec4b
JRT
52=pod
53
54=head1 NAME
55
56Perl::Critic::Policy::Modules::ProhibitEvilModules
57
58=head1 DESCRIPTION
59
60Use this policy if you wish to prohibit the use of specific modules.
61These may be modules that you feel are deprecated, buggy, unsupported,
62insecure, or just don't like.
63
64=head1 CONSTRUCTOR
65
66This policy accepts an additional key-value pair in the C<new> method.
67The key should be 'modules' and the value is a string of
2c943bed
JRT
68space-delimited fully qualified module names. These can be configured
69in the F<.perlcriticrc> file like this:
d59eec4b
JRT
70
71 [Modules::ProhibitEvilModules]
72 modules = Getopt::Std Autoload
73
74By default, there aren't any prohibited modules (although I can think
75of a few that should be).
76
77=head1 NOTES
78
79Note that this policy doesn't apply to pragmas. Future versions may
80allow you to specify an alternative for each prohibited module, which
81can be suggested by L<Perl::Critic>.
82
83=head1 AUTHOR
84
85Jeffrey Ryan Thalhammer <thaljef@cpan.org>
86
87=head1 COPYRIGHT
88
c3c88e54 89Copyright (c) 2005-2006 Jeffrey Ryan Thalhammer. All rights reserved.
d59eec4b
JRT
90
91This program is free software; you can redistribute it and/or modify
92it under the same terms as Perl itself. The full text of this license
93can be found in the LICENSE file included with this module.
94
95=cut