1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ControlStructures/ProhibitUnlessBlocks.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::ControlStructures::ProhibitUnlessBlocks;
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{"unless" block used};
23 Readonly::Scalar my $EXPL => [ 97 ];
25 #-----------------------------------------------------------------------------
27 sub supported_parameters { return () }
28 sub default_severity { return $SEVERITY_LOW }
29 sub default_themes { return qw(core pbp cosmetic) }
30 sub applies_to { return 'PPI::Statement::Compound' }
32 #-----------------------------------------------------------------------------
35 my ( $self, $elem, undef ) = @_;
37 if ( $elem->first_element() eq 'unless' ) {
38 return $self->violation( $DESC, $EXPL, $elem );
47 #-----------------------------------------------------------------------------
53 Perl::Critic::Policy::ControlStructures::ProhibitUnlessBlocks - Write C<if(! $condition)> instead of C<unless($condition)>.
57 This Policy is part of the core L<Perl::Critic> distribution.
62 Conway discourages using C<unless> because it leads to double-negatives
63 that are hard to understand. Instead, reverse the logic and use C<if>.
65 unless($condition) { do_something() } #not ok
66 unless(! $no_flag) { do_something() } #really bad
67 if( ! $condition) { do_something() } #ok
69 This Policy only covers the block-form of C<unless>. For the postfix
70 variety, see C<ProhibitPostfixControls>.
75 This Policy is not configurable except for the standard options.
80 L<Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls>
84 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
88 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
90 This program is free software; you can redistribute it and/or modify
91 it under the same terms as Perl itself. The full text of this license
92 can be found in the LICENSE file included with this module.
98 # cperl-indent-level: 4
100 # indent-tabs-mode: nil
101 # c-indentation-style: bsd
103 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :