| 1 | package Blatte::Builtins; | ||||||||||
| 2 | |||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 12 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 12 | @Blatte::Builtins::builtins = qw($acall $add $ameth $append $apply | |||||||||
| 7 | $aref $aset $concat $defined | ||||||||||
| 8 | $divide $streq $flatten $foreach | ||||||||||
| 9 | $funcall $numge $numgt $hashdel $hashkeys | ||||||||||
| 10 | $hashp $hashref $hashset $hashtest | ||||||||||
| 11 | $int $lc $lcfirst $numle $length $list | ||||||||||
| 12 | $listp $numlt $match $max $min $mkhash | ||||||||||
| 13 | $multiply $not $numeq $pop $push | ||||||||||
| 14 | $random $require $use $scall $shift | ||||||||||
| 15 | $smeth $split $sprintf $strge | ||||||||||
| 16 | $strgt $strle $strlt $subseq $subst | ||||||||||
| 17 | $substr $subtract $uc $ucfirst | ||||||||||
| 18 | $unshift); | ||||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 12 | ▶ | use vars (qw(@ISA @EXPORT), @Blatte::Builtins::builtins); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 12 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 12 | @ISA = qw(Exporter); | |||||||||
| 26 | |||||||||||
| 27 | 12 | @EXPORT = @Blatte::Builtins::builtins; | |||||||||
| 28 | |||||||||||
| 29 | 12 | ▶ | use Blatte qw(traverse true unwrapws flatten); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | ## Data types | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | $foreach = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 34 | 0 | my $fn = &unwrapws($_[1]); | |||||||||
| 35 | 0 | my @result = map { &$fn({}, &unwrapws($_)) } @{&unwrapws($_[2])}; | |||||||||
| 36 | 0 | \@result; | |||||||||
| 37 | 12 | }; | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | $length = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 40 | 0 | my $obj = &unwrapws($_[1]); | |||||||||
| 41 | 0 | ▶ | if (ref($obj) eq 'ARRAY') { # xxx UNIVERSAL::isa ? | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | return scalar(@$obj); | |||||||||
| 43 | } | ||||||||||
| 44 | 0 | length($obj); | |||||||||
| 45 | 12 | }; | |||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | $listp = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 48 | 0 | ref(&unwrapws($_[1])) eq 'ARRAY'; # xxx UNIVERSAL::isa ? | |||||||||
| 49 | 12 | }; | |||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | $list = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||
| 52 | 1 | ▶ | if (@_ > 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | [&unwrapws($_[1]), @_[2..$#_]]; | |||||||||
| 54 | } else { | ||||||||||
| 55 | 0 | []; | |||||||||
| 56 | } | ||||||||||
| 57 | 12 | }; | |||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | $subseq = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 60 | 0 | my($list, $start) = (&unwrapws($_[1]), &unwrapws($_[2])); | |||||||||
| 61 | 0 | ▶ | if ($start < 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | $start += @$list; | |||||||||
| 63 | } | ||||||||||
| 64 | 0 | my $len; | |||||||||
| 65 | 0 | ▶ | if (@_ > 3) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | $len = &unwrapws($_[3]); | |||||||||
| 67 | } else { | ||||||||||
| 68 | 0 | $len = @$list - $start; | |||||||||
| 69 | } | ||||||||||
| 70 | 0 | [@$list[$start .. $start + $len]]; | |||||||||
| 71 | 12 | }; | |||||||||
| 72 | |||||||||||
| 73 | 0 | ▶ | $not = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 74 | 0 | !&true(&unwrapws($_[1])); | |||||||||
| 75 | 12 | }; | |||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | $defined = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 78 | 0 | defined(&unwrapws($_[1])); | |||||||||
| 79 | 12 | }; | |||||||||
| 80 | |||||||||||
| 81 | ## Array references | ||||||||||
| 82 | |||||||||||
| 83 | 1 | ▶ | $aref = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 84 | 1 | &unwrapws($_[1])->[&unwrapws($_[2])]; | |||||||||
| 85 | 12 | }; | |||||||||
| 86 | |||||||||||
| 87 | 1 | ▶ | $aset = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 88 | 1 | &unwrapws($_[1])->[&unwrapws($_[2])] = $_[3]; | |||||||||
| 89 | 12 | }; | |||||||||
| 90 | |||||||||||
| 91 | 1 | ▶ | $push = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 92 | 1 | my $list = &unwrapws($_[1]); | |||||||||
| 93 | 1 | push(@$list, @_[2..$#_]); | |||||||||
| 94 | 1 | $list; | |||||||||
| 95 | 12 | }; | |||||||||
| 96 | |||||||||||
| 97 | 1 | ▶ | $pop = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 98 | 1 | pop(@{&unwrapws($_[1])}); | |||||||||
| 99 | 12 | }; | |||||||||
| 100 | |||||||||||
| 101 | 0 | ▶ | $unshift = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 102 | 0 | my $list = &unwrapws($_[1]); | |||||||||
| 103 | 0 | unshift(@$list, @_[2..$#_]); | |||||||||
| 104 | 0 | $list; | |||||||||
| 105 | 12 | }; | |||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | $shift = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 108 | 0 | shift(@{&unwrapws($_[1])}); | |||||||||
| 109 | 12 | }; | |||||||||
| 110 | |||||||||||
| 111 | 0 | ▶ | $append = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 112 | 0 | my $result = []; | |||||||||
| 113 | 0 | foreach my $l (@_[1..$#_]) { | |||||||||
| 114 | 0 | push(@$result, @$l); | |||||||||
| 115 | } | ||||||||||
| 116 | 0 | $result; | |||||||||
| 117 | 12 | }; | |||||||||
| 118 | |||||||||||
| 119 | ## Hash references | ||||||||||
| 120 | |||||||||||
| 121 | 0 | ▶ | $hashp = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 122 | 0 | ref(&unwrapws($_[1])) eq 'HASH'; # xxx UNIVERSAL::isa ? | |||||||||
| 123 | 12 | }; | |||||||||
| 124 | |||||||||||
| 125 | 1 | ▶ | $mkhash = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 126 | 1 | my $result = {}; | |||||||||
| 127 | 1 | ▶ | for (my $i = 1; $i <= $#_; $i += 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | 3 | $result->{&unwrapws($_[$i])} = $_[$i + 1]; | |||||||||
| 129 | } | ||||||||||
| 130 | 1 | $result; | |||||||||
| 131 | 12 | }; | |||||||||
| 132 | |||||||||||
| 133 | 1 | ▶ | $hashref = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 134 | 1 | &unwrapws($_[1])->{&unwrapws($_[2])}; | |||||||||
| 135 | 12 | }; | |||||||||
| 136 | |||||||||||
| 137 | 0 | ▶ | $hashset = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 138 | 0 | &unwrapws($_[1])->{&unwrapws($_[2])} = $_[3]; | |||||||||
| 139 | 12 | }; | |||||||||
| 140 | |||||||||||
| 141 | 0 | ▶ | $hashdel = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 142 | 0 | delete &unwrapws($_[1])->{&unwrapws($_[2])}; | |||||||||
| 143 | 12 | }; | |||||||||
| 144 | |||||||||||
| 145 | 0 | ▶ | $hashtest = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 146 | 0 | exists &unwrapws($_[1])->{&unwrapws($_[2])}; | |||||||||
| 147 | 12 | }; | |||||||||
| 148 | |||||||||||
| 149 | 0 | ▶ | $hashkeys = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 150 | 0 | my @result = keys %{&unwrapws($_[1])}; | |||||||||
| 151 | 0 | \@result; | |||||||||
| 152 | 12 | }; | |||||||||
| 153 | |||||||||||
| 154 | ## Perl function-calling interface | ||||||||||
| 155 | |||||||||||
| 156 | 0 | ▶ | $acall = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 157 | 0 | my $name = &unwrapws($_[1]); | |||||||||
| 158 | 0 | my @result = &$name(@_[2..$#_]); | |||||||||
| 159 | 0 | \@result; | |||||||||
| 160 | 12 | }; | |||||||||
| 161 | |||||||||||
| 162 | 0 | ▶ | $scall = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 163 | 0 | my $name = &unwrapws($_[1]); | |||||||||
| 164 | 0 | scalar(&$name(@_[2..$#_])); | |||||||||
| 165 | 12 | }; | |||||||||
| 166 | |||||||||||
| 167 | ## Perl object interface | ||||||||||
| 168 | |||||||||||
| 169 | 0 | ▶ | $ameth = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 170 | 0 | my $obj = &unwrapws($_[1]); | |||||||||
| 171 | 0 | my $meth = &unwrapws($_[2]); | |||||||||
| 172 | 0 | my @result = $obj->$meth(@_[3..$#_]); | |||||||||
| 173 | 0 | \@result; | |||||||||
| 174 | 12 | }; | |||||||||
| 175 | |||||||||||
| 176 | 0 | ▶ | $smeth = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 177 | 0 | my $obj = &unwrapws($_[1]); | |||||||||
| 178 | 0 | my $meth = &unwrapws($_[2]); | |||||||||
| 179 | 0 | scalar($obj->$meth(@_[3..$#_])); | |||||||||
| 180 | 12 | }; | |||||||||
| 181 | |||||||||||
| 182 | ## Arithmetic | ||||||||||
| 183 | |||||||||||
| 184 | 1 | ▶ | $add = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 185 | 1 | my $result = 0; | |||||||||
| 186 | 1 | foreach my $num (@_[1..$#_]) { | |||||||||
| 187 | 2 | $result += &unwrapws($num); | |||||||||
| 188 | } | ||||||||||
| 189 | 1 | $result; | |||||||||
| 190 | 12 | }; | |||||||||
| 191 | |||||||||||
| 192 | 1 | ▶ | $multiply = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 193 | 1 | my $result = 1; | |||||||||
| 194 | 1 | foreach my $num (@_[1..$#_]) { | |||||||||
| 195 | 2 | $result *= &unwrapws($num); | |||||||||
| 196 | } | ||||||||||
| 197 | 1 | $result; | |||||||||
| 198 | 12 | }; | |||||||||
| 199 | |||||||||||
| 200 | 1 | ▶ | $subtract = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||
| 201 | 1 | my $result = &unwrapws($_[1]); | |||||||||
| 202 | 1 | ▶ | if (@_ > 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 203 | 1 | foreach my $num (@_[2..$#_]) { | |||||||||
| 204 | 1 | $result -= &unwrapws($num); | |||||||||
| 205 | } | ||||||||||
| 206 | } else { | ||||||||||
| 207 | 0 | $result = -$result; | |||||||||
| 208 | } | ||||||||||
| 209 | 1 | $result; | |||||||||
| 210 | 12 | }; | |||||||||
| 211 | |||||||||||
| 212 | 1 | ▶ | $divide = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||
| 213 | 1 | my $result = &unwrapws($_[1]); | |||||||||
| 214 | 1 | ▶ | if (@_ > 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 215 | 1 | foreach my $num (@_[2..$#_]) { | |||||||||
| 216 | 1 | $result /= &unwrapws($num); | |||||||||
| 217 | } | ||||||||||
| 218 | } else { | ||||||||||
| 219 | 0 | $result = 1.0 / $result; | |||||||||
| 220 | } | ||||||||||
| 221 | 1 | $result; | |||||||||
| 222 | 12 | }; | |||||||||
| 223 | |||||||||||
| 224 | ## Lisp-like primitives | ||||||||||
| 225 | |||||||||||
| 226 | 0 | ▶ | $funcall = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 227 | 0 | my $sub = &unwrapws($_[1]); | |||||||||
| 228 | 0 | &$sub($_[0], @_[2..$#_]); | |||||||||
| 229 | 12 | }; | |||||||||
| 230 | |||||||||||
| 231 | 0 | ▶ | $apply = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 232 | 0 | my $sub = &unwrapws($_[1]); | |||||||||
| 233 | 0 | my @args = @_[2 .. ($#_ - 1)]; | |||||||||
| 234 | 0 | ▶ | if (@_ > 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 235 | 0 | my $last = $_[$#_]; | |||||||||
| 236 | 0 | my $last_unwrapped = &unwrapws($last); | |||||||||
| 237 | 0 | ▶ | if (ref($last_unwrapped) eq 'ARRAY') { # xxx UNIVERSAL::isa ? | ||||||||
|
Branch: 1 branch
| |||||||||||
| 238 | 0 | push(@args, @$last_unwrapped); | |||||||||
| 239 | } else { | ||||||||||
| 240 | 0 | push(@args, $last); | |||||||||
| 241 | } | ||||||||||
| 242 | } | ||||||||||
| 243 | 0 | &$sub($_[0], @args); | |||||||||
| 244 | 12 | }; | |||||||||
| 245 | |||||||||||
| 246 | ## Strings | ||||||||||
| 247 | |||||||||||
| 248 | 0 | ▶ | $flatten = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 249 | 0 | my $result = ''; | |||||||||
| 250 | |||||||||||
| 251 | 0 | foreach my $obj (@_[1..$#_]) { | |||||||||
| 252 | 0 | $result .= &flatten($obj); | |||||||||
| 253 | } | ||||||||||
| 254 | |||||||||||
| 255 | 0 | $result; | |||||||||
| 256 | 12 | }; | |||||||||
| 257 | |||||||||||
| 258 | 1 | ▶ | $uc = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 259 | 1 | uc(&unwrapws($_[1])); | |||||||||
| 260 | 12 | }; | |||||||||
| 261 | |||||||||||
| 262 | 1 | ▶ | $lc = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 263 | 1 | lc(&unwrapws($_[1])); | |||||||||
| 264 | 12 | }; | |||||||||
| 265 | |||||||||||
| 266 | 0 | ▶ | $ucfirst = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 267 | 0 | ucfirst(&unwrapws($_[1])); | |||||||||
| 268 | 12 | }; | |||||||||
| 269 | |||||||||||
| 270 | 0 | ▶ | $lcfirst = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 271 | 0 | lcfirst(&unwrapws($_[1])); | |||||||||
| 272 | 12 | }; | |||||||||
| 273 | |||||||||||
| 274 | 0 | ▶ | $concat = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 275 | 0 | my $result; | |||||||||
| 276 | 0 | foreach my $str (@_[1..$#_]) { | |||||||||
| 277 | 0 | $result .= &unwrapws($str); | |||||||||
| 278 | } | ||||||||||
| 279 | 0 | $result; | |||||||||
| 280 | 12 | }; | |||||||||
| 281 | |||||||||||
| 282 | 2 | ▶ | $substr = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||
| 283 | 2 | my $str = &unwrapws($_[1]); | |||||||||
| 284 | 2 | my $start = &unwrapws($_[2]); | |||||||||
| 285 | 2 | ▶ | if ($#_ == 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 286 | 0 | return substr($str, $start); | |||||||||
| 287 | } | ||||||||||
| 288 | 2 | my $len = &unwrapws($_[3]); | |||||||||
| 289 | 2 | ▶ | if ($#_ == 3) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 290 | 2 | return substr($str, $start, $len); | |||||||||
| 291 | } | ||||||||||
| 292 | 0 | substr($str, $start, $len, &unwrapws($_[4])); | |||||||||
| 293 | 12 | }; | |||||||||
| 294 | |||||||||||
| 295 | 0 | ▶ | $sprintf = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 296 | 0 | my $fmt = &unwrapws($_[1]); | |||||||||
| 297 | 0 | sprintf($fmt, map { &unwrapws($_) } @_[2 .. $#_]); | |||||||||
| 298 | 12 | }; | |||||||||
| 299 | |||||||||||
| 300 | 2 | ▶ | $streq = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 301 | 2 | my $first = &unwrapws($_[1]); | |||||||||
| 302 | 2 | ▶ | for (my $i = 2; $i <= $#_; ++$i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 303 | 2 | ▶ | if ($first ne &unwrapws($_[$i])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 304 | 1 | return undef; | |||||||||
| 305 | } | ||||||||||
| 306 | } | ||||||||||
| 307 | 1 | 1; | |||||||||
| 308 | 12 | }; | |||||||||
| 309 | |||||||||||
| 310 | 0 | ▶ | $strlt = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 311 | 0 | my $n = &unwrapws($_[1]); | |||||||||
| 312 | 0 | foreach my $m (@_[2..$#_]) { | |||||||||
| 313 | 0 | $m = &unwrapws($m); | |||||||||
| 314 | 0 | ▶ | return undef unless $n lt $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 315 | 0 | $n = $m; | |||||||||
| 316 | } | ||||||||||
| 317 | 0 | 1; | |||||||||
| 318 | 12 | }; | |||||||||
| 319 | |||||||||||
| 320 | 0 | ▶ | $strle = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 321 | 0 | my $n = &unwrapws($_[1]); | |||||||||
| 322 | 0 | foreach my $m (@_[2..$#_]) { | |||||||||
| 323 | 0 | $m = &unwrapws($m); | |||||||||
| 324 | 0 | ▶ | return undef unless $n le $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 325 | 0 | $n = $m; | |||||||||
| 326 | } | ||||||||||
| 327 | 0 | 1; | |||||||||
| 328 | 12 | }; | |||||||||
| 329 | |||||||||||
| 330 | 0 | ▶ | $strgt = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 331 | 0 | my $n = &unwrapws($_[1]); | |||||||||
| 332 | 0 | foreach my $m (@_[2..$#_]) { | |||||||||
| 333 | 0 | $m = &unwrapws($m); | |||||||||
| 334 | 0 | ▶ | return undef unless $n gt $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 335 | 0 | $n = $m; | |||||||||
| 336 | } | ||||||||||
| 337 | 0 | 1; | |||||||||
| 338 | 12 | }; | |||||||||
| 339 | |||||||||||
| 340 | 0 | ▶ | $strge = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 341 | 0 | my $n = &unwrapws($_[1]); | |||||||||
| 342 | 0 | foreach my $m (@_[2..$#_]) { | |||||||||
| 343 | 0 | $m = &unwrapws($m); | |||||||||
| 344 | 0 | ▶ | return undef unless $n ge $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 345 | 0 | $n = $m; | |||||||||
| 346 | } | ||||||||||
| 347 | 0 | 1; | |||||||||
| 348 | 12 | }; | |||||||||
| 349 | |||||||||||
| 350 | ## Numbers | ||||||||||
| 351 | |||||||||||
| 352 | 0 | ▶ | $random = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 353 | 0 | ▶ | if ($#_ == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 354 | 0 | return rand(1); | |||||||||
| 355 | } | ||||||||||
| 356 | 0 | rand(&unwrapws($_[1])); | |||||||||
| 357 | 12 | }; | |||||||||
| 358 | |||||||||||
| 359 | 0 | ▶ | $int = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 360 | 0 | int(&unwrapws($_[$#_])); | |||||||||
| 361 | 12 | }; | |||||||||
| 362 | |||||||||||
| 363 | 0 | ▶ | $numeq = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 364 | 0 | my $first = &unwrapws($_[1]); | |||||||||
| 365 | 0 | ▶ | for (my $i = 2; $i <= $#_; ++$i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 366 | 0 | ▶ | if ($first != &unwrapws($_[$i])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 367 | 0 | return undef; | |||||||||
| 368 | } | ||||||||||
| 369 | } | ||||||||||
| 370 | 0 | 1; | |||||||||
| 371 | 12 | }; | |||||||||
| 372 | |||||||||||
| 373 | 0 | ▶ | $max = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 374 | 0 | my $result = &unwrapws($_[1]); | |||||||||
| 375 | 0 | ▶ | for (my $i = 2; $i <= $#_; ++$i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 376 | 0 | my $n = &unwrapws($_[$i]); | |||||||||
| 377 | 0 | ▶ | $result = $n if $n > $result; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 378 | } | ||||||||||
| 379 | 0 | $result; | |||||||||
| 380 | 12 | }; | |||||||||
| 381 | |||||||||||
| 382 | 0 | ▶ | $min = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 383 | 0 | my $result = &unwrapws($_[1]); | |||||||||
| 384 | 0 | ▶ | for (my $i = 2; $i <= $#_; ++$i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 385 | 0 | my $n = &unwrapws($_[$i]); | |||||||||
| 386 | 0 | ▶ | $result = $n if $n < $result; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 387 | } | ||||||||||
| 388 | 0 | $result; | |||||||||
| 389 | 12 | }; | |||||||||
| 390 | |||||||||||
| 391 | 0 | ▶ | $numlt = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 392 | 0 | my $n = &unwrapws($_[1]); | |||||||||
| 393 | 0 | foreach my $m (@_[2..$#_]) { | |||||||||
| 394 | 0 | $m = &unwrapws($m); | |||||||||
| 395 | 0 | ▶ | return undef unless $n < $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 396 | 0 | $n = $m; | |||||||||
| 397 | } | ||||||||||
| 398 | 0 | 1; | |||||||||
| 399 | 12 | }; | |||||||||
| 400 | |||||||||||
| 401 | 0 | ▶ | $numle = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 402 | 0 | my $n = &unwrapws($_[1]); | |||||||||
| 403 | 0 | foreach my $m (@_[2..$#_]) { | |||||||||
| 404 | 0 | $m = &unwrapws($m); | |||||||||
| 405 | 0 | ▶ | return undef unless $n <= $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 406 | 0 | $n = $m; | |||||||||
| 407 | } | ||||||||||
| 408 | 0 | 1; | |||||||||
| 409 | 12 | }; | |||||||||
| 410 | |||||||||||
| 411 | 0 | ▶ | $numgt = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 412 | 0 | my $n = &unwrapws($_[1]); | |||||||||
| 413 | 0 | foreach my $m (@_[2..$#_]) { | |||||||||
| 414 | 0 | $m = &unwrapws($m); | |||||||||
| 415 | 0 | ▶ | return undef unless $n > $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 416 | 0 | $n = $m; | |||||||||
| 417 | } | ||||||||||
| 418 | 0 | 1; | |||||||||
| 419 | 12 | }; | |||||||||
| 420 | |||||||||||
| 421 | 0 | ▶ | $numge = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 422 | 0 | my $n = &unwrapws($_[1]); | |||||||||
| 423 | 0 | foreach my $m (@_[2..$#_]) { | |||||||||
| 424 | 0 | $m = &unwrapws($m); | |||||||||
| 425 | 0 | ▶ | return undef unless $n >= $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 426 | 0 | $n = $m; | |||||||||
| 427 | } | ||||||||||
| 428 | 0 | 1; | |||||||||
| 429 | 12 | }; | |||||||||
| 430 | |||||||||||
| 431 | ## Perl modules | ||||||||||
| 432 | |||||||||||
| 433 | 0 | ▶ | $require = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 434 | 0 | require &unwrapws($_[1]); | |||||||||
| 435 | 12 | }; | |||||||||
| 436 | |||||||||||
| 437 | 0 | ▶ | $use = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 438 | 0 | shift; | |||||||||
| 439 | 0 | eval sprintf('use %s', &flatten(\@_, '')); | |||||||||
| 440 | 12 | }; | |||||||||
| 441 | |||||||||||
| 442 | ## Regular expressions | ||||||||||
| 443 | |||||||||||
| 444 | 0 | ▶ | $match = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 445 | 0 | my $flags = $_[0]->{flags}; | |||||||||
| 446 | 0 | my $str = &unwrapws($_[1]); | |||||||||
| 447 | 0 | my $regex = &unwrapws($_[2]); | |||||||||
| 448 | 0 | my @result = eval("\$str =~ /\$regex/$flags"); | |||||||||
| 449 | 0 | \@result; | |||||||||
| 450 | 12 | }; | |||||||||
| 451 | |||||||||||
| 452 | 0 | ▶ | $subst = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 453 | 0 | my $flags = $_[0]->{flags}; | |||||||||
| 454 | 0 | my $str = &unwrapws($_[1]); | |||||||||
| 455 | 0 | my $regex = &unwrapws($_[2]); | |||||||||
| 456 | 0 | my $replacement = &unwrapws($_[3]); | |||||||||
| 457 | 0 | eval("\$str =~ s/\$regex/\$replacement/$flags"); | |||||||||
| 458 | 0 | $str; | |||||||||
| 459 | 12 | }; | |||||||||
| 460 | |||||||||||
| 461 | 0 | ▶ | $split = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 462 | 0 | my $flags = $_[0]->{flags}; | |||||||||
| 463 | 0 | my $str = &unwrapws($_[1]); | |||||||||
| 464 | 0 | my $regex = &unwrapws($_[2]); | |||||||||
| 465 | 0 | ▶ | if ($#_ == 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 466 | 0 | my @result = eval("split(/\$regex/$flags, \$str)"); | |||||||||
| 467 | 0 | return \@result; | |||||||||
| 468 | } | ||||||||||
| 469 | 0 | my $limit = &unwrapws($_[3]); | |||||||||
| 470 | 0 | my @result = eval("split(/\$regex/$flags, \$str, \$limit)"); | |||||||||
| 471 | 0 | \@result; | |||||||||
| 472 | 12 | }; | |||||||||
| 473 | |||||||||||
| 474 | 12 | 1; | |||||||||
| 475 | |||||||||||
| 476 | __END__ | ||||||||||