Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / TestingAndDebugging / ProhibitNoWarnings.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/TestingAndDebugging/ProhibitNoWarnings.pm $
3 #     $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use List::MoreUtils qw(all);
16
17 use Perl::Critic::Utils qw{ :characters :severities :data_conversion };
18 use base 'Perl::Critic::Policy';
19
20 our $VERSION = '1.088';
21
22 #-----------------------------------------------------------------------------
23
24 Readonly::Scalar my $DESC => q{Warnings disabled};
25 Readonly::Scalar my $EXPL => [ 431 ];
26
27 #-----------------------------------------------------------------------------
28
29 sub supported_parameters {
30     return (
31         {
32             name            => 'allow',
33             description     => 'Permitted warning categories.',
34             default_string  => $EMPTY,
35             parser          => \&_parse_allow,
36         },
37     );
38 }
39
40 sub default_severity { return $SEVERITY_HIGH            }
41 sub default_themes   { return qw( core bugs pbp )       }
42 sub applies_to       { return 'PPI::Statement::Include' }
43
44 #-----------------------------------------------------------------------------
45
46 sub _parse_allow {
47     my ($self, $parameter, $config_string) = @_;
48
49     $self->{_allow} = {};
50
51     if( defined $config_string ) {
52         my $allowed = lc $config_string; #String of words
53         my %allowed = hashify( $allowed =~ m/ (\w+) /gmx );
54         $self->{_allow} = \%allowed;
55     }
56
57     return;
58 }
59
60 #-----------------------------------------------------------------------------
61
62 sub violates {
63
64     my ( $self, $elem, undef ) = @_;
65
66     return if $elem->type()   ne 'no';
67     return if $elem->pragma() ne 'warnings';
68
69     #Arguments to 'no warnings' are usually a list of literals or a
70     #qw() list.  Rather than trying to parse the various PPI elements,
71     #I just use a regex to split the statement into words.  This is
72     #kinda lame, but it does the trick for now.
73
74     # TODO consider: a possible alternate implementation:
75     #   my $re = join q{|}, keys %{$self->{allow}};
76     #   return if $re && $stmnt =~ m/\b(?:$re)\b/mx;
77     # May need to detaint for that to work...  Not sure.
78
79     my $stmnt = $elem->statement();
80     return if !$stmnt;
81     my @words = $stmnt =~ m/ ([[:lower:]]+) /gmx;
82     @words = grep { $_ ne 'qw' && $_ ne 'no' && $_ ne 'warnings' } @words;
83     return if all { exists $self->{_allow}->{$_} } @words;
84
85     #If we get here, then it must be a violation
86     return $self->violation( $DESC, $EXPL, $elem );
87 }
88
89 1;
90
91 __END__
92
93 #-----------------------------------------------------------------------------
94
95 =pod
96
97 =head1 NAME
98
99 Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings - Prohibit various flavors of C<no warnings>.
100
101 =head1 AFFILIATION
102
103 This Policy is part of the core L<Perl::Critic> distribution.
104
105
106 =head1 DESCRIPTION
107
108 There are good reasons for disabling certain kinds of warnings.  But if you
109 were wise enough to C<use warnings> in the first place, then it doesn't make
110 sense to disable them completely.  By default, any C<no warnings> statement
111 will violate this policy.  However, you can configure this Policy to allow
112 certain types of warnings to be disabled (See L<Configuration>).  A bare C<no
113 warnings> statement will always raise a violation.
114
115 =head1 CONFIGURATION
116
117 The permitted warning types can be configured via the C<allow> option.  The
118 value is a list of whitespace-delimited warning types that you want to be able
119 to disable.  See L<perllexwarn> for a list of possible warning types.  An
120 example of this customization:
121
122   [TestingAndDebugging::ProhibitNoWarnings]
123   allow = uninitialized once
124
125 =head1 SEE ALSO
126
127 L<Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings>
128
129 =head1 AUTHOR
130
131 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
132
133 =head1 COPYRIGHT
134
135 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
136
137 This program is free software; you can redistribute it and/or modify it under
138 the same terms as Perl itself.  The full text of this license can be found in
139 the LICENSE file included with this module
140
141 =cut
142
143 ##############################################################################
144 # Local Variables:
145 #   mode: cperl
146 #   cperl-indent-level: 4
147 #   fill-column: 78
148 #   indent-tabs-mode: nil
149 #   c-indentation-style: bsd
150 # End:
151 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :