1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
## name Basic failure
## failures 7
## cut
do_something() if $condition;
do_something() while $condition;
do_something() until $condition;
do_something() unless $condition;
do_something() for @list;
do_something() foreach @list;
do_something() when @list;
#-----------------------------------------------------------------------------
## name Configured to allow all
## failures 0
## parms {allow => 'if while until unless for foreach when'}
## cut
do_something() if $condition;
do_something() while $condition;
do_something() until $condition;
do_something() unless $condition;
do_something() for @list;
do_something() foreach @list;
do_something() when @list;
#-----------------------------------------------------------------------------
## name Configured to allow all, all regular control structures
## failures 0
## parms {allow => 'if unless until while when'}
## cut
if($condition){ do_something() }
while($condition){ do_something() }
until($condition){ do_something() }
unless($condition){ do_something() }
when($smart_match){ do_something() }
#-----------------------------------------------------------------------------
## name Regular for loops
## failures 0
## cut
# PPI versions < 1.03 had problems with this
for my $element (@list){ do_something() }
for (@list){ do_something_else() }
foreach my $element (@list){ do_something() }
foreach (@list){ do_something_else() }
#-----------------------------------------------------------------------------
## name Regular given/when
## failures 0
## cut
given ($foo) {
when ($bar) {
$thingy = $blah;
}
}
#-----------------------------------------------------------------------------
## name Legal postfix if usage
## failures 0
## cut
use Carp;
while ($condition) {
next if $condition;
last if $condition;
redo if $condition;
return if $condition;
goto HELL if $condition;
exit if $condition;
}
die 'message' if $condition;
die if $condition;
warn 'message' if $condition;
warn if $condition;
carp 'message' if $condition;
carp if $condition;
croak 'message' if $condition;
croak if $condition;
cluck 'message' if $condition;
cluck if $condition;
confess 'message' if $condition;
confess if $condition;
exit 0 if $condition;
exit if $condition;
#-----------------------------------------------------------------------------
## name Legal postfix when usage
## failures 0
## cut
use Carp;
while ($condition) {
next when $smart_match;
last when $smart_match;
redo when $smart_match;
return when $smart_match;
goto HELL when $smart_match;
exit when $smart_match;
}
die 'message' when $smart_match;
die when $smart_match;
warn 'message' when $smart_match;
warn when $smart_match;
carp 'message' when $smart_match;
carp when $smart_match;
croak 'message' when $smart_match;
croak when $smart_match;
cluck 'message' when $smart_match;
cluck when $smart_match;
confess 'message' when $smart_match;
confess when $smart_match;
exit 0 when $smart_match;
exit when $smart_match;
#-----------------------------------------------------------------------------
## name override exempt flowcontrols
## failures 0
## parms {flowcontrol => 'assert'}
## cut
use Carp::Assert;
assert $something if $condition;
#-----------------------------------------------------------------------------
## name overriding exempt flowcontrols restores the defaults
## failures 8
## parms {flowcontrol => 'assert'}
## cut
use Carp::Assert;
warn $something if $condition;
die $something if $condition;
carp $something if $condition;
croak $something if $condition;
cluck $something if $condition;
confess $something if $condition;
exit $something if $condition;
do_something() if $condition;
#-----------------------------------------------------------------------------
## name Individual "keyword" hash assignment
## failures 0
## cut
my %hash;
$hash{if} = 1;
$hash{unless} = 1;
$hash{until} = 1;
$hash{while} = 1;
$hash{for} = 1;
$hash{foreach} = 1;
$hash{when} = 1;
#-----------------------------------------------------------------------------
## name "Keyword"-list hash assignment
## failures 0
## cut
my %hash = (
if => 1,
unless => 1,
until => 1,
while => 1,
for => 1,
foreach => 1,
when => 1,
);
#-----------------------------------------------------------------------------
## name RT #48422: Allow flow control method calls
## TODO exemption for method calls not implimented yet
## failures 0
## cut
Exception::Class->throw('an expression') if $error;
Exception::Class->throw($arg1, $arg2) unless not $error;
#-----------------------------------------------------------------------------
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 78
# indent-tabs-mode: nil
# c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
|