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