blib/lib/Perl/Critic/Policy/ControlStructures/ProhibitUntilBlocks.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 93.6% 44 / 47 CC 2 SCAR 1.8
CC
2
Cov
94%
violates
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Perl/Critic/Policy/ClassHierarchies/ProhibitExplicitISA.pm ↑ Summary blib/lib/Perl/Critic/Policy/Subroutines/ProhibitSubroutinePrototypes.pm »
1 package Perl::Critic::Policy::ControlStructures::ProhibitUntilBlocks;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.150';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{"until" block used};
16 40 Readonly::Scalar my $EXPL => [ 97 ];
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 75 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 84 ▶sub default_themes { return qw(core pbp cosmetic) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 31 ▶sub applies_to { return 'PPI::Statement' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24  
25 #-----------------------------------------------------------------------------
26  
27 sub violates {
28 283 ▶ my ( $self, $elem, undef ) = @_;
Subroutine violates: called CC=2 SCAR=7.6
Pod documented
29 283 ▶ if ( $elem->first_element() eq 'until' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->first_element eq "until") 0 283 283
30 0 return $self->violation( $DESC, $EXPL, $elem );
31 }
32 283 return; #ok!
33 }
34  
35 40 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 :
« blib/lib/Perl/Critic/Policy/ClassHierarchies/ProhibitExplicitISA.pm ↑ Summary blib/lib/Perl/Critic/Policy/Subroutines/ProhibitSubroutinePrototypes.pm »