lib/FP/Ops.pm

filter: Statementstmt 62.0% 124 / 200 Branchbran 27.7% 35 / 126 Conditioncond 15.0% 3 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 55.9% 33 / 59 Podpod 0.0% 0 / 35 totaltotal 43.3% 195 / 450 CC 72 SCAR 24.9
CC
72
Cov
47%
__ANON__
72.0
__ANON__
56.0
__ANON__
20.0
CRAP 12.1
« lib/FP/Trie.pm ↑ Summary lib/FP/Equal.pm »
1 #
2 # Copyright (c) 2015-2020 Christian Jaeger, copying@christianjaeger.ch
3 #
4 # This is free software, offered under either the same terms as perl 5
5 # or the terms of the Artistic License version 2 or the terms of the
6 # MIT License (Expat version). See the file COPYING.md that came
7 # bundled with this file.
8 #
9  
10 =head1 NAME
11  
12 FP::Ops -- function wrappers around Perl ops
13  
14 =head1 SYNOPSIS
15  
16 1 ▶ use FP::List; use FP::Stream; use FP::Lazy; use FP::Equal 'is_equal';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶ use FP::Ops qw(add subt applying);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Lazy fibonacci sequence using \&add
20 our $fibs; $fibs =
21 cons 1, cons 1, lazy { stream_zip_with \&add, Keep($fibs), rest $fibs };
22 is_equal $fibs->take(10),
23 list(1, 1, 2, 3, 5, 8, 13, 21, 34, 55);
24  
25 # For each list entry, call `subt` (subtract) with the values in the
26 # given array or sequence.
27 is_equal list([4], [4,2], list(4,2,-1))->map(applying \&subt),
28 list(-4, 2, 3);
29  
30 =head1 DESCRIPTION
31  
32 There's no way to take a code reference to Perl operators, hence a
33 subroutine wrapper is necessary to use them as first-class values
34 (like pass them as arguments to higher-order functions like
35 list_map / ->map). This module provides them.
36  
37 Also similarly, `the_method("foo", @args)` returns a function that
38 does a "foo" method call on its argument, passing @args and then
39 whatever additional arguments the function receives.
40  
41 `cut_method` is a variant of the_method which takes the object
42 as the first argument: `cut_method($obj,"foo",@args)` returns a
43 function that does a "foo" method call on $obj, passing @args and then
44 whatever additional arguments the function receives.
45  
46 Also, `binary_operator("foo")` returns a function that uses "foo" as
47 operator between 2 arguments. `unary_operator("foo")` returns a
48 function that uses "foo" as operator before its single
49 argument. CAREFUL: make sure the strings given as the first argument
50 to these are secured, as they are passed to eval and there is no
51 safety check!
52  
53 =head1 NOTE
54  
55 This is alpha software! Read the status section in the package README
56 or on the L<website|http://functional-perl.org/>.
57  
58 =cut
59  
60 package FP::Ops;
61 60 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 60 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 60 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 60 our @EXPORT = qw();
67 60 our @EXPORT_OK = (
68 qw(
69 add
70 subt
71 mult
72 div
73 mod
74 expt
75 string_cmp
76 string_eq
77 string_eq
78 string_ne
79 string_lt
80 string_le
81 string_gt
82 string_ge
83 stringify
84 string_lc
85 string_uc
86 string_lcfirst
87 string_ucfirst
88 real_cmp
89 number_eq
90 number_ne
91 number_lt
92 number_le
93 number_gt
94 number_ge
95 the_method
96 cut_method
97 applying
98 applying_to
99 binary_operator
100 unary_operator
101 regex_match
102 ),
103  
104 # Manual variants
105 qw(
106 regex_substitute_coderef
107 regex_xsubstitute_coderef
108  
109 regex_substitute_re
110 regex_xsubstitute_re
111 regex_substitute_re_globally
112 regex_xsubstitute_re_globally
113 ),
114  
115 # The first 4 above overloaded into just two (globally
116 # variants see below):
117 qw(
118 regex_substitute
119 regex_xsubstitute
120 ),
121  
122 # These are just aliases:
123 'regex_substitute_globally', # regex_substitute_re_globally
124 'regex_xsubstitute_globally', # regex_xsubstitute_re_globally
125 );
126 60 our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
127  
128 60 ▶use Chj::TEST;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 60 ▶use FP::Show;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 60 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 7190 ▶sub add {
Subroutine add: called CC=2 SCAR=6.9
Pod undocumented
133 7190 my $t = 0;
134 7190 $t += $_ for @_;
135 7190 $t
136 }
137  
138 3 ▶sub subt {
Subroutine subt: called CC=4 SCAR=13.9
Pod undocumented
139 3 ▶ @_ == 1 ? -$_[0] : @_ ? do {
Branch: 2 branches
BranchTrueFalseTotal
@_ == 1 ? : 1 2 3
@_ ? : 2 0 2
140 2 my $t = shift;
141 2 $t -= $_ for @_;
142 2 $t
143 }
144 : die "need at least 1 argument"
145 }
146  
147 27 ▶sub mult {
Subroutine mult: called CC=2 SCAR=6.9
Pod undocumented
148 27 my $t = 1;
149 27 $t *= $_ for @_;
150 27 $t
151 }
152  
153 6 ▶sub div {
Subroutine div: called CC=4 SCAR=14.5
Pod undocumented
154 6 ▶ @_ == 1 ? (1 / $_[0]) : @_ ? do {
Branch: 2 branches
BranchTrueFalseTotal
@_ == 1 ? : 0 6 6
@_ ? : 6 0 6
155 6 my $t = shift;
156 6 $t /= $_ for @_;
157 6 $t
158 }
159 : die "need at least 1 argument"
160 }
161  
162 0 ▶sub mod {
Subroutine mod: not called CC=2 SCAR=17.9
Pod undocumented
163 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
164 0 my ($a, $b) = @_;
165 0 $a % $b
166 }
167  
168 0 ▶sub expt {
Subroutine expt: not called CC=2 SCAR=17.9
Pod undocumented
169 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
170 0 my ($a, $b) = @_;
171 0 $a**$b
172 }
173  
174 6 ▶sub string_cmp {
Subroutine string_cmp: called CC=2 SCAR=7.2
Pod undocumented
175 6 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 6 0 6
176 6 $_[0] cmp $_[1]
177 }
178  
179 0 ▶sub string_eq {
Subroutine string_eq: not called CC=2 SCAR=17.9
Pod undocumented
180 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
181 0 $_[0] eq $_[1]
182 }
183  
184 0 ▶sub string_ne {
Subroutine string_ne: not called CC=2 SCAR=17.9
Pod undocumented
185 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
186 0 $_[0] ne $_[1]
187 }
188  
189 0 ▶sub string_lt {
Subroutine string_lt: not called CC=2 SCAR=17.9
Pod undocumented
190 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
191 0 $_[0] lt $_[1]
192 }
193  
194 0 ▶sub string_le {
Subroutine string_le: not called CC=2 SCAR=17.9
Pod undocumented
195 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
196 0 $_[0] le $_[1]
197 }
198  
199 0 ▶sub string_gt {
Subroutine string_gt: not called CC=2 SCAR=17.9
Pod undocumented
200 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
201 0 $_[0] gt $_[1]
202 }
203  
204 0 ▶sub string_ge {
Subroutine string_ge: not called CC=2 SCAR=17.9
Pod undocumented
205 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
206 0 $_[0] ge $_[1]
207 }
208  
209 10 ▶sub stringify {
Subroutine stringify: called CC=2 SCAR=7.2
Pod undocumented
210 10 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 10 0 10
211 10 "$_[0]"
212 }
213  
214 0 ▶sub string_lc {
Subroutine string_lc: not called CC=2 SCAR=17.9
Pod undocumented
215 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
216 0 lc $_[0]
217 }
218  
219 0 ▶sub string_uc {
Subroutine string_uc: not called CC=2 SCAR=17.9
Pod undocumented
220 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
221 0 uc $_[0]
222 }
223  
224 0 ▶sub string_lcfirst {
Subroutine string_lcfirst: not called CC=2 SCAR=17.9
Pod undocumented
225 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
226 0 lcfirst $_[0]
227 }
228  
229 0 ▶sub string_ucfirst {
Subroutine string_ucfirst: not called CC=2 SCAR=17.9
Pod undocumented
230 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
231 0 ucfirst $_[0]
232 }
233  
234 70 ▶sub real_cmp {
Subroutine real_cmp: called CC=2 SCAR=7.2
Pod undocumented
235 70 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 70 0 70
236 70 $_[0] <=> $_[1]
237 }
238  
239 28 ▶sub number_eq {
Subroutine number_eq: called CC=2 SCAR=7.2
Pod undocumented
240 28 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 28 0 28
241 28 $_[0] == $_[1]
242 }
243  
244 0 ▶sub number_ne {
Subroutine number_ne: not called CC=2 SCAR=17.9
Pod undocumented
245 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
246 0 $_[0] != $_[1]
247 }
248  
249 0 ▶sub number_lt {
Subroutine number_lt: not called CC=2 SCAR=17.9
Pod undocumented
250 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
251 0 $_[0] < $_[1]
252 }
253  
254 0 ▶sub number_le {
Subroutine number_le: not called CC=2 SCAR=17.9
Pod undocumented
255 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
256 0 $_[0] <= $_[1]
257 }
258  
259 0 ▶sub number_gt {
Subroutine number_gt: not called CC=2 SCAR=17.9
Pod undocumented
260 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
261 0 $_[0] > $_[1]
262 }
263  
264 0 ▶sub number_ge {
Subroutine number_ge: not called CC=2 SCAR=17.9
Pod undocumented
265 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
266 0 $_[0] >= $_[1]
267 }
268  
269 314 ▶sub the_method {
Subroutine the_method: called CC=2 SCAR=7.0
Pod undocumented
270 314 ▶ @_ or die "wrong number of arguments";
Branch: 1 branch
BranchTrueFalseTotal
@_ or die "wrong number of arguments" 314 0 314
271 314 my ($method, @args) = @_;
272 113 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
273 113 my $self = shift;
274 113 $self->$method(@args, @_)
275  
276 # any reason to put args before or after _ ? So far I only
277 # have args, no _.
278 }
279 314 }
280  
281 0 ▶sub cut_method {
Subroutine cut_method: not called CC=2 SCAR=17.9
Pod undocumented
282 0 ▶ @_ >= 2 or fp_croak_arity ">= 2";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or fp_croak_arity(">= 2") 0 0 0
283 0 my ($object, $method, @args) = @_;
284 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
285 0 $object->$method(@args, @_)
286 }
287 0 }
288  
289 1 ▶sub applying {
Subroutine applying: called CC=2 SCAR=7.0
Pod undocumented
290 1 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 1 0 1
291 1 my ($f) = @_;
292  
293 3 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
294 3 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 3 0 3
295 3 my ($argv) = @_;
296 3 ▶ @_ = ref($argv) eq "ARRAY" ? @$argv : $argv->values;
Branch: 1 branch
BranchTrueFalseTotal
ref $argv eq 'ARRAY' ? : 2 1 3
297 3 goto &$f
298 }
299 1 }
300  
301 0 ▶sub applying_to {
Subroutine applying_to: not called CC=1 SCAR=6.9
Pod undocumented
302 0 my @v = @_;
303  
304 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
305 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
306 0 my ($f) = @_;
307 0 @_ = @v;
308 0 goto &$f
309 }
310 0 }
311  
312 2 ▶sub binary_operator {
Subroutine binary_operator: called CC=3 SCAR=11.7
Pod undocumented
313 2 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 2 0 2
314 2 my ($code) = @_;
315 2 ▶ eval 'sub { @_ == 2 or fp_croak_arity 2; $_[0] ' . $code . ' $_[1] }'
Branch: 1 branch
BranchTrueFalseTotal
eval 'sub { @_ == 2 or fp_croak_arity 2; $_[0] ' . $code . ' $_[1] }' or die 'binary_operator: ' . show($code) . ": $@" 2 0 2
316 || die "binary_operator: " . show($code) . ": $@";
317  
318 # XX security?
319 }
320  
321 1 ▶sub unary_operator {
Subroutine unary_operator: called CC=3 SCAR=11.7
Pod undocumented
322 1 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 1 0 1
323 1 my ($code) = @_;
324 1 ▶ eval 'sub { @_ == 1 or fp_croak_arity 1; ' . $code . ' $_[0] }'
Branch: 1 branch
BranchTrueFalseTotal
eval 'sub { @_ == 1 or fp_croak_arity 1; ' . $code . ' $_[0] }' or die 'unary_operator: ' . show($code) . ": $@" 1 0 1
325 || die "unary_operator: " . show($code) . ": $@";
326  
327 # XX security?
328 }
329  
330 1 ▶TEST {
Subroutine __ANON__: called CC=1 SCAR=0.0
331 1 my $lt = binary_operator "lt";
332 [
333 1 map { &$lt(@$_) } (
334 [2, 4],
335 [4, 2],
336 [3, 3],
337 ["abc", "bbc"],
338 ["ab", "ab"],
339 ["bbc", "abc"]
340 )
341 ]
342 }
343 60 [1, '', '', 1, '', ''];
344  
345 1 ▶TEST {
Subroutine __ANON__: called CC=1 SCAR=0.0
346 1 my $neg = unary_operator "-";
347 1 [map { &$neg($_) } (3, -2.5, 0)]
348 }
349 60 [-3, 2.5, 0];
350  
351 0 ▶sub regex_match {
Subroutine regex_match: not called CC=2 SCAR=17.9
Pod undocumented
352 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
353 0 my ($re) = @_;
354 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
355 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
356 0 my ($str) = @_;
357 0 $str =~ /$re/
358 }
359 0 }
360  
361 240 ▶sub make_regex_substitute_coderef {
Subroutine make_regex_substitute_coderef: called CC=3 SCAR=14.0
Pod undocumented
362 240 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 240 0 240
363 240 my ($allow_failures) = @_;
364 240 my $name = do {
365 240 ▶ my $x = $allow_failures ? "x" : "";
Branch: 1 branch
BranchTrueFalseTotal
$allow_failures ? : 120 120 240
366 240 "regex_${x}substitute_coderef"
367 };
368 7 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=23.8
369 7 my $coderef = shift;
370 7 ▶ if (@_ == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 0 7 7
elsif (@_ == 1) { } 7 0 7
371 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
372 0 ▶ @_ == 1 or die "expecting 1 argument, got " . @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or die 'expecting 1 argument, got ' . @_ 0 0 0
373 0 local $_ = $_[0];
374 0 ▶ &$coderef or $allow_failures || die "no match";
Branch: 1 branch
BranchTrueFalseTotal
&$coderef or ($allow_failures or die "no match") 0 0 0
Condition0%0/5
&$coderef || ($allow_failures || die('no match'))
l!l&&r!l&&!r
000
$allow_failures or die "no match"
l!l
00
MC/DC0%0/2
&$coderef || ($allow_failures || die('no match'))
&$coderef $allow_failures
Truth table0%0/3
A || B
A= &$coderefB= $allow_failures
ABresult
1X1
011
000
375 0 $_
376 }
377 0 } elsif (@_ == 1) {
378 7 local $_ = $_[0];
379 7 ▶ &$coderef or $allow_failures || die "no match";
Branch: 1 branch
BranchTrueFalseTotal
&$coderef or ($allow_failures or die "no match") 6 1 7
Condition60%3/5
&$coderef || ($allow_failures || die('no match'))
l!l&&r!l&&!r
610
$allow_failures or die "no match"
l!l
10
MC/DC0%0/2
&$coderef || ($allow_failures || die('no match'))
&$coderef $allow_failures
Truth table66%2/3
A || B
A= &$coderefB= $allow_failures
ABresult
1X1
011
000
380 7 $_
381 } else {
382 0 die "$name: expecting 1 or 2 arguments, got " . @_;
383 }
384 }
385 240 }
386  
387 60 *regex_substitute_coderef = make_regex_substitute_coderef 1;
388 60 *regex_xsubstitute_coderef = make_regex_substitute_coderef 0;
389  
390 360 ▶sub make_regex_substitute_re {
Subroutine make_regex_substitute_re: called CC=4 SCAR=25.1
Pod undocumented
391 360 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 360 0 360
392 360 my ($allow_failures, $globally) = @_;
393 360 my $name = do {
394 360 ▶ my $x = $allow_failures ? "x" : "";
Branch: 1 branch
BranchTrueFalseTotal
$allow_failures ? : 180 180 360
395 360 ▶ my $g = $globally ? "_globally" : "";
Branch: 1 branch
BranchTrueFalseTotal
$globally ? : 120 240 360
396 360 "regex_${x}substitute_re$g"
397 };
398 0 ▶ sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
399 0 ▶ if (@_ == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 2) { } 0 0 0
elsif (@_ == 3) { } 0 0 0
400 0 my ($re, $str_or_coderef) = @_;
401 0 ▶ sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
402 0 ▶ @_ == 1 or die "expecting 1 argument, got " . @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or die 'expecting 1 argument, got ' . @_ 0 0 0
403 0 my ($str) = @_;
404 (
405 0 ▶ $globally
Branch: 3 branches
BranchTrueFalseTotal
$globally ? UNIVERSAL::isa($str_or_coderef, "CODE") ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, "CODE") ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/) or ($allow_failures or die "${name}: no match") 0 0 0
$globally ? : 0 0 0
UNIVERSAL::isa($str_or_coderef, 'CODE') ? : 0 0 0
Condition0%0/3
($globally ? UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/)) || ($allow_failures || die("${name}: no match"))
l!l&&r!l&&!r
000
MC/DC0%0/2
($globally ? UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/)) || ($allow_failures || die("${name}: no match"))
($globally ? UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/)) ($allow_failures || die("${name}: no match"))
Truth table0%0/3
A || B
A= ($globally ? UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/))B= ($allow_failures || die("${name}: no match"))
ABresult
1X1
011
000
406 ? (UNIVERSAL::isa($str_or_coderef, "CODE")
407 0 ▶ ? $str =~ s/$re/&$str_or_coderef()/eg
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($str_or_coderef, 'CODE') ? : 0 0 0
408 : $str =~ s/$re/$str_or_coderef/g)
409 : (UNIVERSAL::isa($str_or_coderef, "CODE")
410 0 ▶ ? $str =~ s/$re/&$str_or_coderef()/e
Condition0%0/2
$allow_failures or die "${name}: no match"
l!l
00
MC/DC0%0/1
$allow_failures or die "${name}: no match"
$allow_failures
Truth table0%0/2
A
A= $allow_failures
Aresult
11
00
411 : $str =~ s/$re/$str_or_coderef/)
412 ) or $allow_failures || die "$name: no match";
413 0 $str
414 }
415 0 } elsif (@_ == 3) {
416 0 my ($re, $str_or_coderef, $str) = @_;
417 {
418 # copy-paste of above
419 0 (
420 0 ▶ $globally
Branch: 3 branches
BranchTrueFalseTotal
$globally ? UNIVERSAL::isa($str_or_coderef, "CODE") ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, "CODE") ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/) or ($allow_failures or die "${name}: no match") 0 0 0
$globally ? : 0 0 0
UNIVERSAL::isa($str_or_coderef, 'CODE') ? : 0 0 0
Condition0%0/3
($globally ? UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/)) || ($allow_failures || die("${name}: no match"))
l!l&&r!l&&!r
000
MC/DC0%0/2
($globally ? UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/)) || ($allow_failures || die("${name}: no match"))
($globally ? UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/)) ($allow_failures || die("${name}: no match"))
Truth table0%0/3
A || B
A= ($globally ? UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/eg : $str =~ s/$re/$str_or_coderef/g : (UNIVERSAL::isa($str_or_coderef, 'CODE') ? $str =~ s/$re/&$str_or_coderef();/e : $str =~ s/$re/$str_or_coderef/))B= ($allow_failures || die("${name}: no match"))
ABresult
1X1
011
000
421 ? (UNIVERSAL::isa($str_or_coderef, "CODE")
422 0 ▶ ? $str =~ s/$re/&$str_or_coderef()/eg
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($str_or_coderef, 'CODE') ? : 0 0 0
423 : $str =~ s/$re/$str_or_coderef/g)
424 : (UNIVERSAL::isa($str_or_coderef, "CODE")
425 0 ▶ ? $str =~ s/$re/&$str_or_coderef()/e
Condition0%0/2
$allow_failures or die "${name}: no match"
l!l
00
MC/DC0%0/1
$allow_failures or die "${name}: no match"
$allow_failures
Truth table0%0/2
A
A= $allow_failures
Aresult
11
00
426 : $str =~ s/$re/$str_or_coderef/)
427 ) or $allow_failures || die "$name: no match";
428 }
429 $str
430 0 } else {
431 0 die "$name: expecting 2 or 3 arguments, got " . @_;
432 }
433 }
434 360 }
435  
436 60 *regex_substitute_re = make_regex_substitute_re 1, 0;
437 60 *regex_xsubstitute_re = make_regex_substitute_re 0, 0;
438 60 *regex_substitute_re_globally = make_regex_substitute_re 1, 1;
439 60 *regex_xsubstitute_re_globally = make_regex_substitute_re 0, 1;
440  
441 120 ▶sub make_regex_substitute {
Subroutine make_regex_substitute: called CC=3 SCAR=12.2
Pod undocumented
442 120 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 120 0 120
443 120 my ($allow_failures) = @_;
444 120 my $subst_coderef = make_regex_substitute_coderef($allow_failures);
445 120 my $subst_re = make_regex_substitute_re($allow_failures, 0);
446 120 ▶ my $name = $allow_failures ? "regex_substitute" : "regex_xsubstitute";
Branch: 1 branch
BranchTrueFalseTotal
$allow_failures ? : 60 60 120
447 7 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=20.1
448 # overloading
449 7 ▶ @_ >= 1 or die "$name: need at least 1 argument";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or die "${name}: need at least 1 argument" 7 0 7
450 7 ▶ goto $subst_coderef if UNIVERSAL::isa($_[0], "CODE");
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "CODE") 7 0 7
451 0 ▶ @_ >= 2
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or die "${name}: need at least 2 arguments" . ' if the first is not a coderef' 0 0 0
452 or die "$name: need at least 2 arguments"
453 . " if the first is not a coderef";
454 0 goto $subst_re;
455 }
456 120 }
457  
458 60 *regex_substitute = make_regex_substitute 1;
459 60 *regex_xsubstitute = make_regex_substitute 0;
460 60 *regex_substitute_globally = \&regex_substitute_re_globally;
461 60 *regex_xsubstitute_globally = \&regex_xsubstitute_re_globally;
462  
463 60 1
« lib/FP/Trie.pm ↑ Summary lib/FP/Equal.pm »