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) $
6 ##############################################################################
8 package Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict;
15 use List::MoreUtils qw(all);
17 use Perl::Critic::Utils qw{ :characters :severities :data_conversion };
18 use base 'Perl::Critic::Policy';
20 our $VERSION = '1.088';
22 #-----------------------------------------------------------------------------
24 Readonly::Scalar my $DESC => q{Stricture disabled};
25 Readonly::Scalar my $EXPL => [ 429 ];
27 #-----------------------------------------------------------------------------
29 sub supported_parameters {
33 description => 'Allow vars, subs, and/or refs.',
34 default_string => $EMPTY,
35 parser => \&_parse_allow,
40 sub default_severity { return $SEVERITY_HIGHEST }
41 sub default_themes { return qw( core pbp bugs ) }
42 sub applies_to { return 'PPI::Statement::Include' }
44 #-----------------------------------------------------------------------------
47 my ($self, $parameter, $config_string) = @_;
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;
60 #-----------------------------------------------------------------------------
64 my ( $self, $elem, undef ) = @_;
66 return if $elem->type() ne 'no';
67 return if $elem->pragma() ne 'strict';
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.
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.
79 my $stmnt = $elem->statement();
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;
85 #If we get here, then it must be a violation
86 return $self->violation( $DESC, $EXPL, $elem );
93 #-----------------------------------------------------------------------------
99 Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict - Prohibit various flavors of C<no strict>.
103 This Policy is part of the core L<Perl::Critic> distribution.
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.
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:
123 [TestingAndDebugging::ProhibitNoStrict]
124 allow = vars subs refs
128 L<Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict>
132 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
136 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
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
144 ##############################################################################
147 # cperl-indent-level: 4
149 # indent-tabs-mode: nil
150 # c-indentation-style: bsd
152 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :