File Coverage

blib/lib/Perl/Critic/Policy/ControlStructures/ProhibitUntilBlocks.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition n/a
subroutine 11 11 100.0
pod 4 5 80.0
total 42 43 97.6


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::ControlStructures::ProhibitUntilBlocks;
2              
3 40     40   27662 use 5.010001;
  40         186  
4 40     40   259 use strict;
  40         115  
  40         935  
5 40     40   232 use warnings;
  40         118  
  40         1076  
6 40     40   239 use Readonly;
  40         133  
  40         2155  
7              
8 40     40   292 use Perl::Critic::Utils qw{ :severities };
  40         153  
  40         2071  
9 40     40   5461 use parent 'Perl::Critic::Policy';
  40         126  
  40         296  
10              
11             our $VERSION = '1.148';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{"until" block used};
16             Readonly::Scalar my $EXPL => [ 97 ];
17              
18             #-----------------------------------------------------------------------------
19              
20 91     91 0 1711 sub supported_parameters { return () }
21 75     75 1 352 sub default_severity { return $SEVERITY_LOW }
22 84     84 1 379 sub default_themes { return qw(core pbp cosmetic) }
23 32     32 1 113 sub applies_to { return 'PPI::Statement' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 288     288 1 620 my ( $self, $elem, undef ) = @_;
29 288 100       743 if ( $elem->first_element() eq 'until' ) {
30 1         30 return $self->violation( $DESC, $EXPL, $elem );
31             }
32 287         4501 return; #ok!
33             }
34              
35             1;
36              
37             __END__
38              
39             #-----------------------------------------------------------------------------
40              
41             =pod
42              
43             =head1 NAME
44              
45             Perl::Critic::Policy::ControlStructures::ProhibitUntilBlocks - Write C<while(! $condition)> instead of C<until($condition)>.
46              
47             =head1 AFFILIATION
48              
49             This Policy is part of the core L<Perl::Critic|Perl::Critic>
50             distribution.
51              
52              
53             =head1 DESCRIPTION
54              
55             Conway discourages using C<until> because it leads to double-negatives
56             that are hard to understand. Instead, reverse the logic and use
57             C<while>.
58              
59             until($condition) { do_something() } #not ok
60             until(! $no_flag) { do_something() } #really bad
61             while( ! $condition) { do_something() } #ok
62              
63             This Policy only covers the block-form of C<until>. For the postfix
64             variety, see C<ProhibitPostfixControls>.
65              
66              
67             =head1 CONFIGURATION
68              
69             This Policy is not configurable except for the standard options.
70              
71              
72             =head1 SEE ALSO
73              
74             L<Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls|Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls>
75              
76             =head1 AUTHOR
77              
78             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
79              
80             =head1 COPYRIGHT
81              
82             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
83              
84             This program is free software; you can redistribute it and/or modify
85             it under the same terms as Perl itself. The full text of this license
86             can be found in the LICENSE file included with this module.
87              
88             =cut
89              
90             # Local Variables:
91             # mode: cperl
92             # cperl-indent-level: 4
93             # fill-column: 78
94             # indent-tabs-mode: nil
95             # c-indentation-style: bsd
96             # End:
97             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :