Build all packages removed dependencies of libtest-exception-perl libtest-warn-perl...
[dh-make-perl] / dev / i386 / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / TestingAndDebugging / ProhibitNoStrict.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/TestingAndDebugging/ProhibitNoStrict.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::ProhibitNoStrict;
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{Stricture disabled};
25 Readonly::Scalar my $EXPL => [ 429 ];
26
27 #-----------------------------------------------------------------------------
28
29 sub supported_parameters {
30     return (
31         {
32             name            => 'allow',
33             description     => 'Allow vars, subs, and/or refs.',
34             default_string  => $EMPTY,
35             parser          => \&_parse_allow,
36         },
37     );
38 }
39
40 sub default_severity { return $SEVERITY_HIGHEST         }
41 sub default_themes   { return qw( core pbp bugs )       }
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 'strict';
68
69     #Arguments to 'no strict' are usually a list of literals or a qw()
70     #list.  Rather than trying to parse the various PPI elements, I
71     #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 'strict' } @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::ProhibitNoStrict - Prohibit various flavors of C<no strict>.
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 strictures, But
109 if you were wise enough to C<use strict> in the first place, then it
110 doesn't make sense to disable it completely.  By default, any C<no
111 strict> statement will violate this policy.  However, you can
112 configure this Policy to allow certain types of strictures to be
113 disabled (See L</CONFIGURATION>).  A bare C<no strict> statement will
114 always raise a violation.
115
116 =head1 CONFIGURATION
117
118 The permitted strictures can be configured via the C<allow> option.
119 The value is a list of whitespace-delimited stricture types that you
120 want to permit.  These can be C<vars>, C<subs> and/or C<refs>.  An
121 example of this customization:
122
123   [TestingAndDebugging::ProhibitNoStrict]
124   allow = vars subs refs
125
126 =head1 SEE ALSO
127
128 L<Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict>
129
130 =head1 AUTHOR
131
132 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
133
134 =head1 COPYRIGHT
135
136 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
137
138 This program is free software; you can redistribute it and/or modify
139 it under the same terms as Perl itself.  The full text of this license
140 can be found in the LICENSE file included with this module
141
142 =cut
143
144 ##############################################################################
145 # Local Variables:
146 #   mode: cperl
147 #   cperl-indent-level: 4
148 #   fill-column: 78
149 #   indent-tabs-mode: nil
150 #   c-indentation-style: bsd
151 # End:
152 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :